From b23f9fa97198183ca4aece0344ad6c84247aa133 Mon Sep 17 00:00:00 2001 From: Son Date: Sat, 8 Jan 2022 00:16:32 +0100 Subject: [PATCH] delete email_log if CannotCreateContactForReverseAlias --- email_handler.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/email_handler.py b/email_handler.py index 755dbbd0..c6afac6d 100644 --- a/email_handler.py +++ b/email_handler.py @@ -812,8 +812,14 @@ def forward_email_to_mailbox( LOG.d("Reply-To header, new:%s, old:%s", new_reply_to_header, reply_to_header) # replace CC & To emails by reverse-alias for all emails that are not alias - replace_header_when_forward(msg, alias, "Cc") - replace_header_when_forward(msg, alias, "To") + try: + replace_header_when_forward(msg, alias, "Cc") + replace_header_when_forward(msg, alias, "To") + except CannotCreateContactForReverseAlias: + LOG.d("CannotCreateContactForReverseAlias error, delete %s", email_log) + EmailLog.delete(email_log.id) + Session.commit() + raise # add List-Unsubscribe header if user.one_click_unsubscribe_block_sender: @@ -2349,7 +2355,6 @@ class MailHandler: msg[headers.FROM], msg[headers.TO], ) - Session.rollback() return status.E524 except Exception as e: LOG.e(