You are here

function mimemail_parse_headers in Mime Mail 5

Same name and namespace in other branches
  1. 6 mimemail.inc \mimemail_parse_headers()
  2. 7 includes/mimemail.incoming.inc \mimemail_parse_headers()
1 call to mimemail_parse_headers()
mimemail_parse in ./mimemail.inc

File

./mimemail.inc, line 414

Code

function mimemail_parse_headers($message) {

  // Split out body and headers
  if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $message, $match)) {
    list($hdr, $body) = array(
      $match[1],
      $match[2],
    );
  }

  // Un-fold the headers.
  $hdr = preg_replace(array(
    "/\r/",
    "/\n(\t| )+/",
  ), array(
    '',
    ' ',
  ), $hdr);
  $headers = array();
  foreach (explode("\n", trim($hdr)) as $row) {
    $split = strpos($row, ':');
    $name = trim(substr($row, 0, $split));
    $val = trim(substr($row, $split + 1));
    $headers[$name] = $val;
  }
  $type = preg_replace('/\\s*([^;]+).*/', '\\1', $headers['Content-Type']);
  return array(
    'headers' => $headers,
    'body' => $body,
    'content-type' => $type,
  );
}