From 70704c2befd2f4bffb4c7afbf407d2bb0600f6f9 Mon Sep 17 00:00:00 2001 From: FreeScout Date: Sat, 17 Nov 2018 23:07:17 -0800 Subject: [PATCH] Fix processing References header on fetching emails --- app/Console/Commands/FetchEmails.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/FetchEmails.php b/app/Console/Commands/FetchEmails.php index 48d229b0..229f5673 100644 --- a/app/Console/Commands/FetchEmails.php +++ b/app/Console/Commands/FetchEmails.php @@ -207,8 +207,15 @@ class FetchEmails extends Command if (!is_array($references)) { $references = array_filter(preg_split('/[, <>]/', $references)); } - // Maybe we need to check all references - $prev_message_id = $references[0]; + // Find first non-empty reference + if (is_array($references)) { + foreach ($references as $reference) { + if (!empty(trim($reference))) { + $prev_message_id = trim($reference); + break; + } + } + } } // Some mail service providers change Message-ID of the outgoing email,