From 6c42872440c7dd18de7087014d4cce4f0fbb56c7 Mon Sep 17 00:00:00 2001 From: Son Date: Wed, 5 Jan 2022 15:22:22 +0100 Subject: [PATCH] add is_bounce() --- email_handler.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/email_handler.py b/email_handler.py index 4b424128..10f8c296 100644 --- a/email_handler.py +++ b/email_handler.py @@ -1771,6 +1771,14 @@ def is_automatic_out_of_office(msg: Message) -> bool: return False +def is_bounce(envelope: Envelope, msg: Message): + """Detect whether an email is a Delivery Status Notification""" + return ( + envelope.mail_from == "<>" + and msg.get_content_type().lower() == "multipart/report" + ) + + def handle_unsubscribe(envelope: Envelope, msg: Message) -> str: """return the SMTP status""" # format: alias_id: