From 666d4be65b5241fbf6b8bb6cb7e70ff2705fac4b Mon Sep 17 00:00:00 2001 From: jedi Date: Sat, 4 May 2024 00:37:41 +0200 Subject: [PATCH] stash --- core/mail/protocol.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/mail/protocol.py b/core/mail/protocol.py index 2259608..0bddfd0 100644 --- a/core/mail/protocol.py +++ b/core/mail/protocol.py @@ -205,6 +205,10 @@ def receive_email(envelope, log=None): # log.warning("Header to does not match envelope to") # log.info(f"Header to: {header_to}, envelope to: {envelope.rcpt_tos[0]}") + if Email.objects.filter(reference=header_message_id).exists(): # break before issue thread is created + log.warning("Email already exists") + raise Exception("Email already exists") + recipient = envelope.rcpt_tos[0].lower() if envelope.rcpt_tos else header_to.lower() sender = envelope.mail_from if envelope.mail_from else header_from subject = parsed.get('Subject') @@ -263,7 +267,7 @@ class LMTPHandler: content = None try: content = envelope.content - email, new, reply, thread = await database_sync_to_async(receive_email)(envelope, log) + email, new, reply, thread = await receive_email(envelope, log) log.info(f"Created email {email.id}") systemevent = await database_sync_to_async(SystemEvent.objects.create)(type='email received', reference=email.id)