HtmlMailMime::toHeaders() mangles headers when using the optional \Mail_mime class

Created on 22 October 2020, about 4 years ago
Updated 10 May 2023, over 1 year ago
  public static function toHeaders($input) {
    $headers = [];
    if (!is_array($input)) {
      $decoder = new \Mail_mimeDecode($input);
      $input = $decoder->decode([
        'decode_headers' => TRUE,
        'input' => $input,
      ]);
    }
    foreach ($input as $name => $value) {
      $name = preg_replace(
        [
          '/([[:alpha:]])([[:alpha:]]+)/',
          '/^Mime-/',
          '/-Id$/',
        ],
        [
          'strtoupper("\1") . strtolower("\2")',
          'MIME-',
          '-ID',
        ],
        $name
      );
      $headers[$name] = $value;
    }
    return $headers;
  }

In this snippet, you can no longer do strtoupper() in the preg_replace as I believe the `e` modifier has been deprecated due to security issues?

I'm getting these headers:


    [headers] => Array
        (
            [strtoupper("M") . strtolower("IME")-strtoupper("V") . strtolower("ersion")] => 1.0
            [strtoupper("C") . strtolower("ontent")-strtoupper("T") . strtolower("ype")] => text/plain; charset=UTF-8; format=flowed; delsp=yes
            [strtoupper("C") . strtolower("ontent")-strtoupper("T") . strtolower("ransfer")-strtoupper("E") . strtolower("ncoding")] => 8Bit
            [X-strtoupper("M") . strtolower("ailer")] => Drupal
            [strtoupper("R") . strtolower("eturn")-strtoupper("P") . strtolower("ath")] => test@example.com
            [strtoupper("S") . strtolower("ender")] => test@example.com
            [strtoupper("F") . strtolower("rom")] => Example Site
            [strtoupper("R") . strtolower("eply")-strtoupper("t") . strtolower("o")] => test@example.com
            [MIME-Version] => 1.0
            [Content-Type] => text/html; charset=ISO-8859-1
            [Content-Transfer-Encoding] => quoted-printable
        )/
🐛 Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

🇬🇧United Kingdom nicholasthompson

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024