You are here

function _smtp_remove_headers in SMTP Authentication Support 6

Strips the headers from the body part.

Parameters

input: A string containing the body part to strip.

Return value

A string with the stripped body part.

1 call to _smtp_remove_headers()
smtp_drupal_mail_wrapper in ./smtp.module
Sends out the e-mail.

File

./smtp.module, line 877
Enables Drupal to send e-mail directly to an SMTP server.

Code

function _smtp_remove_headers($input) {
  $part_array = explode("\n", $input);

  // will strip these headers according to RFC2045
  $headers_to_strip = array(
    'Content-Type',
    'Content-Transfer-Encoding',
    'Content-ID',
    'Content-Disposition',
  );
  $pattern = '/^(' . implode('|', $headers_to_strip) . '):/';
  while (count($part_array) > 0) {
    $line = rtrim($part_array[0]);

    // ignore trailing spaces/newlines
    // if the line starts with a known header string
    if (preg_match($pattern, $line)) {
      $line = rtrim(array_shift($part_array));

      // remove line containing matched header.
      // if line ends in a ';' and the next line starts with four spaces, it's a continuation
      // of the header split onto the next line. Continue removing lines while we have this condition.
      while (substr($line, -1) == ';' && count($part_array) > 0 && substr($part_array[0], 0, 4) == '    ') {
        $line = rtrim(array_shift($part_array));
      }
    }
    else {

      // no match header, must be past headers; stop searching.
      break;
    }
  }
  $output = implode("\n", $part_array);
  return $output;
}