Issue #3270647 by P44T, AndyF, Sander Edwards van Muijen, Nitin shrivastava, Albert Volkman, mr.baileys, jshimota01, catch, mpellegrin, poker10, alexpott: PhpMail : broken mail headers in PHP 8.0+ because of LF characters
(cherry picked from commit 915fe89875
)
merge-requests/4179/head
parent
10d3bb7abb
commit
ca62f55ef3
|
@ -109,10 +109,7 @@ class PhpMail implements MailInterface {
|
||||||
// line-ending format appropriate for your system. If you need to
|
// line-ending format appropriate for your system. If you need to
|
||||||
// override this, adjust $settings['mail_line_endings'] in settings.php.
|
// override this, adjust $settings['mail_line_endings'] in settings.php.
|
||||||
$mail_body = preg_replace('@\r?\n@', $line_endings, $message['body']);
|
$mail_body = preg_replace('@\r?\n@', $line_endings, $message['body']);
|
||||||
// For headers, PHP's API suggests that we use CRLF normally,
|
$mail_headers = $headers->toString();
|
||||||
// but some MTAs incorrectly replace LF with CRLF. See #234403.
|
|
||||||
$mail_headers = str_replace("\r\n", "\n", $headers->toString());
|
|
||||||
$mail_subject = str_replace("\r\n", "\n", $mail_subject);
|
|
||||||
|
|
||||||
if (!$this->request->server->has('WINDIR') && !str_contains($this->request->server->get('SERVER_SOFTWARE'), 'Win32')) {
|
if (!$this->request->server->has('WINDIR') && !str_contains($this->request->server->get('SERVER_SOFTWARE'), 'Win32')) {
|
||||||
// On most non-Windows systems, the "-f" option to the sendmail command
|
// On most non-Windows systems, the "-f" option to the sendmail command
|
||||||
|
|
|
@ -77,9 +77,6 @@ class PhpMailTest extends UnitTestCase {
|
||||||
->onlyMethods(['doMail'])
|
->onlyMethods(['doMail'])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$mailer->expects($this->once())->method('doMail')
|
|
||||||
->willReturn(TRUE);
|
|
||||||
|
|
||||||
$request = $this->getMockBuilder(Request::class)
|
$request = $this->getMockBuilder(Request::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
@ -95,7 +92,6 @@ class PhpMailTest extends UnitTestCase {
|
||||||
$reflection_property = $reflection->getProperty('request');
|
$reflection_property = $reflection->getProperty('request');
|
||||||
$reflection_property->setAccessible(TRUE);
|
$reflection_property->setAccessible(TRUE);
|
||||||
$reflection_property->setValue($mailer, $request);
|
$reflection_property->setValue($mailer, $request);
|
||||||
|
|
||||||
return $mailer;
|
return $mailer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,20 +112,43 @@ class PhpMailTest extends UnitTestCase {
|
||||||
'langcode' => 'en',
|
'langcode' => 'en',
|
||||||
'params' => [],
|
'params' => [],
|
||||||
'send' => TRUE,
|
'send' => TRUE,
|
||||||
'subject' => '',
|
'subject' => "test\r\nsubject",
|
||||||
'body' => '',
|
'body' => '',
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'MIME-Version' => '1.0',
|
'MIME-Version' => '1.0',
|
||||||
'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
|
'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
|
||||||
'Content-Transfer-Encoding' => '8Bit',
|
'Content-Transfer-Encoding' => '8Bit',
|
||||||
'X-Mailer' => 'Drupal',
|
'X-Mailer' => 'Drupal',
|
||||||
'Return-Path' => 'from@example.org',
|
|
||||||
'From' => '"Foo, Bar, and Baz" <from@example.org>',
|
'From' => '"Foo, Bar, and Baz" <from@example.org>',
|
||||||
'Reply-to' => 'from@example.org',
|
'Reply-to' => 'from@example.org',
|
||||||
|
'Return-Path' => 'from@example.org',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$mailer = $this->createPhpMailInstance();
|
$mailer = $this->createPhpMailInstance();
|
||||||
|
|
||||||
|
// Verify we use line endings consistent with the PHP mail() function, which
|
||||||
|
// changed with PHP 8. See:
|
||||||
|
// - https://www.drupal.org/node/3270647
|
||||||
|
// - https://bugs.php.net/bug.php?id=81158
|
||||||
|
$line_end = "\r\n";
|
||||||
|
|
||||||
|
$expected_headers = "MIME-Version: 1.0$line_end";
|
||||||
|
$expected_headers .= "Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes$line_end";
|
||||||
|
$expected_headers .= "Content-Transfer-Encoding: 8Bit$line_end";
|
||||||
|
$expected_headers .= "X-Mailer: Drupal$line_end";
|
||||||
|
$expected_headers .= "From: \"Foo, Bar, and Baz\" <from@example.org>$line_end";
|
||||||
|
$expected_headers .= "Reply-to: from@example.org$line_end";
|
||||||
|
|
||||||
|
$mailer->expects($this->once())->method('doMail')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('to@example.org'),
|
||||||
|
$this->equalTo("=?utf-8?Q?test?={$line_end} =?utf-8?Q?subject?="),
|
||||||
|
$this->equalTo(''),
|
||||||
|
$this->stringStartsWith($expected_headers),
|
||||||
|
)
|
||||||
|
->willReturn(TRUE);
|
||||||
|
|
||||||
$this->assertTrue($mailer->mail($message));
|
$this->assertTrue($mailer->mail($message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue