Merge pull request #67 from tompsonx/tompsonx-patch-1

Add reply to for email notification
This commit is contained in:
Ralf Becker 2019-03-14 09:39:15 +01:00 committed by GitHub
commit 4bf2c393fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 2 deletions

View File

@ -304,6 +304,7 @@ abstract class Tracking
* - 'subject' string subject line for the notification of $data,$old, defaults to link-title * - 'subject' string subject line for the notification of $data,$old, defaults to link-title
* - 'link' string of link to view $data * - 'link' string of link to view $data
* - 'sender' sender of email * - 'sender' sender of email
* - 'reply_to' reply to of email
* - 'skip_notify' array of email addresses that should _not_ be notified * - 'skip_notify' array of email addresses that should _not_ be notified
* - CUSTOM_NOTIFICATION string notification body message. Merge print placeholders are allowed. * - CUSTOM_NOTIFICATION string notification body message. Merge print placeholders are allowed.
* @param array $data current entry * @param array $data current entry
@ -787,6 +788,7 @@ abstract class Tracking
// get rest of notification message // get rest of notification message
$sender = $this->get_sender($data,$old,true,$receiver); $sender = $this->get_sender($data,$old,true,$receiver);
$reply_to = $this->get_reply_to($data,$old);
$subject = $this->get_subject($data,$old,$deleted,$receiver); $subject = $this->get_subject($data,$old,$deleted,$receiver);
$link = $this->get_notification_link($data,$old,$receiver); $link = $this->get_notification_link($data,$old,$receiver);
$attachments = $this->get_attachments($data,$old,$receiver); $attachments = $this->get_attachments($data,$old,$receiver);
@ -825,6 +827,7 @@ abstract class Tracking
$body_cache['html'] = "<span style='display:none;'>-----".lang('original message')."-----</span>"."\r\n".$body_cache['html']; $body_cache['html'] = "<span style='display:none;'>-----".lang('original message')."-----</span>"."\r\n".$body_cache['html'];
$notification->set_message($body_cache['html'], 'html'); $notification->set_message($body_cache['html'], 'html');
$notification->set_sender($sender); $notification->set_sender($sender);
$notification->set_reply_to($reply_to);
$notification->set_subject($subject); $notification->set_subject($subject);
$notification->set_links(array($link)); $notification->set_links(array($link));
$notification->set_popupdata($link['app'], $link); $notification->set_popupdata($link['app'], $link);
@ -915,6 +918,23 @@ abstract class Tracking
return $sender; return $sender;
} }
/**
* Get reply to address
*
* The default implementation prefers depending on what is returned by get_config('reply_to').
*
* @param int $user account_lid of user
* @param array $data
* @param array $old
* @return string or null
*/
protected function get_reply_to($data,$old)
{
$reply_to = $this->get_config('reply_to',$data,$old);
return $reply_to;
}
/** /**
* Get the title for a given entry, can be reimplemented * Get the title for a given entry, can be reimplemented
* *

View File

@ -112,6 +112,12 @@ class notifications {
*/ */
protected $sender; protected $sender;
/**
* email address for reply to
* @var string
*/
protected $reply_to;
/** /**
* holds notification subject * holds notification subject
* @var string * @var string
@ -229,6 +235,16 @@ class notifications {
return false; return false;
} }
/**
* Set reply_to for the current notification
*
* @param $_reply_to string for email address to reply to
*/
public function set_reply_to($_reply_to) {
$this->reply_to = $_reply_to;
return true;
}
/** /**
* Set receivers for the current notification * Set receivers for the current notification
* *
@ -550,6 +566,8 @@ class notifications {
if (!empty($this->popupsubject)) $lsubject = $this->popupsubject; if (!empty($this->popupsubject)) $lsubject = $this->popupsubject;
if ($this->popup_links) $llinks = $this->popup_links; if ($this->popup_links) $llinks = $this->popup_links;
if (is_array($this->popup_data)) $popup_data = $this->popup_data; if (is_array($this->popup_data)) $popup_data = $this->popup_data;
} elseif ($backend == 'email') {
if (!empty($this->reply_to)) $popup_data = array( 'reply_to' => $this->reply_to );
} }
$obj->send($this->prepend_message($messages, $prepend_message), $lsubject, $llinks, $this->attachments, $popup_data); $obj->send($this->prepend_message($messages, $prepend_message), $lsubject, $llinks, $this->attachments, $popup_data);

View File

@ -90,8 +90,6 @@ class notifications_email implements notifications_iface {
*/ */
public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false, $_data = false) public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false, $_data = false)
{ {
unset ($_data);
$body_plain = $_messages['plain'].$this->render_links($_links, false, $this->preferences->external_mailclient); $body_plain = $_messages['plain'].$this->render_links($_links, false, $this->preferences->external_mailclient);
$body_html = "<html><body>\n".$_messages['html'].$this->render_links($_links, true, $this->preferences->external_mailclient)."</body>\n</html>\n"; $body_html = "<html><body>\n".$_messages['html'].$this->render_links($_links, true, $this->preferences->external_mailclient)."</body>\n</html>\n";
@ -106,6 +104,10 @@ class notifications_email implements notifications_iface {
$this->mail->setFrom($this->sender->account_email, $this->sender->account_fullname); $this->mail->setFrom($this->sender->account_email, $this->sender->account_fullname);
if ( $_data && isset( $_data['reply_to'] ) ) {
$this->mail->addAddress($_data['reply_to'], '', 'replyto');
}
$this->mail->addHeader('Subject', trim($_subject)); // trim the subject to avoid strange wrong encoding problem $this->mail->addHeader('Subject', trim($_subject)); // trim the subject to avoid strange wrong encoding problem
if ($_messages['html']) if ($_messages['html'])
{ {