From 8894880cb9f633387352c1a7e72b7a41e72dec32 Mon Sep 17 00:00:00 2001 From: Julien Nahum Date: Thu, 6 Mar 2025 13:21:12 +0800 Subject: [PATCH] Improve Email Notification Message-ID and Threading Generation - Refactor email header generation for form submission notifications - Use MD5 hashed submission ID for more consistent message threading - Remove timestamp from Message-ID and Thread-Index generation - Ensure emails are threaded only by submission ID - Simplify header creation logic for better email client compatibility --- .../Forms/FormEmailNotification.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/api/app/Notifications/Forms/FormEmailNotification.php b/api/app/Notifications/Forms/FormEmailNotification.php index ed0ad3e54..d20eefa98 100644 --- a/api/app/Notifications/Forms/FormEmailNotification.php +++ b/api/app/Notifications/Forms/FormEmailNotification.php @@ -161,14 +161,11 @@ private function addCustomHeaders(Email $message): void { $formId = $this->event->form->id; $submissionId = $this->event->data['submission_id'] ?? 'unknown'; + $hashedSubmissionId = md5($submissionId); $domain = Str::after(config('app.url'), '://'); - $timestamp = time(); - // Create a unique Message-ID for each submission - $messageId = ""; - - // Create a References header that links to the form, but not to specific submissions - $references = ""; + // Create a unique Message-ID for each submission (without timestamp) + $messageId = ""; // Add our custom Message-ID as X-Custom-Message-ID $message->getHeaders()->addTextHeader('X-Custom-Message-ID', $messageId); @@ -176,11 +173,12 @@ private function addCustomHeaders(Email $message): void // Add X-Entity-Ref-ID header for Google+ notifications $message->getHeaders()->addTextHeader('X-Entity-Ref-ID', $messageId); - // Add References header - $message->getHeaders()->addTextHeader('References', $references); + // Add References header with the same value as Message-ID + // This ensures emails are only threaded by submission ID, not by form ID + $message->getHeaders()->addTextHeader('References', $messageId); // Add a unique Thread-Index to further prevent grouping - $threadIndex = base64_encode(pack('H*', md5($formId . $submissionId . $timestamp))); + $threadIndex = base64_encode(pack('H*', md5($formId . $submissionId))); $message->getHeaders()->addTextHeader('Thread-Index', $threadIndex); }