The line 566 wants to conform with the RFC 2822 in not allowing any lines being longer than 998 characters -- but fails.

There should be a TRUE as last paramter of wordwrap() for really breaking at 996 chars (see http://www.php.net/manual/en/function.wordwrap.php).

Therefore

// Break really long words at the maximum width allowed.
$line = wordwrap($line, 996 - $values['length'], $values['soft'] ? " \n" : "\n");

should become

// Break really long words at the maximum width allowed.
$line = wordwrap($line, 996 - $values['length'], $values['soft'] ? " \n" : "\n", TRUE);

Patch attached.

Cheers, Alex

CommentFileSizeAuthor
#15 1946090-15.patch1.67 KBAnonymous (not verified)
#10 1946090-10.patch1.74 KBAnonymous (not verified)
#10 1946090-10.test-fail.patch1.07 KBAnonymous (not verified)
#8 1946090-8.patch1.07 KBAnonymous (not verified)
#6 1946090-6.patch680 bytesrpayanm
d7-mail-wordwrap.patch602 bytesalex-mo

Comments

alex-mo’s picture

Version: 7.21 » 7.x-dev
torotil’s picture

Status: Active » Needs review
sun’s picture

Title: _drupal_wrap_mail_line() does not what it is supposed to do » _drupal_wrap_mail_line() does not force-wrap too long words after 996 characters
Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D6, +Needs tests, +Needs backport to D7

Looks good.

Can you add a simple test for this case?

Should still apply cleanly to D8, D7, and D6 (give or take a /core directory).

torotil’s picture

We already have DrupalHtmlToTextTestCase::testVeryLongLineWrap() which should cover this - but obviously hasn't.

jhedstrom’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll
rpayanm’s picture

Status: Needs work » Needs review
StatusFileSize
new680 bytes

Here for drupal 8 :)

pwieck’s picture

Issue tags: -Needs reroll
Anonymous’s picture

StatusFileSize
new1.07 KB

I corrected the test as suggested in #4, but it does not fail. If I check the output text in the test, it seems to be wrapped correctly.

Could someone provide a failing example text?

Status: Needs review » Needs work

The last submitted patch, 8: 1946090-8.patch, failed testing.

Anonymous’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.07 KB
new1.74 KB

This did not fail on my local installation, but did fail on the test bot. Could this be related to php version? My local version is php 5.4.34.

New patches are the combination of #6 and #8.

The last submitted patch, 10: 1946090-10.test-fail.patch, failed testing.

geertvd’s picture

Status: Needs review » Reviewed & tested by the community

This fails on my local installation. I think this is good to go.

alexpott’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 0ed1f2e and pushed to 8.0.x. Thanks!

diff --git a/core/modules/system/src/Tests/Mail/HtmlToTextTest.php b/core/modules/system/src/Tests/Mail/HtmlToTextTest.php
index a90fc7e..3bf7ffc 100644
--- a/core/modules/system/src/Tests/Mail/HtmlToTextTest.php
+++ b/core/modules/system/src/Tests/Mail/HtmlToTextTest.php
@@ -357,7 +357,7 @@ public function testVeryLongLineWrap() {
       $maximum_line_length = max($maximum_line_length, strlen($line . $eol));
     }
     $verbose = 'Maximum line length found was ' . $maximum_line_length . ' octets.';
-    $this->assert($maximum_line_length <= 1000, $verbose);
+    $this->assertTrue($maximum_line_length <= 1000, $verbose);
   }
 
   /**

Minor fix on commit.

  • alexpott committed 0ed1f2e on 8.0.x
    Issue #1946090 by pjonckiere, alex-mo, rpayanm: _drupal_wrap_mail_line...
Anonymous’s picture

Status: Patch (to be ported) » Needs review
Issue tags: -Needs backport to D7
StatusFileSize
new1.67 KB

Backport for D7.

  • alexpott committed 0ed1f2e on 8.1.x
    Issue #1946090 by pjonckiere, alex-mo, rpayanm: _drupal_wrap_mail_line...
izmeez’s picture

Status: Needs review » Reviewed & tested by the community

I don't think this has been committed to Drupal 7 based on the commit references in comments #14 and #16.

Changing status of patch for Drupal 7 to RTBC since the patch in #15 for D7 is the same as that committed to D8.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x - thanks!

This issue has the "needs backport to D6" tag, but I'm guessing that's not happening at this point. Feel free to reopen for Drupal 6 if you want to try :)

  • David_Rothstein committed dbef1ac on 7.x
    Issue #1946090 by pjonckiere, alex-mo, rpayanm: _drupal_wrap_mail_line...
maximpodorov’s picture

This is incorrect anyway, since wordwrap() can't deal with utf-8 (and mail bodies can be in utf-8!).
See https://www.drupal.org/node/364670 for more accurate solution.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.