automatically attach mails addressed to ticket+<uuid>@domain.tld to ticket with matching uuid

This commit is contained in:
j3d1 2024-01-13 00:00:19 +01:00
parent 5a1cfedd56
commit 9269f2ec48
2 changed files with 56 additions and 2 deletions

View file

@ -82,7 +82,13 @@ async def send_smtp(message, log):
await aiosmtplib.send(message, hostname="127.0.0.1", port=25, use_tls=False, start_tls=False)
def find_active_issue_thread(in_reply_to, subject=None):
def find_active_issue_thread(in_reply_to, address, subject):
from re import match
uuid_match = match(r'^ticket\+([a-f0-9-]{36})@', address)
if uuid_match:
issue = IssueThread.objects.filter(uuid=uuid_match.group(1))
if issue.exists():
return issue.first(), False
reply_to = Email.objects.filter(reference=in_reply_to)
if reply_to.exists():
return reply_to.first().issue_thread, False
@ -172,7 +178,7 @@ def receive_email(envelope, log=None):
subject = unescape_and_decode_base64(subject)
target_event = find_target_event(recipient)
active_issue_thread, new = find_active_issue_thread(header_in_reply_to, subject)
active_issue_thread, new = find_active_issue_thread(header_in_reply_to, recipient, subject)
email = Email.objects.create(
sender=sender, recipient=recipient, body=body, subject=subject, reference=header_message_id,