Hi together

I am facing an issue, when trying to send HTML mail using the mimemail module.
The problem i have is, that the Return-Path header is not set correctly in the outgoing Mail. that leads to problems with many mail providers.

I tracked the problem down to the function MimeMailFormatHelper::mimeMailHeaders where this function wraps the return-Path into <> brackets. This leads to a problem in PhpMail::mail() where $site_mail === $message['Return-Path'] is false then, since $message['Return-Path'] is wrapped. Also the wrapped address is not shellsafe, which results in sendmail using the default address, which is not correct in my case.

i will create a patch for that.

CommentFileSizeAuthor
#2 3018562-return-path-fix-2.patch639 bytesmegadesk3000

Comments

megadesk3000 created an issue. See original summary.

megadesk3000’s picture

StatusFileSize
new639 bytes
imclean’s picture

This is the correct format for the "Return-Path" header. See https://tools.ietf.org/html/rfc2822#section-3.6.7 :

The "Return-Path:" header field contains a pair of angle brackets that enclose an optional addr-spec.

That said, it's not really correct for Drupal to set the "Return-Path" header at all. The envelope sender is used by the delivering mail server to set "Return-Path". See: https://tools.ietf.org/html/rfc2821#section-4.4

However, this is how Drupal works at the moment so probably the subject of another discussion.

matthijs’s picture

mpp’s picture

Based on the RFC it would seem that mimemail handles this correctly.

This is a core bug in Drupal\Core\Mail\Plugin\Mail::mail the return path is set but it doesn't handle the path in an RFC compliant way (it doesn't take into account the angle brackets):

    // If 'Return-Path' isn't already set in php.ini, we pass it separately
    // as an additional parameter instead of in the header.
    if (isset($message['headers']['Return-Path'])) {
      $return_path_set = strpos(ini_get('sendmail_path'), ' -f');
      if (!$return_path_set) {
        $message['Return-Path'] = $message['headers']['Return-Path'];
        unset($message['headers']['Return-Path']);
      }
    }

    ...

      $additional_headers = isset($message['Return-Path']) && ($site_mail === $message['Return-Path'] || static::_isShellSafe($message['Return-Path'])) ? '-f' . $message['Return-Path'] : '';

The reason the patch in #2 works is:
- mimemail with 3018562#2 removes the angle brackets
- core mail compares the email addresses and they match

In fact core should compare the addresses in a compliant way (with angle brackets)...

mpp’s picture

Status: Active » Closed (works as designed)
imclean’s picture

Based on the RFC it would seem that mimemail handles this correctly.

Based on the RFC mimemail shouldn't be setting this at all.

  1. It is not a MIME related header: https://www.iana.org/assignments/message-headers/message-headers.xhtml
  2. It should not be set by Drupal or any other module (see #3)

See also: #3089331-6: Return-Path is set blank in MimeMailFormatHelper::mimeMailHeaders

l-laziz’s picture

The patch from this issue RfcComplianceException: RFC 2822 applies cleanly to the latest 1.0-alpha5 version and removes <> from Return-Path.