From f25679ace3d9b485d212bc5303b17aa36ef5ba11 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Thu, 14 Jul 2016 22:17:54 +0000 Subject: [PATCH] Passive Email Threading Add support for threading email conversations happening outside the system. Autoresponders are paused when threading is on passive mode. Alerts may still go out to agents as configured. --- include/class.thread.php | 44 +++++++++++----------------------------- include/class.ticket.php | 2 ++ 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/include/class.thread.php b/include/class.thread.php index b6fc9b5f1..ecfae52fd 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -312,6 +312,7 @@ class Thread extends VerySimpleModel { 'reply_to' => $entry, 'recipients' => $mailinfo['recipients'], 'to-email-id' => $mailinfo['to-email-id'], + 'autorespond' => !isset($mailinfo['passive']), ); // XXX: Is this necessary? @@ -1178,40 +1179,19 @@ implements TemplateVariable { // ThreadEntry was positively identified return $t; } + } - // Try to determine if it's a reply to a tagged email. - // (Deprecated) - $ref = null; - if (strpos($mid, '+')) { - list($left, $right) = explode('@',$mid); - list($left, $ref) = explode('+', $left); - $mid = "$left@$right"; - } - $entries = ThreadEntry::objects() - ->filter(array('email_info__mid' => $mid)) - ->order_by(false); - foreach ($entries as $t) { - // Capture the first match thread item - if (!$thread) - $thread = $t; - // We found a match - see if we can ID the user. - // XXX: Check access of ref is enough? - if ($ref && ($uid = $t->getUIDFromEmailReference($ref))) { - if ($ref[0] =='s') //staff - $mailinfo['staffId'] = $uid; - else // user or collaborator. - $mailinfo['userId'] = $uid; - - // Best possible case — found the thread and the - // user - 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) { + $mailinfo['passive'] = true; + return $entry; } - // Second best case — found a thread but couldn't identify the - // user from the header. Return the first thread entry matched - if ($thread) - return $thread; // Search for ticket by the [#123456] in the subject line // This is the last resort - emails must match to avoid message diff --git a/include/class.ticket.php b/include/class.ticket.php index d126259da..a8ccd9585 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -2336,6 +2336,8 @@ implements RestrictedAccess, Threadable { : true; if ($autorespond && $message->isBounceOrAutoReply()) $autorespond = false; + elseif ($autorespond && isset($vars['autorespond'])) + $autorespond = $vars['autorespond']; $this->onMessage($message, ($autorespond && $alerts)); //must be called b4 sending alerts to staff. -- GitLab