handle case alias was deleted in the meantime

This commit is contained in:
Son 2021-12-31 12:14:22 +01:00
parent 01a8a0343e
commit b24d58bdf3
1 changed files with 12 additions and 1 deletions

View File

@ -51,6 +51,7 @@ from email_validator import validate_email, EmailNotValidError
from flanker.addresslib import address
from flanker.addresslib.address import EmailAddress
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import ObjectDeletedError
from app import pgp_utils, s3
from app.alias_utils import try_auto_create
@ -547,7 +548,17 @@ def handle_forward(envelope, msg: Message, rcpt_to: str) -> List[Tuple[bool, str
from_header = get_header_unicode(msg[headers.FROM])
LOG.d("Create or get contact for from_header:%s", from_header)
contact = get_or_create_contact(from_header, envelope.mail_from, alias)
try:
contact = get_or_create_contact(from_header, envelope.mail_from, alias)
except ObjectDeletedError:
LOG.d("maybe alias was deleted in the meantime")
alias = Alias.get_by(email=alias_address)
if not alias:
LOG.i("Alias %s was deleted in the meantime", alias_address)
if should_ignore_bounce(envelope.mail_from):
return [(True, status.E207)]
else:
return [(False, status.E515)]
reply_to_contact = None
if msg[headers.REPLY_TO]: