diff --git a/smtp.module b/smtp.module index b96d7e0..1da5c23 100644 --- a/smtp.module +++ b/smtp.module @@ -592,10 +592,10 @@ function smtp_drupal_mail_wrapper($message) { // $mail->AltBody or $mail->Body, depending on whether there is // also a text/html part ot not. if (strpos($body_part, 'multipart/alternative')) { - // Get boundary ID from the Content-Type header. - $boundary2 = _smtp_get_substring($body_part, 'boundary', '"', '"'); // Clean up the text. $body_part = trim(_smtp_remove_headers(trim($body_part))); + // Get boundary ID from the Content-Type header. + $boundary2 = _smtp_get_substring($body_part, 'boundary', '"', '"'); // Split the body based on the boundary ID. $body_parts2 = _smtp_boundary_split($body_part, $boundary2); @@ -792,29 +792,23 @@ function _smtp_boundary_split($input, $boundary) { 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)); + if (strpos($part_array[0], 'Content') !== FALSE) { + if (strpos($part_array[1], 'Content') !== FALSE) { + if (strpos($part_array[2], 'Content') !== FALSE) { + array_shift($part_array); + array_shift($part_array); + array_shift($part_array); + } + else { + array_shift($part_array); + array_shift($part_array); } - } else { - // no match header, must be past headers; stop searching. - break; + } + else { + array_shift($part_array); } } - + $output = implode("\n", $part_array); return $output; } // End of _smtp_remove_headers().