diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php index 7644cbb7eaee141a20de00e0ae705336ff3770ed..18f42a58bd4061612e2a30598e66718adde047c2 100644 --- a/include/class.mailfetch.php +++ b/include/class.mailfetch.php @@ -335,23 +335,31 @@ class MailFetcher { $header['system_emails'] = array(); $header['recipients'] = array(); + $header['thread_entry_recipients'] = array(); foreach($tolist as $source => $list) { foreach($list as $addr) { if (!($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) { //Skip virtual Delivered-To addresses if ($source == 'delivered-to') continue; + $name = $this->mime_decode(@$addr->personal); + $email = strtolower($addr->mailbox).'@'.$addr->host; $header['recipients'][] = array( 'source' => sprintf(_S("Email (%s)"),$source), - 'name' => $this->mime_decode(@$addr->personal), - 'email' => strtolower($addr->mailbox).'@'.$addr->host); + 'name' => $name, + 'email' => $email); + + $header['thread_entry_recipients'][$source][] = sprintf('%s <%s>', $name, $email); } elseif ($emailId) { $header['system_emails'][] = $emailId; + $system_email = Email::lookup($emailId); + $header['thread_entry_recipients']['to'][] = (string) $system_email; if (!$header['emailId']) $header['emailId'] = $emailId; } } } + $header['thread_entry_recipients']['to'] = array_unique($header['thread_entry_recipients']['to']); //See if any of the recipients is a delivered to address if ($tolist['delivered-to']) { diff --git a/include/class.mailparse.php b/include/class.mailparse.php index 58eb2a984e157f17ba0a0d87b3b295aedfeb420e..7d474c411f3ad9da889408f396e7c2fb9b617f9f 100644 --- a/include/class.mailparse.php +++ b/include/class.mailparse.php @@ -648,23 +648,31 @@ class EmailDataParser { $tolist['delivered-to'] = $dt; $data['system_emails'] = array(); + $data['thread_entry_recipients'] = array(); foreach ($tolist as $source => $list) { foreach($list as $addr) { if (!($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) { //Skip virtual Delivered-To addresses if ($source == 'delivered-to') continue; + $name = $this->mime_decode(@$addr->personal); + $email = strtolower($addr->mailbox).'@'.$addr->host; $data['recipients'][] = array( 'source' => sprintf(_S("Email (%s)"), $source), - 'name' => trim(@$addr->personal, '"'), - 'email' => strtolower($addr->mailbox).'@'.$addr->host); + 'name' => $name, + 'email' => $email); + + $data['thread_entry_recipients'][$source][] = sprintf('%s <%s>', $name, $email); } elseif ($emailId) { $data['system_emails'][] = $emailId; + $system_email = Email::lookup($emailId); + $data['thread_entry_recipients']['to'][] = (string) $system_email; if (!$data['emailId']) $data['emailId'] = $emailId; } } } + $data['thread_entry_recipients']['to'] = array_unique($data['thread_entry_recipients']['to']); /* * In the event that the mail was delivered to the system although none of the system diff --git a/include/class.thread.php b/include/class.thread.php index e8da34ca0e93b089a4f2c800cd25d6ba203979cd..b1a0f1bf7a0eb462bf5df7acb3ff0eae4a3321ad 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -428,6 +428,7 @@ implements Searchable { 'ip' => '', 'reply_to' => $entry, 'recipients' => $mailinfo['recipients'], + 'thread_entry_recipients' => $mailinfo['thread_entry_recipients'], 'to-email-id' => $mailinfo['to-email-id'], 'autorespond' => !isset($mailinfo['passive']), ); @@ -1504,8 +1505,9 @@ implements TemplateVariable { )); //add recipients to thread entry - if ($vars['recipients']) - $entry->recipients = json_encode($vars['recipients']); + if ($vars['thread_entry_recipients']) + $entry->recipients = json_encode($vars['thread_entry_recipients']); + if (Collaborator::getIdByUserId($vars['userId'], $vars['threadId'])) $entry->flags |= ThreadEntry::FLAG_COLLABORATOR; diff --git a/include/class.ticket.php b/include/class.ticket.php index bec6136bfee9b6ce72375cc15cca22f2db1b0400..615931fa0bca9a134e6ac543ee21651ce55c69dd 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -1629,14 +1629,6 @@ implements RestrictedAccess, Threadable, Searchable { $poster = User::lookup($entry->user_id); $posterEmail = $poster->getEmail()->address; - $recipients = array(); - if($vars['ccs']) { - foreach ($vars['ccs'] as $cc) { - $collab = Collaborator::getIdByUserId($cc, $this->getThread()->getId()); - $recipients[] = Collaborator::lookup($collab); - } - } - $vars = array_merge($vars, array( 'message' => (string) $entry, 'poster' => $poster ?: _S('A collaborator'), @@ -1658,35 +1650,22 @@ implements RestrictedAccess, Threadable, Searchable { } } - $collaborators = array(); - $collabsCc = array(); - foreach ($recipients as $recipient) { - if(get_class($recipient) == 'Collaborator') { - if ($recipient->isCc()) - $collabsCc[] = $recipient->getEmail()->address; - } + foreach ($recipients as $key => $recipient) { + $recipient = $recipient->getContact(); if(get_class($recipient) == 'TicketOwner') - $owner = $recipient; - } + $owner = $recipient; - foreach ($collabsCc as $cc) { - if (in_array($cc, $skip)) - continue; - elseif ($cc != $posterEmail) - $collaborators[] = $cc; - } + if ((get_class($recipient) == 'Collaborator' ? $recipient->getUserId() : $recipient->getId()) == $entry->user_id) + unset($recipients[$key]); + } - //the ticket user is a recipient + //see if the ticket user is a recipient if ($owner->getEmail()->address != $poster->getEmail()->address && !in_array($owner->getEmail()->address, $skip)) $owner_recip = $owner->getEmail()->address; - $collaborators['cc'] = $collaborators; - - //collaborator email sent out - if ($collaborators['cc'] || $owner_recip) { - //say dear collaborator if the ticket user is not a recipient - if (!$owner_recip) { + //say dear collaborator if the ticket user is not a recipient + if (!$owner_recip) { $nameFormats = array_keys(PersonsName::allFormats()); $names = array(); foreach ($nameFormats as $key => $value) { @@ -1694,16 +1673,13 @@ implements RestrictedAccess, Threadable, Searchable { } $names = array_merge($names, array('recipient' => $recipient)); $cnotice = $this->replaceVars($msg, $names); - } - - //otherwise address email to ticket user - else + } + //otherwise address email to ticket user + else $cnotice = $this->replaceVars($msg, array('recipient' => $owner)); - //if the ticket user is a recipient, put them in to address otherwise, cc all recipients - $email->send($owner_recip ? $owner_recip : '', $cnotice['subj'], $cnotice['body'], $attachments, - $options, $collaborators); - } + $email->send($recipients, $cnotice['subj'], $cnotice['body'], $attachments, + $options); } function onMessage($message, $autorespond=true, $reopen=true) { @@ -2902,14 +2878,14 @@ implements RestrictedAccess, Threadable, Searchable { if (!$vars['ip_address'] && $_SERVER['REMOTE_ADDR']) $vars['ip_address'] = $_SERVER['REMOTE_ADDR']; - // Add new collaboratorss (if any). + // Add new collaborators (if any). if (isset($vars['ccs']) && count($vars['ccs'])) - $this->addCollaborators($vars['ccs']); + $this->addCollaborators($vars['ccs'], array(), $errors); // Get active recipients of the response $recipients = $this->getRecipients($vars['reply-to'], $vars['ccs']); if ($recipients instanceof MailingList) - $vars['recipients'] = $recipients->getEmailAddresses(); + $vars['thread_entry_recipients'] = $recipients->getEmailAddresses(); if (!($response = $this->getThread()->addResponse($vars, $errors))) return null; diff --git a/include/class.util.php b/include/class.util.php index 962ef6f7a33efd342c3365b7c723d520ef9bc4fc..a3bc2305d130c8b7bf5885cc4df99f4dcf1cae22 100644 --- a/include/class.util.php +++ b/include/class.util.php @@ -20,6 +20,10 @@ implements EmailContact { $this->type = $type; } + function getContact() { + return $this->contact; + } + function getId() { return $this->contact->getId(); } diff --git a/include/staff/templates/thread-email-recipients.tmpl.php b/include/staff/templates/thread-email-recipients.tmpl.php index 3bae51c02fab5ae3b20fc24c1c7e22f78427a8c2..6935c1fa873ec8cad13273bc580a05f960147b49 100644 --- a/include/staff/templates/thread-email-recipients.tmpl.php +++ b/include/staff/templates/thread-email-recipients.tmpl.php @@ -11,8 +11,8 @@ if (!$_REQUEST['mode']) { ?> $recipients = Format::htmlchars($recipients); foreach ($recipients as $k => $v) { echo sprintf('<tr><td nowrap width="5" valign="top"><b>%s</b>:</td><td>%s</td></tr>', - ucfirst($k), - implode('<br>', $v) + ucfirst($k), + is_array($v) ? implode('<br>', $v) : $v ); } ?> diff --git a/include/staff/templates/thread-entry.tmpl.php b/include/staff/templates/thread-entry.tmpl.php index 3407e534b966dd6d9a588e45367e70a3731c789f..f45f20b028afdd17fd5b6b16fc11e84042c14bbf 100644 --- a/include/staff/templates/thread-entry.tmpl.php +++ b/include/staff/templates/thread-entry.tmpl.php @@ -55,10 +55,10 @@ if ($user && $cfg->isAvatarsEnabled()) <span class="label label-bare"><?php echo __('Resent'); ?></span> <?php } if ($entry->flags & ThreadEntry::FLAG_REPLY_ALL) { ?> - <span class="label label-bare"><?php echo __('Reply All'); ?></span> + <span class="label label-bare"><i class="icon-group"></i></span> <?php } if ($entry->flags & ThreadEntry::FLAG_REPLY_USER) { ?> - <span class="label label-bare"><?php echo __('Reply to User'); ?></span> + <span class="label label-bare"><i class="icon-user"></i></span> <?php } if ($entry->flags & ThreadEntry::FLAG_COLLABORATOR && $entry->type == 'M') { ?> <span class="label label-bare"><?php echo __('Cc Collaborator'); ?></span>