diff --git a/include/class.filter_action.php b/include/class.filter_action.php index 531b997e3008354a0a1bc84f25d62121f1bdf50c..7de00efe9e82d79e974d3bd2411c60161920baf6 100644 --- a/include/class.filter_action.php +++ b/include/class.filter_action.php @@ -453,15 +453,42 @@ class FA_SendEmail extends TriggerAction { if (!$config['from'] || !($mailer = Email::lookup($config['from']))) $mailer = new Mailer(); - // Honor %{user} variable - $to = $config['recipients']; + // Allow %{user} in the To: line $replacer = new VariableReplacer(); $replacer->assign(array( - 'user' => sprintf('%s <%s>', $ticket['name'], $ticket['email']) + 'user' => sprintf('"%s" <%s>', $ticket['name'], $ticket['email']) )); - $to = $replacer->replaceVars($to); + $to = $replacer->replaceVars($config['recipients']); + + require_once PEAR_DIR . 'Mail/RFC822.php'; + require_once PEAR_DIR . 'PEAR.php'; + + if (!($mails = Mail_RFC822::parseAddressList($to)) || PEAR::isError($mails)) + return false; + + // Allow %{recipient} in the body + foreach ($mails as $R) { + $recipient = sprintf('%s <%s@%s>', $R->personal, $R->mailbox, $R->host); + $replacer->assign(array( + 'recipient' => new EmailAddress($recipient), + )); + $I = $replacer->replaceVars($info); + $mailer->send($recipient, $I['subject'], $I['message']); + } + + } - $mailer->send($to, $info['subject'], $info['message']); + static function getVarScope() { + $context = array( + 'ticket' => array( + 'class' => 'FA_SendEmail_TicketInfo', 'desc' => __('Ticket'), + ), + 'user' => __('Ticket Submitter'), + 'recipient' => array( + 'class' => 'EmailAddress', 'desc' => __('Recipient'), + ), + ) + osTicket::getVarScope(); + return VariableReplacer::compileScope($context); } function getConfigurationOptions() { @@ -504,6 +531,7 @@ class FA_SendEmail extends TriggerAction { 'configuration' => array( 'placeholder' => __('Message'), 'html' => true, + 'context' => 'fa:send_email', ), )), 'from' => new ChoiceField(array( @@ -515,3 +543,12 @@ class FA_SendEmail extends TriggerAction { } } FilterAction::register('FA_SendEmail', /* @trans */ 'Communication'); + +class FA_SendEmail_TicketInfo { + static function getVarScope() { + return array( + 'message' => __('Message from the EndUser'), + 'source' => __('Source'), + ); + } +} diff --git a/include/class.forms.php b/include/class.forms.php index 77744763a91a7852b4631fcb10f9dc725caafdad..796a8549e0432b5715f84c78de1549ddd0e71ded 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -2458,6 +2458,7 @@ class TextareaWidget extends Widget { function render($options=array()) { $config = $this->field->getConfiguration(); $class = $cols = $rows = $maxlength = ""; + $attrs = array(); if (isset($config['rows'])) $rows = "rows=\"{$config['rows']}\""; if (isset($config['cols'])) @@ -2470,9 +2471,12 @@ class TextareaWidget extends Widget { $class = sprintf('class="%s"', implode(' ', $class)); $this->value = Format::viewableImages($this->value); } + if (isset($config['context'])) + $attrs['data-root-context'] = '"'.$config['context'].'"'; ?> <span style="display:inline-block;width:100%"> <textarea <?php echo $rows." ".$cols." ".$maxlength." ".$class + .' '.Format::array_implode('=', ' ', $attrs) .' placeholder="'.$config['placeholder'].'"'; ?> id="<?php echo $this->id; ?>" name="<?php echo $this->name; ?>"><?php diff --git a/include/class.ticket.php b/include/class.ticket.php index d0a766aefebd7991b3645de4dcb21834edddbb34..cd314a300cde2620279a0337008ef46b9568b0f7 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -1876,6 +1876,7 @@ implements RestrictedAccess, Threadable, TemplateVariable { 'recipients' => array( 'class' => 'UserList', 'desc' => __('List of all recipient names'), ), + 'source' => __('Source'), 'status' => array( 'class' => 'TicketStatus', 'desc' => __('Status'), ), diff --git a/include/class.user.php b/include/class.user.php index f4b3c18eda09a321dc4b0edf81b98aa411a66175..960588dae4853e7a8f1952b7c4ac4d3885450104 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -693,7 +693,7 @@ implements TemplateVariable { case 'domain': return $info->host; case 'personal': - return $info->personal; + return trim($info->personal, '"'); case 'mailbox': return $info->mailbox; } diff --git a/include/class.variable.php b/include/class.variable.php index e47b74d742770df073538355a660ee39f7d50c2c..3b9e8ce2497492f34436400072c603f6aaa12725 100644 --- a/include/class.variable.php +++ b/include/class.variable.php @@ -232,6 +232,11 @@ class VariableReplacer { $roots = array('ticket'); break; + case 'fa:send_email': + // FIXME: Make this pluggable + require_once INCLUDE_DIR . 'class.filter_action.php'; + return FA_SendEmail::getVarScope(); + default: if ($info = Page::getContext($root)) { $roots = $info;