This commit is contained in:
j3d1 2024-05-04 00:37:41 +02:00
parent ce11d2dff1
commit 62ce4e95bf

View file

@ -205,6 +205,10 @@ def receive_email(envelope, log=None):
# log.warning("Header to does not match envelope to") # log.warning("Header to does not match envelope to")
# log.info(f"Header to: {header_to}, envelope to: {envelope.rcpt_tos[0]}") # 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() 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 sender = envelope.mail_from if envelope.mail_from else header_from
subject = parsed.get('Subject') subject = parsed.get('Subject')
@ -263,7 +267,7 @@ class LMTPHandler:
content = None content = None
try: try:
content = envelope.content 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}") log.info(f"Created email {email.id}")
systemevent = await database_sync_to_async(SystemEvent.objects.create)(type='email received', systemevent = await database_sync_to_async(SystemEvent.objects.create)(type='email received',
reference=email.id) reference=email.id)