From c7b95df007d4ddaea4df76608883e142f67fce59 Mon Sep 17 00:00:00 2001 From: Kirill Roskolii Date: Fri, 16 Oct 2015 15:11:56 +1300 Subject: [PATCH] Issue #2300223 by Snir, jantoine, RoSk0: The "from" parameter is not configurable. --- message_notify.rules.inc | 16 ++++++++++++++-- .../email/MessageNotifierEmail.class.php | 3 ++- plugins/notifier/email/email.inc | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/message_notify.rules.inc b/message_notify.rules.inc index c14bc7a..eec3bf6 100644 --- a/message_notify.rules.inc +++ b/message_notify.rules.inc @@ -62,6 +62,14 @@ function message_notify_rules_action_info() { 'allow null' => TRUE, 'optional' => TRUE, ), + 'from' => array( + 'type' => 'text', + 'label' => t('The sender of the email'), + 'description' => t('The sender of the email. If left empty, the mail will be sent from the site-wide configured address.'), + 'default value' => FALSE, + 'allow null' => TRUE, + 'optional' => TRUE, + ), ), 'base' => 'message_notify_rules_process', ); @@ -72,7 +80,7 @@ function message_notify_rules_action_info() { /** * Action: Process and send Message. */ -function message_notify_rules_process(Message $message, $save_on_fail, $save_on_success, $rendered_subject_field, $rendered_body_field, $mail = FALSE) { +function message_notify_rules_process(Message $message, $save_on_fail, $save_on_success, $rendered_subject_field, $rendered_body_field, $mail = FALSE, $from = FALSE) { $options = array( 'save on fail' => $save_on_fail, 'save on success' => $save_on_success, @@ -86,7 +94,11 @@ function message_notify_rules_process(Message $message, $save_on_fail, $save_on_ } if ($mail) { - $options['mail'] = str_replace(array("\r", "\n"), '', $mail); + $options['mail'] = str_replace(array("\r", "\n"), '', $mail); + } + + if ($from) { + $options['from'] = $from; } message_notify_send_message($message, $options, 'email'); diff --git a/plugins/notifier/email/MessageNotifierEmail.class.php b/plugins/notifier/email/MessageNotifierEmail.class.php index b0e5da4..9a34983 100644 --- a/plugins/notifier/email/MessageNotifierEmail.class.php +++ b/plugins/notifier/email/MessageNotifierEmail.class.php @@ -13,6 +13,7 @@ public function deliver(array $output = array()) { $account = user_load($message->uid); $mail = $options['mail'] ? $options['mail'] : $account->mail; + $from = $options['from'] ? $options['from'] : NULL; $languages = language_list(); if (!$options['language override']) { @@ -28,7 +29,7 @@ public function deliver(array $output = array()) { // Pass the message entity along to hook_drupal_mail(). $output['message_entity'] = $message; - $result = drupal_mail('message_notify', $message->type, $mail, $lang, $output); + $result = drupal_mail('message_notify', $message->type, $mail, $lang, $output, $from); return $result['result']; } diff --git a/plugins/notifier/email/email.inc b/plugins/notifier/email/email.inc index f81d499..16445a2 100644 --- a/plugins/notifier/email/email.inc +++ b/plugins/notifier/email/email.inc @@ -7,6 +7,8 @@ $plugin = array( 'options' => array( // Override mail. Don't use the email that is assigned to the user. 'mail' => FALSE, + // Override from. Don't use the site-wide configured address. + 'from' => FALSE, ), // A notifier must define its own view modes. // Those view modes are later going to be rendered and sent.