if the complaint cannot be handled, forward it normally

This commit is contained in:
Son Nguyen Kim 2021-09-09 18:54:54 +02:00
parent db55f289c1
commit 6e9dfdd6f1

View file

@ -1282,23 +1282,23 @@ def handle_bounce_forward_phase(msg: Message, email_log: EmailLog):
) )
def handle_hotmail_complaint(msg: Message): def handle_hotmail_complaint(msg: Message) -> bool:
""" """
Handle hotmail complaint sent to postmaster Handle hotmail complaint sent to postmaster
Return True if the complaint can be handled, False otherwise
""" """
orig_msg = get_orig_message_from_outlook_complaint(msg) orig_msg = get_orig_message_from_outlook_complaint(msg)
to_header = orig_msg["To"] to_header = orig_msg["To"]
if not to_header: if not to_header:
LOG.e("cannot find the alias") LOG.e("cannot find the alias")
LOG.d("msg:%s, \n orig_msg:%s", msg, orig_msg) return False
return
_, alias_address = parseaddr_unicode(to_header) _, alias_address = parseaddr_unicode(to_header)
alias = Alias.get_by(email=alias_address) alias = Alias.get_by(email=alias_address)
if not alias: if not alias:
LOG.d("No alias for %s", alias_address) LOG.d("No alias for %s", alias_address)
return return False
user = alias.user user = alias.user
LOG.w("Handle hotmail complaint for %s %s %s", alias, user, alias.mailboxes) LOG.w("Handle hotmail complaint for %s %s %s", alias, user, alias.mailboxes)
@ -1319,6 +1319,8 @@ def handle_hotmail_complaint(msg: Message):
max_nb_alert=2, max_nb_alert=2,
) )
return True
def handle_bounce_reply_phase(envelope, msg: Message, email_log: EmailLog): def handle_bounce_reply_phase(envelope, msg: Message, email_log: EmailLog):
""" """
@ -1734,8 +1736,10 @@ def handle(envelope: Envelope) -> str:
and rcpt_tos[0] == POSTMASTER and rcpt_tos[0] == POSTMASTER
): ):
LOG.w("Handle hotmail complaint") LOG.w("Handle hotmail complaint")
handle_hotmail_complaint(msg)
return status.E208 # if the complaint cannot be handled, forward it normally
if handle_hotmail_complaint(msg):
return status.E208
# Handle bounce # Handle bounce
if ( if (