From 5b25b3e2d59558c7a933195fb404597a64a85cbd Mon Sep 17 00:00:00 2001
From: Oliver Schramm <oliver.schramm97@gmail.com>
Date: Fri, 5 Oct 2018 21:45:56 +0200
Subject: [PATCH 1/2] [ticket/15830] Move event to a more useful place

PHPBB3-15830
---
 phpBB/includes/functions_messenger.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php
index 75c15657b0..b5c8baada6 100644
--- a/phpBB/includes/functions_messenger.php
+++ b/phpBB/includes/functions_messenger.php
@@ -325,6 +325,9 @@ class messenger
 			'SITENAME'	=> htmlspecialchars_decode($config['sitename']),
 		));
 
+		// Parse message through template
+		$this->msg = trim($this->template->assign_display('body'));
+
 		$subject = $this->subject;
 		$message = $this->msg;
 		$template  = $this->template;
@@ -353,9 +356,6 @@ class messenger
 		$this->msg = $message;
 		unset($subject, $message);
 
-		// Parse message through template
-		$this->msg = trim($this->template->assign_display('body'));
-
 		// 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);
 

From 2d736479d8f7040d9fbbb12fb7961e329f62bac2 Mon Sep 17 00:00:00 2001
From: Oliver Schramm <oliver.schramm97@gmail.com>
Date: Mon, 22 Oct 2018 15:17:18 +0200
Subject: [PATCH 2/2] [ticket/15830] Add event to modify template

PHPBB3-15830
---
 phpBB/includes/functions_messenger.php | 38 +++++++++++++++-----------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php
index b5c8baada6..40654b7988 100644
--- a/phpBB/includes/functions_messenger.php
+++ b/phpBB/includes/functions_messenger.php
@@ -325,14 +325,27 @@ class messenger
 			'SITENAME'	=> htmlspecialchars_decode($config['sitename']),
 		));
 
-		// Parse message through template
-		$this->msg = trim($this->template->assign_display('body'));
-
 		$subject = $this->subject;
-		$message = $this->msg;
-		$template  = $this->template;
+		$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
@@ -340,21 +353,14 @@ class messenger
 		*						and the message without sending it
 		* @var	string	subject	The message subject
 		* @var	string	message	The message text
-		* @var	\phpbb\template\template	template	Template object
 		* @since 3.1.11-RC1
-		* @changed 3.2.4-RC1 Added template
 		*/
-		$vars = array(
-			'method',
-			'break',
-			'subject',
-			'message',
-			'template',
-		);
+		$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);
+		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);