From f9830affea4cc1e8141eeb4386b378f3cbe9351f Mon Sep 17 00:00:00 2001 From: jedi Date: Sat, 4 May 2024 01:43:59 +0200 Subject: [PATCH] stash --- core/mail/protocol.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/mail/protocol.py b/core/mail/protocol.py index d88d31a..d5bb889 100644 --- a/core/mail/protocol.py +++ b/core/mail/protocol.py @@ -11,6 +11,10 @@ from notify_sessions.models import SystemEvent from tickets.models import IssueThread +class SpecialMailException(Exception): + pass + + def find_quoted_printable(s, marker): positions = [i for i in range(len(s)) if s.lower().startswith('=?utf-8?' + marker + '?', i)] for pos in positions: @@ -207,9 +211,9 @@ def receive_email(envelope, log=None): # handle undelivered mail 'MAILER-DAEMON@' - #if header_from.startswith('MAILER-DAEMON@'): - # log.warning("Mail delivery failed") - # return None, False, None, None + if header_from.trim("<>").startswith('MAILER-DAEMON@') and envelope.mail_from.trim("<>") == "": + log.warning("Ignoring mailer daemon") + raise SpecialMailException("Ignoring mailer daemon") if Email.objects.filter(reference=header_message_id).exists(): # break before issue thread is created log.warning("Email already exists") @@ -292,6 +296,9 @@ class LMTPHandler: await send_smtp(reply) log.info("Sent auto reply") + return '250 Message accepted for delivery' + except SpecialMailException as e: + log.warning(f"Special mail exception: {e}") return '250 Message accepted for delivery' except Exception as e: from hashlib import sha256