Problem/Motivation

Drupal documents that email messages are formatted using format=flowed; delsp=yes encoding, and specifies this encoding in the Content-Type header for email messages. However, #2078917: E-mails contain double spaces in soft-wrapped sentences broke the format=flowed; delsp=yes encoding (I guess because folks didn't test on a client that interprets this encoding, and didn't fully understand how the encoding works).

In addition, the PhpMail class re-wraps email messages by calling MailFormatHelper::htmlToText() and then MailFormatHelper::wrapMail(). First of all, MailFormatHelper::htmlToText() calls MailFormatHelper::wrapMail() on each chunk internally, so this is not necessary.

More importantly, when called on an already-formatted body, MailFormatHelper::wrapMail() breaks the format=flowed; delsp=yes encoding because it converts soft breaks to hard breaks. So, this unnecessary call to MailFormatHelper::wrapMail() needs to be removed.

Steps to reproduce

To reproduce this issue, you will need to read email messages sent by Drupal using any email client that can properly interpret format=flowed; delsp=yes encoding, such as Mutt, Thunderbird, etc.

In these email readers, you will see that soft-wrapped lines have been converted to hard-wrap: Lines that were supposed to be soft-wrapped purely for purposes of sending short lines on the wire, and unwrapped/re-flowed by the email reader, will still be hard-wrapped in the displayed email message. We want these lines to appear "flowed," and only soft-wrapped by the email reader where needed to fit in the user's viewport. See the attached screenshots for what email messages look like in an email reader (e.g. Thunderbird) with and without the patch.

In addition, in any cases where MailFormatHelper::wrapMail() is called only once on the email body (e.g. the SymfonyMailer plugin), email readers supporting format=flowed; delsp=yes will be missing a space when they re-flow wrapped lines, which is also incorrect. A space is deleted when the encoding is interpreted, but no extra space was added during encoding, so you end up with words stuck together.

Proposed resolution

Undo the change from #2078917: E-mails contain double spaces in soft-wrapped sentences and port #1447236: DefaultMailSystem implements MailSystemInterface::format() incorrectly to Drupal 11.

Remaining tasks

User interface changes

Vastly improved display of email messages in email clients that interpret format=flowed; delsp=yes encoding. An extra space will be present in soft-wrapped lines if the email reader does not properly interpret this encoding.

Before

After

API changes

Email messages are already specified in the email headers and documented in the code as being format=flowed; delsp=yes so there is no API change here.

Data model changes

None

Release notes snippet

Issue fork drupal-3451611

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

mfb created an issue. See original summary.

mfb’s picture

Status: Active » Needs review
mfb’s picture

Issue summary: View changes
smustgrave’s picture

Status: Needs review » Needs work

Can we provide examples in the summary for how this is better?

Thanks

mfb’s picture

Issue summary: View changes
Status: Needs work » Needs review

@smustgrave I fleshed out part of the steps to reproduce a bit. If we need more, maybe you can clarify what you would like an example of.

smustgrave’s picture

Vastly improved display of email messages in email clients

can we get screenshots of the improvements

mfb’s picture

Issue summary: View changes
StatusFileSize
new34.22 KB
new31.15 KB

Ok I added some screenshots for the default out-of-the-box mailer, with and without the patch applied. (The other bug fixed by this patch is that the body is soft-wrapped but words are stuck together due to missing space; I didn't yet dig into how to reproduce it, but I suspect it could happen with a non-default mailer setup.)

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Thanks, examples seem good improvements.

quietone’s picture

I read the issue summary, comments and the MR. Just about everything here is in order. It would be better if the screenshots were available from the issue summary but there are only 8 comments so far, so they are not hard to find. There are no unanswered questions. The comments in the MR are clear and easy to understand.

Leaving at RTBC

xjm’s picture

Issue summary: View changes

Embedding the screenshots.

xjm’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

Made a change to the issue summary... originally it sounded like this needed to be postponed on reverting another issue, but the issue was committed in 2013, so what is actually proposed here is to undo the change from that issue and implement a different fix instead. The situation was further confused by the fact that a better fix was proposed for Drupal 7 but not for Drupal 8, violating the backport policy. :)

xjm’s picture

Issue summary: View changes

An important thing to understand for this issue (which I had to re-read the summary to get) is that MailFormatHelper::htmlToText() already calls MailFormatHelper::wrapMail(), so the second call in the PHP mailer was redundant.

xjm’s picture

NW for the above comments/suggestions I posted on the MR, which should get reviewed by @mfb, another previous issue contributor, or a relevant maintainer (i.e., credit will not be granted to someone doing a drive-by application of my suggestions). Thanks!

xjm’s picture

Issue summary: View changes
mfb’s picture

Status: Needs work » Needs review

Thanks @xjm, I further clarified the comments.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Feedback appears to be reviewed by @mfb mvoing back to RTBC.

  • longwave committed 5be98c43 on 10.3.x
    Issue #3451611 by mfb, xjm, smustgrave, quietone: Fix the format=flowed...
longwave’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Backported down to 10.3.x as a valid bug fix, although this is a very minor behaviour change it makes things better and I see no reason to keep it to major releases only.

Committed and pushed c29768f406 to 11.x and 1e5f032e26 to 11.0.x and bc8de78fe2 to 10.4.x and 5be98c43a8 to 10.3.x. Thanks!

  • longwave committed bc8de78f on 10.4.x
    Issue #3451611 by mfb, xjm, smustgrave, quietone: Fix the format=flowed...

  • longwave committed 1e5f032e on 11.0.x
    Issue #3451611 by mfb, xjm, smustgrave, quietone: Fix the format=flowed...

  • longwave committed c29768f4 on 11.x
    Issue #3451611 by mfb, xjm, smustgrave, quietone: Fix the format=flowed...
longwave’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Fixing issue status and credits after crossposting with the bot.

Status: Fixed » Closed (fixed)

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