return 5** if CannotCreateContactForReverseAlias

This commit is contained in:
Son 2022-01-08 00:16:16 +01:00
parent ed39d47e7a
commit 01ba5e8bf0
3 changed files with 18 additions and 1 deletions

View File

@ -59,4 +59,5 @@ E522 = (
"at a rate that prevents additional messages from being delivered."
)
E523 = "550 SL E523 Unknown error"
E524 = "550 SL E524 Wrong use of reverse-alias"
# endregion

View File

@ -1574,7 +1574,7 @@ class Contact(Base, ModelMixin):
# make sure contact.website_email isn't a reverse alias
orig_contact = Contact.get_by(reply_email=website_email)
if orig_contact:
raise CannotCreateContactForReverseAlias
raise CannotCreateContactForReverseAlias(str(orig_contact))
Session.add(new_contact)

View File

@ -133,6 +133,7 @@ from app.errors import (
VERPForward,
VERPReply,
MailSentFromReverseAlias,
CannotCreateContactForReverseAlias,
)
from app.log import LOG, set_message_id
from app.models import (
@ -2335,6 +2336,21 @@ class MailHandler:
try:
ret = self._handle(envelope, msg)
return ret
# happen if reverse-alias is used during the forward phase
# as in this case, a new reverse-alias needs to be created for this reverse-alias -> chaos
except CannotCreateContactForReverseAlias as e:
LOG.w(
"Probably due to reverse-alias used in the forward phase, "
"error:%s mail_from:%s, rcpt_tos:%s, header_from:%s, header_to:%s",
e,
envelope.mail_from,
envelope.rcpt_tos,
msg[headers.FROM],
msg[headers.TO],
)
Session.rollback()
return status.E524
except Exception as e:
LOG.e(
"email handling fail with error:%s mail_from:%s, rcpt_tos:%s, header_from:%s, header_to:%s, saved to %s",