From 4c63b4c0f19c09e3f8a8714ada2bb6a532344c52 Mon Sep 17 00:00:00 2001 From: Son Date: Fri, 7 Jan 2022 12:18:46 +0100 Subject: [PATCH] refactor --- email_handler.py | 53 ++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/email_handler.py b/email_handler.py index 13c80b23..c616d8d7 100644 --- a/email_handler.py +++ b/email_handler.py @@ -2064,7 +2064,9 @@ def handle(envelope: Envelope) -> str: LOG.d("Handle unsubscribe request from %s", mail_from) return handle_unsubscribe(envelope, msg) - # emails sent to transactional VERP. Either bounce emails or out-of-office + # region: mail sent to VERP + + # sent to transactional VERP. Either bounce emails or out-of-office if ( len(rcpt_tos) == 1 and rcpt_tos[0].startswith(TRANSACTIONAL_BOUNCE_PREFIX) @@ -2085,29 +2087,7 @@ def handle(envelope: Envelope) -> str: ) return status.E408 - if ( - len(rcpt_tos) == 1 - and mail_from == "staff@hotmail.com" - and rcpt_tos[0] == POSTMASTER - ): - LOG.w("Handle hotmail complaint") - - # if the complaint cannot be handled, forward it normally - if handle_hotmail_complaint(msg): - return status.E208 - - if ( - len(rcpt_tos) == 1 - and mail_from == "feedback@arf.mail.yahoo.com" - and rcpt_tos[0] == POSTMASTER - ): - LOG.w("Handle yahoo complaint") - - # if the complaint cannot be handled, forward it normally - if handle_yahoo_complaint(msg): - return status.E210 - - # Mails sent to forward VERP, can be either bounce or out-of-office + # sent to forward VERP, can be either bounce or out-of-office if ( len(rcpt_tos) == 1 and rcpt_tos[0].startswith(BOUNCE_PREFIX) @@ -2153,6 +2133,7 @@ def handle(envelope: Envelope) -> str: ) return status.E409 + # sent to reply VERP, can be either bounce or out-of-office if len(rcpt_tos) == 1 and rcpt_tos[0].startswith( f"{BOUNCE_PREFIX_FOR_REPLY_PHASE}+" ): @@ -2219,6 +2200,30 @@ def handle(envelope: Envelope) -> str: ) return handle_bounce(envelope, email_log, msg) + # endregion + + if ( + len(rcpt_tos) == 1 + and mail_from == "staff@hotmail.com" + and rcpt_tos[0] == POSTMASTER + ): + LOG.w("Handle hotmail complaint") + + # if the complaint cannot be handled, forward it normally + if handle_hotmail_complaint(msg): + return status.E208 + + if ( + len(rcpt_tos) == 1 + and mail_from == "feedback@arf.mail.yahoo.com" + and rcpt_tos[0] == POSTMASTER + ): + LOG.w("Handle yahoo complaint") + + # if the complaint cannot be handled, forward it normally + if handle_yahoo_complaint(msg): + return status.E210 + # case where From: header is a reverse alias which should never happen from_header = get_header_unicode(msg[headers.FROM]) if from_header: