From 565f6dc1420bea74463a67b8b3985c80be0cbea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Mon, 4 Mar 2024 17:44:19 +0100 Subject: [PATCH] If there is no transactional id, skip it (#2047) --- email_handler.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/email_handler.py b/email_handler.py index efa00f9b0..ce55249d5 100644 --- a/email_handler.py +++ b/email_handler.py @@ -1892,23 +1892,24 @@ def handle_transactional_bounce( ): LOG.d("handle transactional bounce sent to %s", rcpt_to) - # parse the TransactionalEmail - transactional_id = transactional_id or parse_id_from_bounce(rcpt_to) transactional = TransactionalEmail.get(transactional_id) - # a transaction might have been deleted in delete_logs() - if transactional: - LOG.i("Create bounce for %s", transactional.email) - bounce_info = get_mailbox_bounce_info(msg) - if bounce_info: - Bounce.create( - email=transactional.email, - info=bounce_info.as_bytes().decode(), - commit=True, - ) - else: - LOG.w("cannot get bounce info, debug at %s", save_email_for_debugging(msg)) - Bounce.create(email=transactional.email, commit=True) + if not transactional: + LOG.i( + f"No transactional record for {envelope.mail_from} -> {envelope.rcpt_tos}" + ) + return + LOG.i("Create bounce for %s", transactional.email) + bounce_info = get_mailbox_bounce_info(msg) + if bounce_info: + Bounce.create( + email=transactional.email, + info=bounce_info.as_bytes().decode(), + commit=True, + ) + else: + LOG.w("cannot get bounce info, debug at %s", save_email_for_debugging(msg)) + Bounce.create(email=transactional.email, commit=True) def handle_bounce(envelope, email_log: EmailLog, msg: Message) -> str: