From c4dfe9e536834b9e8db0a9c24e7c6956c079ac41 Mon Sep 17 00:00:00 2001 From: rachitpoudel101 Date: Tue, 17 Jun 2025 10:23:43 +0545 Subject: [PATCH] Fix ticket ID matching across multiple queues --- helpdesk/email.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/helpdesk/email.py b/helpdesk/email.py index f3dff0ac..00e78b39 100644 --- a/helpdesk/email.py +++ b/helpdesk/email.py @@ -1090,9 +1090,31 @@ def extract_email_metadata( else DeleteIgnoredTicketException() ) + # First try to get ticket ID from the current queue's slug ticket_id: typing.Optional[int] = get_ticket_id_from_subject_slug( queue.slug, subject, logger ) + + # If no ticket ID found in the current queue, check all other queues + if ticket_id is None: + # Get all enabled queues except the current one + other_queues = Queue.objects.exclude(id=queue.id).filter( + email_box_type__isnull=False, allow_email_submission=True + ) + + for other_queue in other_queues: + ticket_id = get_ticket_id_from_subject_slug( + other_queue.slug, subject, logger + ) + if ticket_id is not None: + # Found a matching ticket in another queue, use that queue instead + logger.info( + f"Found ticket {ticket_id} matching subject in queue {other_queue.slug} " + f"instead of current queue {queue.slug}" + ) + queue = other_queue + break + files = [] # first message in thread, we save full body to avoid losing forwards and things like that include_chained_msgs = (