raise error when a non reverse-alias is used during the reply phase
This commit is contained in:
parent
035d238c75
commit
5195c9de8b
|
@ -20,3 +20,9 @@ class CannotCreateContactForReverseAlias(Exception):
|
||||||
"""raised when a contact is created that has website_email=reverse_alias of another contact"""
|
"""raised when a contact is created that has website_email=reverse_alias of another contact"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class NonReverseAliasInReplyPhase(Exception):
|
||||||
|
"""raised when a non reverse-alias is used during a reply phase"""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
|
@ -127,6 +127,7 @@ from app.email_utils import (
|
||||||
get_mailbox_bounce_info,
|
get_mailbox_bounce_info,
|
||||||
save_email_for_debugging,
|
save_email_for_debugging,
|
||||||
)
|
)
|
||||||
|
from app.errors import NonReverseAliasInReplyPhase
|
||||||
from app.log import LOG, set_message_id
|
from app.log import LOG, set_message_id
|
||||||
from app.models import (
|
from app.models import (
|
||||||
Alias,
|
Alias,
|
||||||
|
@ -373,16 +374,21 @@ def replace_header_when_reply(msg: Message, alias: Alias, header: str):
|
||||||
|
|
||||||
for _, reply_email in getaddresses(headers):
|
for _, reply_email in getaddresses(headers):
|
||||||
# no transformation when alias is already in the header
|
# no transformation when alias is already in the header
|
||||||
|
# can happen when user clicks "Reply All"
|
||||||
if reply_email == alias.email:
|
if reply_email == alias.email:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
contact = Contact.get_by(reply_email=reply_email)
|
contact = Contact.get_by(reply_email=reply_email)
|
||||||
if not contact:
|
if not contact:
|
||||||
LOG.w(
|
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
|
# still keep this email in header
|
||||||
new_addrs.append(reply_email)
|
# new_addrs.append(reply_email)
|
||||||
else:
|
else:
|
||||||
new_addrs.append(formataddr((contact.name, contact.website_email)))
|
new_addrs.append(formataddr((contact.name, contact.website_email)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue