Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2 into ZF2-377
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-mabe committed Jul 17, 2012
5 parents 02e6999 + 1ede9ce + 757d24d + edaf480 + 8630680 commit 0d2038d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Decode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Zend\Mime;

use Zend\Mail\Headers;
use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
Expand Down Expand Up @@ -100,9 +101,10 @@ public static function splitMessageStruct($message, $boundary, $EOL = Mime::LINE
* @param Headers $headers output param, headers container
* @param string $body output param, content of message
* @param string $EOL EOL string; defaults to {@link Zend_Mime::LINEEND}
* @param boolean $strict enable strict mode for parsing message
* @return null
*/
public static function splitMessage($message, &$headers, &$body, $EOL = Mime::LINEEND)
public static function splitMessage($message, &$headers, &$body, $EOL = Mime::LINEEND, $strict = false)
{
if ($message instanceof Headers) {
$message = $message->toString();
Expand All @@ -116,6 +118,14 @@ public static function splitMessage($message, &$headers, &$body, $EOL = Mime::LI
return;
}

// see @ZF2-372, pops the first line off a message if it doesn't contain a header
if (!$strict) {
$parts = explode(': ', $firstline, 2);
if (count($parts) != 2) {
$message = substr($message, strpos($message, $EOL)+1);
}
}

// find an empty line between headers and body
// default is set new line
if (strpos($message, $EOL . $EOL)) {
Expand All @@ -128,7 +138,9 @@ public static function splitMessage($message, &$headers, &$body, $EOL = Mime::LI
list($headers, $body) = explode("\n\n", $message, 2);
// at last resort find anything that looks like a new line
} else {
@list($headers, $body) = @preg_split("%([\r\n]+)\\1%U", $message, 2);
ErrorHandler::start(E_NOTICE|E_WARNING);
list($headers, $body) = preg_split("%([\r\n]+)\\1%U", $message, 2);
ErrorHandler::stop();
}

$headers = Headers::fromString($headers, $EOL);
Expand Down

0 comments on commit 0d2038d

Please sign in to comment.