You are here

public static function MailMIME::toHeaders in Mail MIME 7

Same name and namespace in other branches
  1. 8.2 mailmime.inc \MailMIME::toHeaders()
  2. 6.2 mailmime.inc \MailMIME::toHeaders()
  3. 6 mailmime.inc \MailMIME::toHeaders()
  4. 7.2 mailmime.inc \MailMIME::toHeaders()

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

Parameters

$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

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

2 calls to MailMIME::toHeaders()
MailMIME::encodeEmail in ./mailmime.inc
Convert message headers and body into an encoded string.
MailMIME::toEmail in ./mailmime.inc
Return a (headers, body) pair for sending.

File

./mailmime.inc, line 712
Provides the MailMIME class for creating MIME-formatted email messages.

Class

MailMIME
The MailMIME class is used to create MIME email messages.

Code

public static function toHeaders($input) {
  $headers = array();
  if (!is_array($input)) {
    $input = mail_mimeDecode::decode(array(
      'decode_headers' => TRUE,
      'input' => $input,
    ))->headers;
  }
  foreach ($input as $name => $value) {
    $name = preg_replace(array(
      '/([[:alpha:]])([[:alpha:]]+)/e',
      '/^Mime-/',
      '/-Id$/',
    ), array(
      'strtoupper("\\1") . strtolower("\\2")',
      'MIME-',
      '-ID',
    ), $name);
    $headers[$name] = $value;
  }
  return $headers;
}