From 3f7c5277235713fb8aa3f058c19ee3eac4e5b3ca Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Thu, 17 Sep 2015 10:27:13 +0000 Subject: [PATCH] Add option to use dept/agent name on replies Enable the ability to show the agent's full name or department's name on responses/replies in addition to the emails address name. Email address of the response would still be designated outgoing email address of the Department to which the ticket is assigned or the system default outgoing email address. * Agents can set the default FROM Name in Profile > Preference. * Private department's name won't be used regardless of the setting. * Agent's name won't be used if identity masking is enabled. --- include/class.mailer.php | 12 ++++++++---- include/class.staff.php | 5 +++++ include/class.ticket.php | 36 ++++++++++++++++++++++++++++------- include/staff/profile.inc.php | 28 ++++++++++++++++++++++++++- 4 files changed, 69 insertions(+), 12 deletions(-) diff --git a/include/class.mailer.php b/include/class.mailer.php index 3faae3266..1d3712211 100644 --- a/include/class.mailer.php +++ b/include/class.mailer.php @@ -66,10 +66,14 @@ class Mailer { $this->ht['from'] = $from; } - function getFromAddress() { + function getFromAddress($options=array()) { - if(!$this->ht['from'] && ($email=$this->getEmail())) - $this->ht['from'] =sprintf('"%s" <%s>', ($email->getName()?$email->getName():$email->getEmail()), $email->getEmail()); + if (!$this->ht['from'] && ($email=$this->getEmail())) { + if (($name = $options['from_name'] ?: $email->getName())) + $this->ht['from'] =sprintf('"%s" <%s>', $name, $email->getEmail()); + else + $this->ht['from'] =sprintf('<%s>', $email->getEmail()); + } return $this->ht['from']; } @@ -318,7 +322,7 @@ class Mailer { $subject = preg_replace("/(\r\n|\r|\n)/s",'', trim($subject)); $headers = array ( - 'From' => $this->getFromAddress(), + 'From' => $this->getFromAddress($options), 'To' => $to, 'Subject' => $subject, 'Date'=> date('D, d M Y H:i:s O'), diff --git a/include/class.staff.php b/include/class.staff.php index cbbc5200f..84fed0444 100644 --- a/include/class.staff.php +++ b/include/class.staff.php @@ -282,6 +282,10 @@ implements AuthenticatedUser, EmailContact, TemplateVariable { return $this->default_signature_type; } + function getReplyFromNameType() { + return $this->default_from_name; + } + function getDefaultPaperSize() { return $this->default_paper_size; } @@ -621,6 +625,7 @@ implements AuthenticatedUser, EmailContact, TemplateVariable { $this->max_page_size = $vars['max_page_size']; $this->auto_refresh_rate = $vars['auto_refresh_rate']; $this->default_signature_type = $vars['default_signature_type']; + $this->default_from_name = $vars['default_from_name']; $this->default_paper_size = $vars['default_paper_size']; $this->lang = $vars['lang']; $this->onvacation = isset($vars['onvacation'])?1:0; diff --git a/include/class.ticket.php b/include/class.ticket.php index c97ebbd2e..3d176f05f 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -1496,6 +1496,10 @@ implements RestrictedAccess, Threadable { $attachments = $cfg->emailAttachments()?$entry->getAttachments():array(); $options = array('thread' => $entry); + + if ($vars['from_name']) + $options += array('from_name' => $vars['from_name']); + foreach ($recipients as $recipient) { // Skip folks who have already been included on this part of // the conversation @@ -2494,15 +2498,33 @@ implements RestrictedAccess, Threadable { if (!$alert) return $response; - $options = array(); $email = $dept->getEmail(); - + $options = array('thread'=>$response); + $signature = $from_name = ''; if ($thisstaff && $vars['signature']=='mine') $signature=$thisstaff->getSignature(); elseif ($vars['signature']=='dept' && $dept->isPublic()) $signature=$dept->getSignature(); - else - $signature=''; + + if ($thisstaff && ($type=$thisstaff->getReplyFromNameType())) { + switch ($type) { + case 'mine': + if (!$cfg->hideStaffName()) + $from_name = (string) $thisstaff->getName(); + break; + case 'dept': + if ($dept->isPublic()) + $from_name = $dept->getName(); + break; + case 'email': + default: + $from_name = $email->getName(); + } + + if ($from_name) + $options += array('from_name' => $from_name); + + } $variables = array( 'response' => $response, @@ -2511,9 +2533,7 @@ implements RestrictedAccess, Threadable { 'poster' => $thisstaff ); - $user = $this->getOwner(); - $options = array('thread' => $response); if (($email=$dept->getEmail()) && ($tpl = $dept->getTemplate()) && ($msg=$tpl->getReplyMsgTemplate()) @@ -2528,7 +2548,9 @@ implements RestrictedAccess, Threadable { if ($vars['emailcollab']) { $this->notifyCollaborators($response, - array('signature' => $signature) + array( + 'signature' => $signature, + 'from_name' => $from_name) ); } return $response; diff --git a/include/staff/profile.inc.php b/include/staff/profile.inc.php index a41e31304..aacea1421 100644 --- a/include/staff/profile.inc.php +++ b/include/staff/profile.inc.php @@ -196,9 +196,35 @@ if ($avatar->isChangeable()) { ?> </select> </td> </tr> + + <tr> + <td><?php echo __('Default From Name');?>: + <div class="faded"><?php echo __('From name to use when replying to a thread');?></div> + </td> + <td> + <select name="default_from_name"> + <?php + $options=array( + 'email' => __("Email Address Name"), + 'dept' => sprintf(__("Department Name (%s)"), + __('if public' /* This is used in 'Department's Name (>if public<)' */)), + 'mine' => __('My Name')); + if ($cfg->hideStaffName()) + unset($options['mine']); + + foreach($options as $k=>$v) { + echo sprintf('<option value="%s" %s>%s</option>', + $k,($staff->default_from_name==$k)?'selected="selected"':'',$v); + } + ?> + </select> + <div class="error"><?php echo $errors['default_from_name']; ?></div> + </td> + </tr> + <tr> <td><?php echo __('Default Signature');?>: - <div class="faded"><?php echo __('This can be selected when replying to a ticket');?></div> + <div class="faded"><?php echo __('This can be selected when replying to a thread');?></div> </td> <td> <select name="default_signature_type"> -- GitLab