From db05dd1188957a579631d46ab01b336c306c9177 Mon Sep 17 00:00:00 2001 From: Michael J Rubinsky Date: Wed, 10 Dec 2014 00:09:03 -0500 Subject: [PATCH] Fix issue with clients that send broken, mixed EOL, messages. Nine, for example, currently does this and it completly breaks the email parsing code. Also, use Horde_Stream::search(). --- .../lib/Horde/ActiveSync/Rfc822.php | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/Rfc822.php b/framework/ActiveSync/lib/Horde/ActiveSync/Rfc822.php index 071a9e9956b..010647b1c3d 100644 --- a/framework/ActiveSync/lib/Horde/ActiveSync/Rfc822.php +++ b/framework/ActiveSync/lib/Horde/ActiveSync/Rfc822.php @@ -224,21 +224,14 @@ public function getBytes() */ protected function _findHeader() { - $i = 0; - while (!$this->_stream->eof()) { - $data = $this->_stream->substring(0, 8192); - $hdr_pos = strpos($data, "\r\n\r\n"); - if ($hdr_pos !== false) { - return array($hdr_pos + ($i * 8192), 4); - } - $hdr_pos = strpos($data, "\n\n"); - if ($hdr_pos !== false) { - return array($hdr_pos + ($i * 8192), 2); - } - $i++; + // Look for the EOL that is found first in the message. Some clients + // are sending mixed EOL in S/MIME signed messages. + switch ($this->_stream->getEOL()) { + case "\n": + return array($this->_stream->search("\n\n"), 2); + case "\r\n": + return array($this->stream->search("\r\n\r\n"), 4); } - $this->_stream->end(); - return array($this->_stream->pos(), 0); } }