From 874cef6a19fb9fd9f12c11d2477170baa4a7eea2 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 19 Sep 2020 20:14:55 +0200 Subject: [PATCH 1/2] Transform email header string to header array & replace it at various situations. --- phpmailer/phpmailer.php | 9 ++++++--- securemail/SecureTestEmail.php | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/phpmailer/phpmailer.php b/phpmailer/phpmailer.php index e9a3c66ea..2b38f07a6 100644 --- a/phpmailer/phpmailer.php +++ b/phpmailer/phpmailer.php @@ -90,9 +90,12 @@ function phpmailer_emailer_send_prepare(App $a, IEmail &$email) // additional headers if (!empty($email->getAdditionalMailHeader())) { - foreach (explode("\n", trim($email->getAdditionalMailHeader())) as $header_line) { - list($name, $value) = explode(':', $header_line, 2); - $mailer->addCustomHeader(trim($name), trim($value)); + foreach ($email->getAdditionalMailHeader() as $name => $values) { + // Skip the "Message-ID" header because PHP-Mailer is using its own + if ($name == 'Message-Id') { + continue; + } + $mailer->addCustomHeader(trim($name), trim(implode("\n", $values))); } } diff --git a/securemail/SecureTestEmail.php b/securemail/SecureTestEmail.php index e15ef601f..8341f5451 100644 --- a/securemail/SecureTestEmail.php +++ b/securemail/SecureTestEmail.php @@ -54,6 +54,6 @@ class SecureTestEmail extends Email parent::__construct($sitename, $sender_email, $sender_email, $a->user['email'], $subject, "

{$message}

", $message, - '', local_user()); + [], local_user()); } } From 5663e61791e996cbfbadff116481f6e20e0639cb Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 19 Sep 2020 22:49:44 +0200 Subject: [PATCH 2/2] Add improvements --- phpmailer/phpmailer.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/phpmailer/phpmailer.php b/phpmailer/phpmailer.php index 2b38f07a6..5b43c8f19 100644 --- a/phpmailer/phpmailer.php +++ b/phpmailer/phpmailer.php @@ -91,11 +91,13 @@ function phpmailer_emailer_send_prepare(App $a, IEmail &$email) // additional headers if (!empty($email->getAdditionalMailHeader())) { foreach ($email->getAdditionalMailHeader() as $name => $values) { - // Skip the "Message-ID" header because PHP-Mailer is using its own + // Set the "Message-ID" header for PHP-Mailer directly if ($name == 'Message-Id') { - continue; + // implode all values to one entry, because there's only one value possible + $mailer->MessageID = trim(implode("", $values)); + } else { + $mailer->addCustomHeader(trim($name), trim(implode("\n", $values))); } - $mailer->addCustomHeader(trim($name), trim(implode("\n", $values))); } }