diff --git a/include/class.mailer.php b/include/class.mailer.php index 51cbab842478edffe874978856699c072cb4cec3..017d7fbb0ec99267cf1e51920a4e2dd62a88e13d 100644 --- a/include/class.mailer.php +++ b/include/class.mailer.php @@ -305,28 +305,8 @@ class Mailer { require_once (PEAR_DIR.'Mail.php'); // PEAR Mail package require_once (PEAR_DIR.'Mail/mime.php'); // PEAR Mail_Mime packge - $messageId = $this->getMessageId($recipients, $options); - - - if (is_object($recipient) && is_callable(array($recipient, 'getEmail'))) { - // Add personal name if available - if (is_callable(array($recipient, 'getName'))) { - $to = sprintf('"%s" <%s>', - $recipient->getName()->getOriginal(), $recipient->getEmail() - ); - } - else { - $to = $recipient->getEmail(); - } - } else { - $to = $recipient; - } - - //do some cleanup - $to = preg_replace("/(\r\n|\r|\n)/s",'', trim($to)); $subject = preg_replace("/(\r\n|\r|\n)/s",'', trim($subject)); - $headers = array ( 'From' => $this->getFromAddress($options), 'Subject' => $subject, @@ -350,12 +330,12 @@ class Mailer { $entry = null; switch (true) { - case $recipient instanceof TicketOwner: - case $recipient instanceof Collaborator: + case $recipients instanceof TicketOwner: + case $recipients instanceof Collaborator: $entry = $thread->getLastEmailMessage(array( - 'user_id' => $recipient->getUserId())); + 'user_id' => $recipients->getUserId())); break; - case $recipient instanceof Staff: + case $recipients instanceof Staff: //XXX: is it necessary ?? break; } @@ -592,8 +572,6 @@ class Mailer { if ($this->getEmail()) $args = array('-f '.$this->getEmail()->getEmail()); $mail = mail::factory('mail', $args); - // Ensure the To: header is properly encoded. - $to = $headers['To']; $result = $mail->send($to, $headers, $body); if(!PEAR::isError($result)) return $messageId; diff --git a/include/class.thread.php b/include/class.thread.php index 3393043e60e91aed5130ae70bf863e26c44c56e3..5545b2db6d1f7c8978602087f37a5f95cbc8d5f6 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -1476,11 +1476,11 @@ implements TemplateVariable { function setReplyFlag($entry, $replyType) { switch ($replyType) { - case 'reply-all': + case 'all': return $entry->flags |= ThreadEntry::FLAG_REPLY_ALL; break; - case 'reply-user': + case 'user': return $entry->flags |= ThreadEntry::FLAG_REPLY_USER; break; } @@ -1530,7 +1530,7 @@ implements TemplateVariable { $ticketUser = Ticket::objects()->filter(array('ticket_id'=>$ticket[0]))->values_flat('user_id')->first(); //User - if ($ticketUser && Ticket::checkReply('user', $vars['emailreply'])) { + if ($ticketUser && strcasecmp('none', $vars['reply-to'])) { $uEmail = UserEmailModel::objects()->filter(array('user_id'=>$ticketUser[0]))->values_flat('address')->first(); $u = array(); $u[$ticketUser[0]] = $uEmail[0]; @@ -1541,15 +1541,15 @@ implements TemplateVariable { $entry->flags |= ThreadEntry::FLAG_COLLABORATOR; //add reply type flag - self::setReplyFlag($entry, $vars['emailreply']); + self::setReplyFlag($entry, $vars['reply-to']); //Cc collaborators - if ($vars['ccs'] && Ticket::checkReply('cc', $vars['emailreply'])) { + if ($vars['ccs'] && !strcasecmp('all', $vars['reply-to'])) { $cc = Collaborator::getCollabList($vars['ccs']); $recipients['cc'] = $cc; } - if ($vars['emailreply'] != '0' && $recipients) + if ($vars['reply-to'] != 'none' && $recipients) $entry->recipients = json_encode($recipients); if ($entry->format == 'html') diff --git a/include/class.ticket.php b/include/class.ticket.php index 7d1182062315feb2786f85716e1b3b72de475c8d..5b276e7e8a4e2e275d7e05257045723741f1f1c7 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -1095,6 +1095,25 @@ implements RestrictedAccess, Threadable, Searchable { return $c; } + function addCollaborators($users, $vars, &$errors, $event=true) { + + if (!$users || !is_array($users)) + return null; + + $collabs = $this->getCollaborators(); + $new = array(); + foreach ($users as $user) { + if (!($user instanceof User) + && !($user = User::lookup($user))) + continue; + if ($collabs->findFirst(array('user_id' => $user->getId()))) + continue; + if ($c=$this->addCollaborator($user, $vars, $errors, $event)) + $new[] = $c; + } + return $new; + } + //XXX: Ugly for now function updateCollaborators($vars, &$errors) { global $thisstaff; @@ -1386,17 +1405,6 @@ implements RestrictedAccess, Threadable, Searchable { return false; } - function checkReply($userType, $replyType) { - if ($userType == 'cc' && $replyType == 'reply-all') - return true; - - if ($userType == 'user' && ($replyType == 'reply-all' || $replyType == 'reply-user')) - return true; - - return false; - } - - function setAnsweredState($isanswered) { $this->isanswered = $isanswered; return $this->save(); @@ -2959,8 +2967,9 @@ implements RestrictedAccess, Threadable, Searchable { // Get active recipients $recipients = new MailingList(); - $recioients->add($this->getOwner()); - if ($collabs = $this->getActiveCollaborators()) { + $recipients->add($this->getOwner()); + if (!strcasecmp('all', $vars['reply-to']) + && ($collabs = $this->getActiveCollaborators())){ foreach ($collabs as $c) if ($vars['ccs'] && in_array($c->getUserId(), $vars['ccs'])) @@ -4042,33 +4051,28 @@ implements RestrictedAccess, Threadable, Searchable { if (!($ticket=self::create($create_vars, $errors, 'staff', false))) return false; - $collabsCc = array(); - if (isset($vars['ccs'])) { - foreach ($vars['ccs'] as $uid) { - $ccuser = User::lookup($uid); - - if ($ccuser && !$existing = Collaborator::getIdByUserId($ccuser->getId(), $ticket->getThreadId())) { - $collabsCc[] = $ccuser->getEmail()->address; + if (isset($vars['ccs'])) + $ticket->addCollaborators($vars['ccs'], array(), $errors); - if (($c2=$ticket->getThread()->addCollaborator($ccuser,array(), $errors))) - $c2->setCc(); - } - } - $collabsCc['cc'] = $collabsCc; - } + if (strcasecmp('user', $vars['reply-to'])) + $recipients = $ticket->getRecipients(); + else + $recipients = $ticket->getOwner(); $vars['msgId']=$ticket->getLastMsgId(); // Effective role for the department $role = $ticket->getRole($thisstaff); + $alert = strcasecmp('none', $vars['reply-to']); + // post response - if any $response = null; if($vars['response'] && $role->hasPerm(Ticket::PERM_REPLY)) { $vars['response'] = $ticket->replaceVars($vars['response']); // $vars['cannedatachments'] contains the attachments placed on // the response form. - $response = $ticket->postReply($vars, $errors, is_null($vars['emailreply']) ?: $vars['emailreply'] === "0"); + $response = $ticket->postReply($vars, $errors, $alert && !$cfg->notifyONNewStaffTicket()); } // Not assigned...save optional note if any @@ -4080,7 +4084,7 @@ implements RestrictedAccess, Threadable, Searchable { } if (!$cfg->notifyONNewStaffTicket() - || !isset($vars['emailreply']) + || !$alert || !($dept=$ticket->getDept()) ) { return $ticket; //No alerts. @@ -4127,13 +4131,8 @@ implements RestrictedAccess, Threadable, Searchable { ); //ticket created on user's behalf - if (Ticket::checkReply('cc', $vars['emailreply'])) { - $email->send($ticket->getOwner(), $msg['subj'], $msg['body'], $attachments, - $options, $collabsCc); - } - elseif (Ticket::checkReply('user', $vars['emailreply'])) - $email->send($ticket->getOwner(), $msg['subj'], $msg['body'], $attachments, - $options); + $email->send($recipients, $msg['subj'], $msg['body'], $attachments, + $options); } return $ticket; } diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php index daaa18a38ec823c22ca406e3e9b00161caa25e50..8e4a8e8f8fc3cbee7480a8f5116ffc44e376ff8b 100644 --- a/include/staff/ticket-open.inc.php +++ b/include/staff/ticket-open.inc.php @@ -167,10 +167,10 @@ if ($_POST) <?php echo __('Ticket Notice');?>: </td> <td> - <select id="emailreply" name="emailreply"> - <option value="reply-all"><?php echo __('Alert All'); ?></option> - <option value="reply-user"><?php echo __('Alert to User'); ?></option> - <option value="0">— <?php echo __('Do Not Send Alert'); ?> —</option> + <select id="reply-to" name="reply-to"> + <option value="all"><?php echo __('Alert All'); ?></option> + <option value="user"><?php echo __('Alert to User'); ?></option> + <option value="none">— <?php echo __('Do Not Send Alert'); ?> —</option> </select> </td> </tr> diff --git a/scp/tickets.php b/scp/tickets.php index 1e1a085ab48afbf63f32af2db1329b4ba037fdf3..07d34243ffe3367aa0f0bde6db2b2707a49ceec6 100644 --- a/scp/tickets.php +++ b/scp/tickets.php @@ -172,8 +172,9 @@ if($_POST && !$errors): if(!$errors['err'] && Banlist::isBanned($ticket->getEmail())) $errors['err']=__('Email is in banlist. Must be removed to reply.'); } - - if(!$errors && ($response=$ticket->postReply($vars, $errors, $_POST['emailreply']))) { + $alert = strcasecmp('none', $_POST['reply-to']); + if(!$errors && ($response=$ticket->postReply($vars, $errors, + $alert))) { $msg = sprintf(__('%s: Reply posted successfully'), sprintf(__('Ticket #%s'), sprintf('<a href="tickets.php?id=%d"><b>%s</b></a>',