diff --git a/include/class.thread.php b/include/class.thread.php index b6fc9b5f15504d779dc7619d0e4a6fc384ab8bd2..ecfae52fd5087da5fa1b92427985f9313681e66d 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 2afbe818f318ea9a54abdccdcf11db8acec8420b..642a4911595644af27b3af7fcd148e0201b357ed 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -1535,7 +1535,7 @@ implements RestrictedAccess, Threadable { } } - function onMessage($message, $autorespond=true) { + function onMessage($message, $autorespond=true, $reopen=true) { global $cfg; $this->isanswered = 0; @@ -1547,7 +1547,7 @@ implements RestrictedAccess, Threadable { // We're also checking autorespond flag because we don't want to // reopen closed tickets on auto-reply from end user. This is not to // confused with autorespond on new message setting - if ($autorespond && $this->isClosed() && $this->isReopenable()) { + if ($reopen && $this->isClosed() && $this->isReopenable()) { $this->reopen(); // Auto-assign to closing staff or the last respondent if the // agent is available and has access. Otherwise, put the ticket back @@ -2334,10 +2334,13 @@ implements RestrictedAccess, Threadable { $autorespond = isset($vars['mailflags']) ? !$vars['mailflags']['bounce'] && !$vars['mailflags']['auto-reply'] : true; + $reopen = $autorespond; // Do not reopen bounces if ($autorespond && $message->isBounceOrAutoReply()) - $autorespond = false; + $autorespond = $reopen= false; + elseif ($autorespond && isset($vars['autorespond'])) + $autorespond = $vars['autorespond']; - $this->onMessage($message, ($autorespond && $alerts)); //must be called b4 sending alerts to staff. + $this->onMessage($message, ($autorespond && $alerts), $reopen); //must be called b4 sending alerts to staff. if ($autorespond && $alerts && $cfg && $cfg->notifyCollabsONNewMessage()) $this->notifyCollaborators($message, array('signature' => '')); @@ -2404,6 +2407,7 @@ implements RestrictedAccess, Threadable { $sentlist[] = $staff->getEmail(); } } + return $message; } @@ -2825,6 +2829,7 @@ implements RestrictedAccess, Threadable { if (!$this->save()) return false; + $vars['note'] = ThreadEntryBody::clean($vars['note']); if ($vars['note']) $this->logNote(_S('Ticket Updated'), $vars['note'], $thisstaff); @@ -2897,9 +2902,11 @@ implements RestrictedAccess, Threadable { } static function isTicketNumberUnique($number) { - return 0 === static::objects() + $num = static::objects() ->filter(array('number' => $number)) - ->count(); + ->count(); + + return ($num === 0); } /* Quick staff's tickets stats */