diff --git a/core/lib/Drupal/Core/Mail/MailFormatHelper.php b/core/lib/Drupal/Core/Mail/MailFormatHelper.php index c3fc206721f9d7105861466d15411614817c293b..05e4c190933aa2e06f4bb740648c8dc996fed676 100644 --- a/core/lib/Drupal/Core/Mail/MailFormatHelper.php +++ b/core/lib/Drupal/Core/Mail/MailFormatHelper.php @@ -311,7 +311,7 @@ protected static function wrapMailLine(&$line, $key, $values) { } if (!$line_is_mime_header) { // Use soft-breaks only for purely quoted or un-indented text. - $line = wordwrap($line, 77 - $values['length'], $values['soft'] ? " \n" : "\n"); + $line = wordwrap($line, 77 - $values['length'], $values['soft'] ? " \n" : "\n"); } // Break really long words at the maximum width allowed. $line = wordwrap($line, 996 - $values['length'], $values['soft'] ? " \n" : "\n", TRUE); diff --git a/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php b/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php index 809420759969714d7eead551514144ff8629e30a..a578a02463903dc949b5cf872d93904c29dc61df 100644 --- a/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php +++ b/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php @@ -64,10 +64,8 @@ public function format(array $message) { // Join the body array into one string. $message['body'] = implode("\n\n", $message['body']); - // Convert any HTML to plain-text. + // Convert any HTML to plain text (which also wraps the mail body). $message['body'] = MailFormatHelper::htmlToText($message['body']); - // Wrap the mail body for sending. - $message['body'] = MailFormatHelper::wrapMail($message['body']); return $message; } diff --git a/core/lib/Drupal/Core/Mail/Plugin/Mail/SymfonyMailer.php b/core/lib/Drupal/Core/Mail/Plugin/Mail/SymfonyMailer.php index c848a0a43108f7eb9f89686dcdb2cf10fdd9adc1..80b545465e42c6e1f6b12c1a32ded8eb222ca5fc 100644 --- a/core/lib/Drupal/Core/Mail/Plugin/Mail/SymfonyMailer.php +++ b/core/lib/Drupal/Core/Mail/Plugin/Mail/SymfonyMailer.php @@ -98,11 +98,14 @@ public function __construct( } public function format(array $message) { - // Convert any HTML to plain-text. foreach ($message['body'] as &$part) { + // If the message contains HTML, convert it to plain text (which also + // wraps the mail body). if ($part instanceof MarkupInterface) { $part = MailFormatHelper::htmlToText($part); } + // If the message does not contain HTML, it still needs to be wrapped + // properly. else { $part = MailFormatHelper::wrapMail($part); } diff --git a/core/tests/Drupal/Tests/Core/Mail/MailFormatHelperTest.php b/core/tests/Drupal/Tests/Core/Mail/MailFormatHelperTest.php index 4dc849147638035211561e350547169e05b8c7d5..2232be3394b02d8acb4306e98eea9ba81854e36e 100644 --- a/core/tests/Drupal/Tests/Core/Mail/MailFormatHelperTest.php +++ b/core/tests/Drupal/Tests/Core/Mail/MailFormatHelperTest.php @@ -32,8 +32,11 @@ public function testWrapMail(): void { // Check that the body headers were not wrapped even though some exceeded // 77 characters. $this->assertEquals($headers_in_body, $processed_headers, 'Headers in the body are not wrapped.'); - // Check that the body text is wrapped. - $this->assertEquals(wordwrap($body, 77, " \n"), $processed_body, 'Body text is wrapped.'); + // Check that the body text is soft-wrapped according to the + // "format=flowed; delsp=yes" encoding. When interpreting this encoding, + // mail readers will delete a space at the end of the line; therefore an + // extra trailing space should be present in the raw body (see RFC 3676). + $this->assertEquals(wordwrap($body, 77, " \n"), $processed_body, 'Body text is soft-wrapped.'); } }