raise error when a non reverse-alias is used during the reply phase

This commit is contained in:
Son 2022-01-07 10:34:08 +01:00
parent 035d238c75
commit 5195c9de8b
2 changed files with 14 additions and 2 deletions

View File

@ -20,3 +20,9 @@ class CannotCreateContactForReverseAlias(Exception):
"""raised when a contact is created that has website_email=reverse_alias of another contact"""
pass
class NonReverseAliasInReplyPhase(Exception):
"""raised when a non reverse-alias is used during a reply phase"""
pass

View File

@ -127,6 +127,7 @@ from app.email_utils import (
get_mailbox_bounce_info,
save_email_for_debugging,
)
from app.errors import NonReverseAliasInReplyPhase
from app.log import LOG, set_message_id
from app.models import (
Alias,
@ -373,16 +374,21 @@ def replace_header_when_reply(msg: Message, alias: Alias, header: str):
for _, reply_email in getaddresses(headers):
# no transformation when alias is already in the header
# can happen when user clicks "Reply All"
if reply_email == alias.email:
continue
contact = Contact.get_by(reply_email=reply_email)
if not contact:
LOG.w(
"%s email in reply phase %s must be reply emails", header, reply_email
"email %s contained in %s header in reply phase %s must be reply emails. headers:%s",
reply_email,
header,
headers,
)
raise NonReverseAliasInReplyPhase
# still keep this email in header
new_addrs.append(reply_email)
# new_addrs.append(reply_email)
else:
new_addrs.append(formataddr((contact.name, contact.website_email)))