From 85bfc48bdd8c2fbd79642fc49f6918f167bb945d Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Tue, 25 Oct 2016 05:37:12 +0000
Subject: [PATCH] oops: Missing Message-ID & References

Address cases where incoming email doesn't have message-id or references
---
 include/class.thread.php | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/include/class.thread.php b/include/class.thread.php
index c3fb481e6..164624d35 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -1122,11 +1122,13 @@ implements TemplateVariable {
     function lookupByEmailHeaders(&$mailinfo, &$seen=false) {
         // Search for messages using the References header, then the
         // in-reply-to header
-        if ($entry = ThreadEntry::objects()
-            ->filter(array('email_info__mid' => $mailinfo['mid']))
-            ->order_by(false)
-            ->first()
-        ) {
+        if ($mailinfo['mid'] &&
+                ($entry = ThreadEntry::objects()
+                 ->filter(array('email_info__mid' => $mailinfo['mid']))
+                 ->order_by(false)
+                 ->first()
+                 )
+         ) {
             $seen = true;
             return $entry;
         }
@@ -1189,15 +1191,15 @@ implements TemplateVariable {
                 return $t;
             }
         }
-
         // Passive threading - listen mode
-        $entry = ThreadEntry::objects()
-            ->filter(array(
-                'email_info__mid__in' => array_map(
-                    function ($a) { return "<$a>"; },
-                $possibles)))
-            ->first();
-        if ($entry) {
+        if (count($possibles)
+                && ($entry = ThreadEntry::objects()
+                    ->filter(array('email_info__mid__in' => array_map(
+                        function ($a) { return "<$a>"; },
+                    $possibles)))
+                    ->first()
+                )
+         ) {
             $mailinfo['passive'] = true;
             return $entry;
         }
-- 
GitLab