diff --git a/include/class.thread.php b/include/class.thread.php index a717e89af82c02a521cd8d972ff3821812475c8b..2267056c67db6e1a12b1407e068d12cccea385d6 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -380,6 +380,33 @@ Class ThreadEntry { return $references; } + /** + * Retrieve a list of all the recients of this message if the message + * was received via email. + * + * Returns: + * (array<RFC_822>) list of recipients parsed with the Mail/RFC822 + * address parsing utility. Returns an empty array if the message was + * not received via email. + */ + function getAllEmailRecipients() { + $headers = self::getEmailHeaderArray(); + $recipients = array(); + if (!$headers) + return $recipients; + + foreach (array('To', 'Cc') as $H) { + if (!isset($headers[$H])) + continue; + + if (!($all = Mail_Parse::parseAddressList($headers[$H]))) + continue; + + $recipients = array_merge($recipients, $all); + } + return $recipients; + } + function getUIDFromEmailReference($ref) { $info = unpack('Vtid/Vuid', diff --git a/include/class.ticket.php b/include/class.ticket.php index e7546870eba255341c0819fc8d2af7d98ac5c4eb..b8037ce8fd905e2bf40d0fe75b58a0af67ab96f0 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -1102,15 +1102,24 @@ class Ticket { return; //Who posted the entry? - $uid = 0; + $skip = array(); if ($entry instanceof Message) { $poster = $entry->getUser(); // Skip the person who sent in the message - $uid = $entry->getUserId(); + $skip[$entry->getUserId()] = 1; + // Skip all the other recipients of the message + foreach ($entry->getEmailAllRecipients() as $R) { + foreach ($recipients as $R2) { + if ($R2->getEmail() == ($R->mailbox.'@'.$R->hostname)) { + $skip[$R2->getUserId()] = true; + break; + } + } + } } else { $poster = $entry->getStaff(); // Skip the ticket owner - $uid = $this->getUserId(); + $skip[$this->getUserId()] = 1; } $vars = array_merge($vars, array( @@ -1125,7 +1134,10 @@ class Ticket { $options = array('inreplyto' => $entry->getEmailMessageId(), 'thread' => $entry); foreach ($recipients as $recipient) { - if ($uid == $recipient->getUserId()) continue; + // Skip folks who have already been included on this part of + // the conversation + if (isset($skip[$recipient->getUserId()])) + continue; $notice = $this->replaceVars($msg, array('recipient' => $recipient)); $email->send($recipient, $notice['subj'], $notice['body'], $attachments, $options);