phpBB

Code Changes

File: includes/functions_messenger.php

  Unmodified   Added   Modified   Removed
Line 24Line 24
*/
class messenger
{

*/
class messenger
{

	var $msg, $extra_headers, $replyto, $from, $subject;

	var $msg, $replyto, $from, $subject;

	var $addresses = array();

	var $addresses = array();

 
	var $extra_headers = array();


var $mail_priority = MAIL_NORMAL_PRIORITY;
var $use_queue = true;


var $mail_priority = MAIL_NORMAL_PRIORITY;
var $use_queue = true;

Line 36Line 37
	/**
* Constructor
*/

	/**
* Constructor
*/

	function messenger($use_queue = true)

	function __construct($use_queue = true)

	{
global $config;


	{
global $config;


Line 180Line 181
	/**
* Adds X-AntiAbuse headers
*

	/**
* Adds X-AntiAbuse headers
*

	* @param array $config		Configuration array
* @param user $user A user object
*
* @return null

	* @param \phpbb\config\config	$config		Config object
* @param \phpbb\user $user User object
* @return void


	*/
function anti_abuse_headers($config, $user)
{

	*/
function anti_abuse_headers($config, $user)
{

Line 325Line 325
		));

$subject = $this->subject;

		));

$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

		*
* @event core.modify_notification_message
* @var int method User notification method NOTIFY_EMAIL|NOTIFY_IM|NOTIFY_BOTH

Line 337Line 354
		* @var	string	message	The message text
* @since 3.1.11-RC1
*/

		* @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)));

		extract($phpbb_dispatcher->trigger_event('core.modify_notification_message', compact($vars)));

 


		$this->subject = $subject;
$this->msg = $message;

		$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);


// 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);

Line 366Line 376
		else
{
$this->subject = (($this->subject != '') ? $this->subject : $user->lang['NO_EMAIL_SUBJECT']);

		else
{
$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)

		}

if ($drop_header)

Line 516Line 532
	*/
function msg_email()
{

	*/
function msg_email()
{

		global $config;

		global $config, $phpbb_dispatcher;


if (empty($config['email_enable']))
{


if (empty($config['email_enable']))
{

Line 543Line 559

$contact_name = htmlspecialchars_decode($config['board_contact_name']);
$board_contact = (($contact_name !== '') ? '"' . mail_encode($contact_name) . '" ' : '') . '<' . $config['board_contact'] . '>';


$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))
{


if (empty($this->replyto))
{

Line 749Line 792
	/**
* constructor
*/

	/**
* constructor
*/

	function queue()

	function __construct()

	{
global $phpEx, $phpbb_root_path, $phpbb_filesystem, $phpbb_container;


	{
global $phpEx, $phpbb_root_path, $phpbb_filesystem, $phpbb_container;


Line 782Line 825
	*/
function process()
{

	*/
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();


$lock = new \phpbb\lock\flock($this->cache_file);
$lock->acquire();

Line 879Line 922
				switch ($object)
{
case 'email':

				switch ($object)
{
case 'email':

 
						$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)
{

						$err_msg = '';
$to = (!$to) ? 'undisclosed-recipients:;' : $to;


						$err_msg = '';
$to = (!$to) ? 'undisclosed-recipients:;' : $to;


Line 896Line 960
							$messenger = new messenger();
$messenger->error('EMAIL', $err_msg);
continue 2;

							$messenger = new messenger();
$messenger->error('EMAIL', $err_msg);
continue 2;

 
							}

						}
break;


						}
break;


Line 948Line 1013

try
{


try
{

					$this->filesystem->phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE);

					$this->filesystem->phpbb_chmod($this->cache_file, \phpbb\filesystem\filesystem_interface::CHMOD_READ | \phpbb\filesystem\filesystem_interface::CHMOD_WRITE);

				}
catch (\phpbb\filesystem\exception\filesystem_exception $e)
{

				}
catch (\phpbb\filesystem\exception\filesystem_exception $e)
{

Line 1002Line 1067

try
{


try
{

				$this->filesystem->phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE);

				$this->filesystem->phpbb_chmod($this->cache_file, \phpbb\filesystem\filesystem_interface::CHMOD_READ | \phpbb\filesystem\filesystem_interface::CHMOD_WRITE);

			}
catch (\phpbb\filesystem\exception\filesystem_exception $e)
{

			}
catch (\phpbb\filesystem\exception\filesystem_exception $e)
{

Line 1263Line 1328
	var $backtrace = false;
var $backtrace_log = array();


	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;

	{
// Always create a backtrace for admins to identify SMTP problems
$this->backtrace = true;

Line 1516Line 1581
	*/
protected function starttls()
{

	*/
protected function starttls()
{

 
		global $config;

// allow SMTPS (what was used by phpBB 3.0) if hostname is prefixed with tls:// or ssl://
if (strpos($config['smtp_host'], 'tls://') === 0 || strpos($config['smtp_host'], 'ssl://') === 0)
{
return true;
}


		if (!function_exists('stream_socket_enable_crypto'))
{
return false;

		if (!function_exists('stream_socket_enable_crypto'))
{
return false;

Line 1538Line 1611

if (socket_set_blocking($this->socket, 1))
{


if (socket_set_blocking($this->socket, 1))
{

			$result = stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);



			// https://secure.php.net/manual/en/function.stream-socket-enable-crypto.php#119122
$crypto = (phpbb_version_compare(PHP_VERSION, '5.6.7', '<')) ? STREAM_CRYPTO_METHOD_TLS_CLIENT : STREAM_CRYPTO_METHOD_SSLv23_CLIENT;
$result = stream_socket_enable_crypto($this->socket, true, $crypto);

			socket_set_blocking($this->socket, (int) $stream_meta['blocked']);
}


			socket_set_blocking($this->socket, (int) $stream_meta['blocked']);
}


Line 1824Line 1899
{
global $config, $phpbb_root_path, $phpEx;


{
global $config, $phpbb_root_path, $phpEx;


	// We use the EOL character for the OS here because the PHP mail function does not correctly transform line endings. On Windows SMTP is used (SMTP is \r\n), on UNIX a command is used...
// Reference: http://bugs.php.net/bug.php?id=15841








	// Convert Numeric Character References to UTF-8 chars (ie. Emojis)
$subject = utf8_decode_ncr($subject);
$msg = utf8_decode_ncr($msg);

/**
* We use the EOL character for the OS here because the PHP mail function does not correctly transform line endings.
* On Windows SMTP is used (SMTP is \r\n), on UNIX a command is used...
* Reference: http://bugs.php.net/bug.php?id=15841
*/

	$headers = implode($eol, $headers);

if (!class_exists('\phpbb\error_collector'))

	$headers = implode($eol, $headers);

if (!class_exists('\phpbb\error_collector'))

Line 1836Line 1918
	$collector = new \phpbb\error_collector;
$collector->install();


	$collector = new \phpbb\error_collector;
$collector->install();


	// On some PHP Versions mail() *may* fail if there are newlines within the subject.
// Newlines are used as a delimiter for lines in mail_encode() according to RFC 2045 section 6.8.
// Because PHP can't decide what is wanted we revert back to the non-RFC-compliant way of separating by one space (Use '' as parameter to mail_encode() results in SPACE used)




	/**
* On some PHP Versions mail() *may* fail if there are newlines within the subject.
* Newlines are used as a delimiter for lines in mail_encode() according to RFC 2045 section 6.8.
* Because PHP can't decide what is wanted we revert back to the non-RFC-compliant way of separating by one space
* (Use '' as parameter to mail_encode() results in SPACE used)
*/

	$additional_parameters = $config['email_force_sender'] ? '-f' . $config['board_email'] : '';

	$additional_parameters = $config['email_force_sender'] ? '-f' . $config['board_email'] : '';

 


	$result = mail($to, mail_encode($subject, ''), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $headers, $additional_parameters);

$collector->uninstall();

	$result = mail($to, mail_encode($subject, ''), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $headers, $additional_parameters);

$collector->uninstall();