diff --git a/include/class.mailer.php b/include/class.mailer.php index 23270c845956509386b23921aa46cb924d1badb9..a99fb7a6acefd2058ec53c2dbc5b6c11d9bd5ae3 100644 --- a/include/class.mailer.php +++ b/include/class.mailer.php @@ -144,10 +144,15 @@ class Mailer { $sig = $this->getEmail()?$this->getEmail()->getEmail():'@osTicketMailer'; if ($recipient instanceof EmailContact) { // Create a tag for the outbound email - $tag = pack('VVa', + $entry = (isset($options['thread']) && $options['thread'] instanceof ThreadEntry) + ? $options['thread'] : false; + $thread = $entry ? $entry->getThread() + : (isset($options['thread']) && $options['thread'] instanceof Thread + ? $options['thread']->getId() : false); + $tag = pack('VVVa', $recipient->getId(), - (isset($options['thread']) && $options['thread'] instanceof ThreadEntry) - ? $options['thread']->getId() : 0, + $entry ? $entry->getId() : 0, + $thread ? $thread->getId() : 0, ($recipient instanceof Staff ? 'S' : ($recipient instanceof TicketOwner ? 'U' : ($recipient instanceof Collaborator ? 'C' @@ -157,7 +162,7 @@ class Mailer { // Sign the tag with the system secret salt $sig = '@' . substr(hash_hmac('sha1', $tag.$rand, SECRET_SALT), -10); } - return sprintf('<A%s-%s-%s-%s>', + return sprintf('<B%s-%s-%s-%s>', static::getSystemMessageIdCode(), $rand, $tag, $sig); } @@ -180,6 +185,7 @@ class Mailer { * 'version' - (string|FALSE) version code of the message id * 'code' - (string) unique but predictable help desk message-id * 'id' - (string) random characters serving as the unique id + * 'entryId' - (int) thread-entry-id from which the message originated * 'threadId' - (int) thread-id from which the message originated * 'staffId' - (int|null) staff the email was originally sent to * 'userId' - (int|null) user the email was originally sent to @@ -207,29 +213,32 @@ class Mailer { // Detect the MessageId version, which should be the tenth char of // the second segment $rv['version'] = @$parts[0][0]; + $format = 'Vuid/VentryId/auserClass'; switch ($rv['version']) { - case 'A': - default: - list($rv['code'], $rv['id'], $tag) = $parts; - // Drop the leading version code - $rv['code'] = substr($rv['code'], 1); - // Verify tag signature - $chksig = substr(hash_hmac('sha1', $tag.$rv['id'], SECRET_SALT), -10); - if ($tag && $sig == $chksig && ($tag = base64_decode($tag))) { - // Find user and ticket id - $rv += unpack('Vuid/VthreadId/auserClass', $tag); - // Attempt to make the user-id more specific - $classes = array( - 'S' => 'staffId', 'U' => 'userId' - ); - if (isset($classes[$rv['userClass']])) - $rv[$classes[$rv['userClass']]] = $rv['uid']; - } - // Round-trip detection - the first section is the local - // system's message-id code - $rv['loopback'] = (0 === strcasecmp($rv['code'], - static::getSystemMessageIdCode())); - break; + case 'B': + $format = 'Vuid/VentryId/VthreadId/auserClass'; + case 'A': + default: + list($rv['code'], $rv['id'], $tag) = $parts; + // Drop the leading version code + $rv['code'] = substr($rv['code'], 1); + // Verify tag signature + $chksig = substr(hash_hmac('sha1', $tag.$rv['id'], SECRET_SALT), -10); + if ($tag && $sig == $chksig && ($tag = base64_decode($tag))) { + // Find user and ticket id + $rv += unpack($format, $tag); + // Attempt to make the user-id more specific + $classes = array( + 'S' => 'staffId', 'U' => 'userId' + ); + if (isset($classes[$rv['userClass']])) + $rv[$classes[$rv['userClass']]] = $rv['uid']; + } + // Round-trip detection - the first section is the local + // system's message-id code + $rv['loopback'] = (0 === strcasecmp($rv['code'], + static::getSystemMessageIdCode())); + break; } return $rv; } diff --git a/include/class.thread.php b/include/class.thread.php index 65487811f43203102fcfd012d57e743ebf4e6c49..b8b5badebdb3f37ce0a30c7e86cb3ba51abdfe2c 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -779,8 +779,8 @@ class ThreadEntry extends VerySimpleModel { // to true. $mid_info = Mailer::decodeMessageId($mid); if ($mid_info['loopback'] && isset($mid_info['uid']) - && @$mid_info['threadId'] - && ($t = ThreadEntry::lookup($mid_info['threadId'])) + && @$mid_info['entryId'] + && ($t = ThreadEntry::lookup($mid_info['entryId'])) ) { if (@$mid_info['userId']) { $mailinfo['userId'] = $mid_info['userId']; diff --git a/include/class.ticket.php b/include/class.ticket.php index 0c073e11639790a5c1c8cc7181d8334d13fdc4d1..41cc699305670f58ecbdabbaa4aa60abb98b50d7 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -1273,6 +1273,11 @@ implements RestrictedAccess, Threadable { 'thread'=>$message ); } + else { + $options += array( + 'thread' => $this->getThread(), + ); + } //Send auto response - if enabled. if($autorespond