From 469889d24a4bd89ba8d2fe552d910c55aeb9a57c Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Tue, 31 Mar 2015 11:29:27 -0500 Subject: [PATCH] thread: Avoid crash with multiple Message-ID headers --- include/class.mailfetch.php | 11 ++++++++--- include/class.mailparse.php | 5 ++++- include/class.thread.php | 3 ++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php index c4ecd0e7b..2950e7d14 100644 --- a/include/class.mailfetch.php +++ b/include/class.mailfetch.php @@ -346,10 +346,15 @@ class MailFetcher { // Ensure we have a message-id. If unable to read it out of the // email, use the hash of the entire email headers - if (!$header['mid'] && $header['header']) - if (!($header['mid'] = Mail_Parse::findHeaderEntry($header['header'], - 'message-id'))) + if (!$header['mid'] && $header['header']) { + $header['mid'] = Mail_Parse::findHeaderEntry($header['header'], + 'message-id'); + + if (is_array($header['mid'])) + $header['mid'] = array_pop(array_filter($header['mid'])); + if (!$header['mid']) $header['mid'] = '<' . md5($header['header']) . '@local>'; + } return $header; } diff --git a/include/class.mailparse.php b/include/class.mailparse.php index 969cc56e4..f8209f395 100644 --- a/include/class.mailparse.php +++ b/include/class.mailparse.php @@ -242,8 +242,11 @@ class Mail_Parse { } function getMessageId(){ - if (!($mid = $this->struct->headers['message-id'])) + if (($mid = $this->struct->headers['message-id']) && is_array($mid)) + $mid = array_pop(array_filter($mid)); + if (!$mid) $mid = sprintf('<%s@local>', md5($this->getHeader())); + return $mid; } diff --git a/include/class.thread.php b/include/class.thread.php index 019cd8b65..d56b16a9f 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -803,7 +803,8 @@ Class ThreadEntry { function saveEmailInfo($vars) { - if(!$vars || !$vars['mid']) + // Don't save empty message ID + if (!$vars || !$vars['mid']) return 0; $this->ht['email_mid'] = $vars['mid']; -- GitLab