The current implementation is:

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.
  $message['body'] = drupal_html_to_text($message['body']);
  // Wrap the mail body for sending.
  $message['body'] = drupal_wrap_mail($message['body']);
  return $message;
}

However, according to the description of drupal_html_to_text(), the call to drupal_wrap_mail() is unnecessary and should be removed since it converts all soft breaks into hard breaks, making format=flowed meaningless.

Issue fork drupal-1447236

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

C. Lee’s picture

Version: 7.12 » 8.x-dev
StatusFileSize
new559 bytes

Here is the patch for 8.x

C. Lee’s picture

Status: Active » Needs review
C. Lee’s picture

StatusFileSize
new547 bytes

Patch for 7.x

Status: Needs review » Needs work

The last submitted patch, fix-mail-wrapping-1447236-3.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mfb’s picture

Version: 8.6.x-dev » 7.x-dev
Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new1.35 KB

Here's an updated patch for this issue, as well as a later-introduced bug which broke the format=flowed delsp email formatting.

mfb’s picture

Would love if someone wants to review this - could be part of a future bugfix release for Drupal 7? :)

avpaderno’s picture

Status: Needs review » Needs work
-    // Convert any HTML to plain-text.
+    // Convert any HTML to plain-text and wrap the mail body for sending.
     $message['body'] = drupal_html_to_text($message['body']);
-    // Wrap the mail body for sending.
-    $message['body'] = drupal_wrap_mail($message['body']);
     return $message;

Since the call to drupal_wrap_mail() is removed, the comment cannot says and wrap the mail body for sending, as that is done by drupal_wrap_mail().

-  $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);

The changed line uses " \n" (two spaces and a new line) instead of " \n" (a space and a new line), but the other call to wordwrap() uses " \n" (a space and a new line). I am not sure this is a typo or a inconsistent change.

mfb’s picture

Status: Needs work » Needs review

Since the call to drupal_wrap_mail() is removed, the comment cannot says and wrap the mail body for sending, as that is done by drupal_wrap_mail().

drupal_html_to_text() wraps the mail for sending. As the function documentation states: "The output will be suitable for use as 'format=flowed; delsp=yes' text (RFC 3676) and can be passed directly to drupal_mail() for sending." Within drupal_html_to_text(), drupal_wrap_mail() will be called on each chunk.

The changed line uses " \n" (two spaces and a new line) instead of " \n" (a space and a new line), but the other call to wordwrap() uses " \n" (a space and a new line). I am not sure this is a typo or a inconsistent change.

The trailing space will be deleted when format=flowed "delsp" email is formatted for display. When wrapping at a space, you want to preserve the space, so you end up with two spaces at the end of the line. For extremely long words, there should be no space when the word is reassembled for display, so you have just one space at the end of the line.

With this change, I am simply reverting 273c78ded2005cac80e2fa965f9131a85be16f0b, so this code goes back to it's original logic in #154218: Add HTML to text convertor for email (and wrap mails properly) (mostly, there was apparently an additional bug fix in there meanwhile)

If this seems too unclear, I could add additional verbiage to the code comments?

avpaderno’s picture

Status: Needs review » Reviewed & tested by the community

I apologize: That comment is correct because drupal_html_to_text() calls drupal_wrap_mail(). This issue should be sufficient to document that calling drupal_wrap_mail() after drupal_html_to_text() is not necessary.

With what explained in comment #14, I think this issue is R&TBC.

poker10’s picture

Status: Reviewed & tested by the community » Needs review

Thanks for working on this. I reviewed the patch and compared it with the D10. I am curious, if there is an issue for this for D10? Because it seems like the code in D10 is the same as the D7 code:

https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...

https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...

Do we need to change this in D10 first?

Thanks!

mfb’s picture

avpaderno’s picture

I created a merge request from the last patch, since patches are no longer tested.

mfb’s picture

Status: Needs review » Reviewed & tested by the community

This was now fixed in drupal 11 and 10, and merge request is the same as my patch at #11, so setting back to RTBC

poker10’s picture

Issue tags: +Pending Drupal 7 commit

Thanks! I compared the D10/11 committed code and this MR and the changes looks the same, see: https://git.drupalcode.org/project/drupal/-/commit/c29768f4068611be2c81a... (from #3451611: Fix the format=flowed; delsp=yes encoding of email messages). So I think this looks good.

The tests are green: https://git.drupalcode.org/issue/drupal-1447236/-/pipelines/228167

Tagging for a final review.

  • mcdruid committed 5e42a643 on 7.x
    Issue #1447236 by C. Lee, avpaderno, mfb, poker10: DefaultMailSystem...
mcdruid’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Pending Drupal 7 commit

Thanks!

mfb’s picture

🥳

Status: Fixed » Closed (fixed)

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