diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index 68aaf24ae5180137412e5f05cad11a23b2e9c0f8..626f51af081721166e0d728e88cd615adc05423c 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -504,7 +504,8 @@ class TicketsAjaxAPI extends AjaxController { if ($user->getId() == $ticket->getOwnerId()) $errors['err'] = sprintf('Ticket owner, %s, is a collaborator by default!', $user->getName()); - elseif (($c=$ticket->addCollaborator($user, $errors))) { + elseif (($c=$ticket->addCollaborator($user, + array('isactive'=>1), $errors))) { $note = Format::htmlchars(sprintf('%s <%s> added as a collaborator', $c->getName(), $c->getEmail())); $ticket->logNote('New Collaborator Added', $note, diff --git a/include/api.tickets.php b/include/api.tickets.php index 45cbc2db97eccb120b0f22f7f47ba97ec8026ced..daa7ffe431a17d43d39227347f4b3efc0ac8053b 100644 --- a/include/api.tickets.php +++ b/include/api.tickets.php @@ -40,7 +40,7 @@ class TicketApiController extends ApiController { $supported = array_merge($supported, array('header', 'mid', 'emailId', 'ticketId', 'reply-to', 'reply-to-name', 'in-reply-to', 'references', - 'recipients' => array("*" => array("name", "email")) + 'recipients' => array('*' => array('name', 'email', 'source')) )); $supported['attachments']['*'][] = 'cid'; diff --git a/include/class.collaborator.php b/include/class.collaborator.php index bf57617d70b6f7555cae73db9403b5b79d47d8f7..bf823dacdb366279ec88b5de9657843283f72ba9 100644 --- a/include/class.collaborator.php +++ b/include/class.collaborator.php @@ -101,16 +101,17 @@ class Collaborator { static function add($info, &$errors) { - if(!$info || !$info['ticketId'] || !$info['userId']) + if (!$info || !$info['ticketId'] || !$info['userId']) $errors['err'] = 'Invalid or missing information'; - elseif(($c=self::lookup($info))) + elseif (($c=self::lookup($info))) $errors['err'] = sprintf('%s is already a collaborator', $c->getName()); - if($errors) return false; + if ($errors) return false; $sql='INSERT INTO '.TICKET_COLLABORATOR_TABLE - .' SET isactive=1, updated=NOW() ' + .' SET updated=NOW() ' + .' ,isactive='.db_input(isset($info['isactive']) ? $info['isactive'] : 0) .' ,ticket_id='.db_input($info['ticketId']) .' ,user_id='.db_input($info['userId']); diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php index 2b05c3a593fbaef7620f5259bc1728f065834153..d962e1e1fe22d0f3d08e00bc9d43a404eb223757 100644 --- a/include/class.mailfetch.php +++ b/include/class.mailfetch.php @@ -286,18 +286,21 @@ class MailFetcher { // Put together a list of recipients $tolist = array(); if($headerinfo->to) - $tolist = array_merge($tolist, $headerinfo->to); + $tolist['to'] = $headerinfo->to; if($headerinfo->cc) - $tolist = array_merge($tolist, $headerinfo->cc); + $tolist['cc'] = $headerinfo->cc; $header['recipients'] = array(); - foreach($tolist as $addr) { - if(!($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) { - $header['recipients'][] = array( - 'name' => $this->mime_decode(@$addr->personal), - 'email' => strtolower($addr->mailbox).'@'.$addr->host); - } elseif(!$header['emailId']) { - $header['emailId'] = $emailId; + foreach($tolist as $source => $list) { + foreach($list as $addr) { + if(!($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) { + $header['recipients'][] = array( + 'source' => $source, + 'name' => $this->mime_decode(@$addr->personal), + 'email' => strtolower($addr->mailbox).'@'.$addr->host); + } elseif(!$header['emailId']) { + $header['emailId'] = $emailId; + } } } diff --git a/include/class.mailparse.php b/include/class.mailparse.php index 42d4abe242eb9e6b4e202a83d589076e3b858995..48cf98a59107736936b35d2738f734c3ad5f0e94 100644 --- a/include/class.mailparse.php +++ b/include/class.mailparse.php @@ -393,18 +393,21 @@ class EmailDataParser { $data['recipients'] = array(); $tolist = array(); if(($to = $parser->getToAddressList())) - $tolist = array_merge($tolist, $to); + $tolist['to'] = $to; if(($cc = $parser->getCcAddressList())) - $tolist = array_merge($tolist, $cc); - - foreach ($tolist as $addr) { - if(!($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) { - $data['recipients'][] = array( - 'name' => trim(@$addr->personal, '"'), - 'email' => strtolower($addr->mailbox).'@'.$addr->host); - } elseif(!$data['emailId']) { - $data['emailId'] = $emailId; + $tolist['cc'] = $cc; + + foreach ($tolist as $source => $list) { + foreach($list as $addr) { + if(!($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) { + $data['recipients'][] = array( + 'source' => $source, + 'name' => trim(@$addr->personal, '"'), + 'email' => strtolower($addr->mailbox).'@'.$addr->host); + } elseif(!$data['emailId']) { + $data['emailId'] = $emailId; + } } } @@ -412,8 +415,8 @@ class EmailDataParser { if(!$data['emailId']) { unset($data['recipients']); $emailId = 0; - if($bcc = $parser->getBccAddressList()) - foreach ($bcc as $addr) { + if($bcc = $parser->getBccAddressList()) { + foreach ($bcc as $addr) if(($emailId=Email::getIdByEmail($addr->mailbox.'@'.$addr->host))) break; } diff --git a/include/class.ticket.php b/include/class.ticket.php index 5f829a86533c90aacb99dbf137a9f3d35b792da7..3238c62f56d3355276d8899a85a33ff9bffdb14e 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -586,15 +586,15 @@ class Ticket { return $this->collaborators; } - function addCollaborator($user, &$errors) { + function addCollaborator($user, $vars, &$errors) { - if(!$user || $user->getId()==$this->getOwnerId()) + if (!$user || $user->getId()==$this->getOwnerId()) return null; - $vars = array( + $vars = array_merge(array( 'ticketId' => $this->getId(), - 'userId' => $user->getId()); - if(!($c=Collaborator::add($vars, $errors))) + 'userId' => $user->getId()), $vars); + if (!($c=Collaborator::add($vars, $errors))) return null; $this->collaborators = null; @@ -1459,15 +1459,22 @@ class Ticket { //Add email recipients as collaborators if ($vars['recipients']) { + //TODO: Disable collaborators added by other collaborator + // staff approval will be required. + $info = array('isactive' => 1); $collabs = array(); foreach ($vars['recipients'] as $recipient) { if (($user=User::fromVars($recipient))) - if ($c=$this->addCollaborator($user, $errors)) - $collabs[] = $c; + if ($c=$this->addCollaborator($user, $info, $errors)) + $collabs[] = sprintf('%s %s', + (string) $c, + $recipient['source'] ? " ({$recipient['source']}) " : '' + ); } //TODO: Can collaborators add others? if ($collabs) { - $this->logNote('Collaborators CCed by enduser', + //TODO: Change EndUser to name of user. + $this->logNote('Collaborators added by enduser', implode("<br>", $collabs), 'EndUser', false); } }