diff options
Diffstat (limited to 'phpBB/includes/functions_messenger.php')
-rw-r--r-- | phpBB/includes/functions_messenger.php | 129 |
1 files changed, 97 insertions, 32 deletions
diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index a85a3b67c5..4f0d40031d 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -37,7 +37,7 @@ class messenger /** * Constructor */ - function messenger($use_queue = true) + function __construct($use_queue = true) { global $config; @@ -326,9 +326,26 @@ class messenger )); $subject = $this->subject; - $message = $this->msg; + $template = $this->template; /** - * Event to modify notification message text before parsing + * Event to modify the template before parsing + * + * @event core.modify_notification_template + * @var int method User notification method NOTIFY_EMAIL|NOTIFY_IM|NOTIFY_BOTH + * @var bool break Flag indicating if the function only formats the subject + * and the message without sending it + * @var string subject The message subject + * @var \phpbb\template\template template The (readonly) template object + * @since 3.2.4-RC1 + */ + $vars = array('method', 'break', 'subject', 'template'); + extract($phpbb_dispatcher->trigger_event('core.modify_notification_template', compact($vars))); + + // Parse message through template + $message = trim($this->template->assign_display('body')); + + /** + * Event to modify notification message text after parsing * * @event core.modify_notification_message * @var int method User notification method NOTIFY_EMAIL|NOTIFY_IM|NOTIFY_BOTH @@ -338,19 +355,12 @@ class messenger * @var string message The message text * @since 3.1.11-RC1 */ - $vars = array( - 'method', - 'break', - 'subject', - 'message', - ); + $vars = array('method', 'break', 'subject', 'message'); extract($phpbb_dispatcher->trigger_event('core.modify_notification_message', compact($vars))); + $this->subject = $subject; $this->msg = $message; - unset($subject, $message); - - // Parse message through template - $this->msg = trim($this->template->assign_display('body')); + unset($subject, $message, $template); // Because we use \n for newlines in the body message we need to fix line encoding errors for those admins who uploaded email template files in the wrong encoding $this->msg = str_replace("\r\n", "\n", $this->msg); @@ -369,6 +379,12 @@ class messenger $this->subject = (($this->subject != '') ? $this->subject : $user->lang['NO_EMAIL_SUBJECT']); } + if (preg_match('#^(List-Unsubscribe:(.*?))$#m', $this->msg, $match)) + { + $this->extra_headers[] = $match[1]; + $drop_header .= '[\r\n]*?' . preg_quote($match[1], '#'); + } + if ($drop_header) { $this->msg = trim(preg_replace('#' . $drop_header . '#s', '', $this->msg)); @@ -517,7 +533,7 @@ class messenger */ function msg_email() { - global $config; + global $config, $phpbb_dispatcher; if (empty($config['email_enable'])) { @@ -545,6 +561,33 @@ class messenger $contact_name = htmlspecialchars_decode($config['board_contact_name']); $board_contact = (($contact_name !== '') ? '"' . mail_encode($contact_name) . '" ' : '') . '<' . $config['board_contact'] . '>'; + $break = false; + $addresses = $this->addresses; + $subject = $this->subject; + $msg = $this->msg; + /** + * Event to send message via external transport + * + * @event core.notification_message_email + * @var bool break Flag indicating if the function return after hook + * @var array addresses The message recipients + * @var string subject The message subject + * @var string msg The message text + * @since 3.2.4-RC1 + */ + $vars = array( + 'break', + 'addresses', + 'subject', + 'msg', + ); + extract($phpbb_dispatcher->trigger_event('core.notification_message_email', compact($vars))); + + if ($break) + { + return true; + } + if (empty($this->replyto)) { $this->replyto = $board_contact; @@ -750,7 +793,7 @@ class queue /** * constructor */ - function queue() + function __construct() { global $phpEx, $phpbb_root_path, $phpbb_filesystem, $phpbb_container; @@ -783,7 +826,7 @@ class queue */ function process() { - global $config, $phpEx, $phpbb_root_path, $user; + global $config, $phpEx, $phpbb_root_path, $user, $phpbb_dispatcher; $lock = new \phpbb\lock\flock($this->cache_file); $lock->acquire(); @@ -880,23 +923,45 @@ class queue switch ($object) { case 'email': - $err_msg = ''; - $to = (!$to) ? 'undisclosed-recipients:;' : $to; - - if ($config['smtp_delivery']) + $break = false; + /** + * Event to send message via external transport + * + * @event core.notification_message_process + * @var bool break Flag indicating if the function return after hook + * @var array addresses The message recipients + * @var string subject The message subject + * @var string msg The message text + * @since 3.2.4-RC1 + */ + $vars = array( + 'break', + 'addresses', + 'subject', + 'msg', + ); + extract($phpbb_dispatcher->trigger_event('core.notification_message_process', compact($vars))); + + if (!$break) { - $result = smtpmail($addresses, mail_encode($subject), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $err_msg, $headers); - } - else - { - $result = phpbb_mail($to, $subject, $msg, $headers, PHP_EOL, $err_msg); - } + $err_msg = ''; + $to = (!$to) ? 'undisclosed-recipients:;' : $to; - if (!$result) - { - $messenger = new messenger(); - $messenger->error('EMAIL', $err_msg); - continue 2; + if ($config['smtp_delivery']) + { + $result = smtpmail($addresses, mail_encode($subject), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $err_msg, $headers); + } + else + { + $result = phpbb_mail($to, $subject, $msg, $headers, PHP_EOL, $err_msg); + } + + if (!$result) + { + $messenger = new messenger(); + $messenger->error('EMAIL', $err_msg); + continue 2; + } } break; @@ -1264,7 +1329,7 @@ class smtp_class var $backtrace = false; var $backtrace_log = array(); - function smtp_class() + function __construct() { // Always create a backtrace for admins to identify SMTP problems $this->backtrace = true; |