Empty e-mail's body when using pear/mail_mime-decode on Linux

Created on 11 May 2023, over 1 year ago
Updated 12 May 2023, over 1 year ago

Problem/Motivation

Using Mail_mimeDecode is broken on Linux resulting in empty e-mails (message.body in template is NULL).
Basically PHP docs for mail() and RFCs recommend to use a CRLF (\r\n) as separator for each line. This is what mimeDecode.php is doing in _splitBodyHeader() by attempting to split headers from body using \r\n\r\n which fails to split a header and body produced by htmlmail and as result this cause internal error: 'Could not split header and body' (in mimeDecode) which sets body to NULL.
By default htmlmail is splitting header and body by $eol$eol which is system dependent (PHP_EOL).

Steps to reproduce

Setup:
- composer.json: drupal/htmlmail:^3.0@alpha
- composer.json: pear/mail_mime-decode:1.5.5.2
- Applied patches: https://www.drupal.org/files/issues/2022-11-23/htmlmail-3005217-18-allow... β†’ & https://www.drupal.org/files/issues/2023-05-10/htmlmail-HtmlMailMime-317... β†’
- Formatter: HTML Mail, Sender: SMTP

- E-mail send tested from /admin/config/system/htmlmail/test

Proposed resolution

Solution would be to change header and body separator to "\r\n\r\n" by default.

Workaround: Add $config['mail_line_endings'] = "\r\n\r\n"; to your settings file.

See also: https://git.drupalcode.org/search?search=mail_line_endings&nav_source=na...

πŸ› Bug report
Status

Postponed: needs info

Version

3.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom kenorb

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kenorb
  • πŸ‡¬πŸ‡§United Kingdom kenorb
  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    Is there a reason you can't use the Mime Mail module instead? See 🌱 The future of the HTML Mail module Needs review

    The issue of email line separators has been a problem forever - ever since PHP added mail() functionality. PHP does the wrong thing, then Drupal core does the wrong thing trying to compensate for PHP, so mail module like HTML Mail had to do the wrong thing to work with the Drupal core hack that *required* \n\n even though the RFC says \r\n.

    This has been possibly fixed in PHP 8.0, but we still need to fix Drupal core. That issue is πŸ› PhpMail : broken mail headers in PHP 8.0+ because of LF characters Fixed . Bottom line, this is not a new issue, everyone who maintains a mail-related module is aware of this, and it is also something that has no definitive fix because in some cases mail transfer agents (which are independent of PHP and Drupal) also do the wrong thing with respect to line termination characters. I have always argued that Drupal should stick with the RFC and if that causes problems with the MTA then the MTA should be fixed or a different MTA should be used - it shouldn't be the case that Drupal has to add hacks to avoid issues with MTAs.

    I have put a lot of effort into Mime Mail over the past few years to make it comply with the RFC. HTML Mail on the other hand in my opinion is a lost cause because it relies on an old, outdated, and not supported PEAR package. There is no active maintainer for HTML Mail, unlike Mime Mail, and it would take quite a bit of effort to bring HTML Mail up to standards - effort which I see as wasted because at this point in time there is no need to have multiple contributed modules to do the same thing.

    I am inclined to mark this issue as "won't fix" in light of what I wrote in 🌱 The future of the HTML Mail module Needs review . Please discuss any concerns you have about the transition from HTML Mail to Mime Mail in that issue.

Production build 0.71.5 2024