This commit is contained in:
j3d1 2024-05-04 01:43:59 +02:00
parent 19ee21d8d4
commit 97ed83d5a4

View file

@ -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