Skip to content
Snippets Groups Projects
Commit c83e16c6 authored by catch's avatar catch
Browse files

Issue #3270647 by P44T, AndyF, Sander Edwards van Muijen, Nitin shrivastava,...

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 915fe898)
parent c9053e9d
Branches
Tags
27 merge requests!11628Update file MediaLibraryWidget.php,!7564Revert "Issue #3364773 by roshnichordiya, Chris Matthews, thakurnishant_06,...,!5752Issue #3275828 by joachim, quietone, bradjones1, Berdir: document the reason...,!5627Issue #3261805: Field not saved when change of 0 on string start,!5427Issue #3338518: send credentials in ajax if configured in CORS settings.,!5395Issue #3387916 by fjgarlin, Spokje: Each GitLab job exposes user email,!5217Issue #3386607 by alexpott: Improve spell checking in commit-code-check.sh,!5064Issue #3379522 by finnsky, Gauravvvv, kostyashupenko, smustgrave, Chi: Revert...,!5040SDC ComponentElement: Transform slots scalar values to #plain_text instead of throwing an exception,!4958Issue #3392147: Whitelist IP for a Ban module.,!4942Issue #3365945: Errors: The following table(s) do not have a primary key: forum_index,!4894Issue #3280279: Add API to allow sites to opt in to upload SVG images in CKEditor 5,!4857Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!4856Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!4788Issue #3272985: RSS Feed header reverts to text/html when cached,!4716Issue #3362929: Improve 400 responses for broken/invalid image style routes,!4553Draft: Issue #2980951: Permission to see own unpublished comments in comment thread,!4273Add UUID to sections,!4192Issue #3367204: [CKEditor5] Missing dependency on drupal.ajax,!3679Issue #115801: Allow password on registration without disabling e-mail verification,!3106Issue #3017548: "Filtered HTML" text format does not support manual teaser break (<!--break-->),!3066Issue #3325175: Deprecate calling \Drupal\menu_link_content\Form\MenuLinkContentForm::_construct() with the $language_manager argument,!3004Issue #2463967: Use .user.ini file for PHP settings,!2851Issue #2264739: Allow multiple field widgets to not use tabledrag,!1484Exposed filters get values from URL when Ajax is on,!925Issue #2339235: Remove taxonomy hard dependency on node module,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links
......@@ -109,10 +109,7 @@ public function mail(array $message) {
// line-ending format appropriate for your system. If you need to
// override this, adjust $settings['mail_line_endings'] in settings.php.
$mail_body = preg_replace('@\r?\n@', $line_endings, $message['body']);
// For headers, PHP's API suggests that we use CRLF normally,
// 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);
$mail_headers = $headers->toString();
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
......
......@@ -77,9 +77,6 @@ protected function createPhpMailInstance(): PhpMail {
->onlyMethods(['doMail'])
->getMock();
$mailer->expects($this->once())->method('doMail')
->willReturn(TRUE);
$request = $this->getMockBuilder(Request::class)
->disableOriginalConstructor()
->getMock();
......@@ -95,7 +92,6 @@ protected function createPhpMailInstance(): PhpMail {
$reflection_property = $reflection->getProperty('request');
$reflection_property->setAccessible(TRUE);
$reflection_property->setValue($mailer, $request);
return $mailer;
}
......@@ -116,20 +112,43 @@ public function testMail() {
'langcode' => 'en',
'params' => [],
'send' => TRUE,
'subject' => '',
'subject' => "test\r\nsubject",
'body' => '',
'headers' => [
'MIME-Version' => '1.0',
'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
'Content-Transfer-Encoding' => '8Bit',
'X-Mailer' => 'Drupal',
'Return-Path' => 'from@example.org',
'From' => '"Foo, Bar, and Baz" <from@example.org>',
'Reply-to' => 'from@example.org',
'Return-Path' => 'from@example.org',
],
];
$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));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment