You are here

public static function HtmlMailMime::toHeaders in HTML Mail 8.3

Same name and namespace in other branches
  1. 8 src/Utility/HTMLMailMime.php \Drupal\htmlmail\Utility\HTMLMailMime::toHeaders()

Returns an array with keys changed to match the case of email headers.

Parameters

string|array $input: The headers to be changed, either as a \Mail_mime CRLF-delimited string or as an associative array of (name => value) pairs.

Return value

array An associative array of (name => value) pairs, with the case changed to match normal email headers.

2 calls to HtmlMailMime::toHeaders()
HtmlMailMime::encodeEmail in src/Utility/HtmlMailMime.php
Convert message headers and body into an encoded string.
HtmlMailMime::toEmail in src/Utility/HtmlMailMime.php
Return a (headers, body) pair for sending.

File

src/Utility/HtmlMailMime.php, line 605

Class

HtmlMailMime
Class HtmlMailMime.

Namespace

Drupal\htmlmail\Utility

Code

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;
}