diff --git a/library/Zend/Mail/Storage/Mbox.php b/library/Zend/Mail/Storage/Mbox.php index 847c3c0e0b2..7ae7754ff5b 100644 --- a/library/Zend/Mail/Storage/Mbox.php +++ b/library/Zend/Mail/Storage/Mbox.php @@ -42,6 +42,8 @@ class Mbox extends AbstractStorage * @var string */ protected $messageClass = '\Zend\Mail\Storage\Message\File'; + + protected $messageEOL; /** * Count messages all messages in current box @@ -108,8 +110,18 @@ public function getMessage($id) || is_subclass_of($this->messageClass, '\Zend\Mail\Storage\Message\File')) { // TODO top/body lines $messagePos = $this->getPos($id); - return new $this->messageClass(array('file' => $this->fh, 'startPos' => $messagePos['start'], - 'endPos' => $messagePos['end'])); + + $messageClassParams = array( + 'file' => $this->fh, + 'startPos' => $messagePos['start'], + 'endPos' => $messagePos['end'] + ); + + if ($this->messageEOL) { + $messageClassParams['EOL'] = $this->messageEOL; + } + + return new $this->messageClass($messageClassParams); } $bodyLines = 0; // TODO: need a way to change that @@ -183,6 +195,10 @@ public function __construct($params) if (!isset($params->filename)) { throw new Exception\InvalidArgumentException('no valid filename given in params'); } + + if (isset($params->messageEOL)) { + $this->messageEOL = $params->messageEOL; + } $this->openMboxFile($params->filename); $this->has['top'] = true; diff --git a/library/Zend/Mail/Storage/Part/File.php b/library/Zend/Mail/Storage/Part/File.php index b119c8e3c4d..ef92eba616d 100644 --- a/library/Zend/Mail/Storage/Part/File.php +++ b/library/Zend/Mail/Storage/Part/File.php @@ -25,7 +25,8 @@ class File extends Part * - file filename or open file handler with message content (required) * - startPos start position of message or part in file (default: current position) * - endPos end position of message or part in file (default: end of file) - * + * - EOL end of Line for fields + * * @param array $params full message with or without headers * @throws Exception\RuntimeException * @throws Exception\InvalidArgumentException @@ -53,7 +54,11 @@ public function __construct(array $params) $header .= $line; } - $this->headers = Headers::fromString($header); + if (isset($params['EOL'])){ + $this->headers = Headers::fromString($header, $params['EOL']); + }else{ + $this->headers = Headers::fromString($header); + } $this->contentPos[0] = ftell($this->fh); if ($endPos !== null) { diff --git a/tests/ZendTest/Mail/Storage/MboxTest.php b/tests/ZendTest/Mail/Storage/MboxTest.php index 6bd55299b2d..6711b487a61 100644 --- a/tests/ZendTest/Mail/Storage/MboxTest.php +++ b/tests/ZendTest/Mail/Storage/MboxTest.php @@ -19,6 +19,7 @@ class MboxTest extends \PHPUnit_Framework_TestCase { protected $_mboxOriginalFile; protected $_mboxFile; + protected $_mboxFileUnix; protected $_tmpdir; public function setUp() @@ -43,16 +44,26 @@ public function setUp() return; } } - - $this->_mboxOriginalFile = __DIR__ . '/../_files/test.mbox/INBOX'; + + $this->_mboxOriginalFile = __DIR__ . '/../_files/test.mbox/INBOX'; $this->_mboxFile = $this->_tmpdir . 'INBOX'; copy($this->_mboxOriginalFile, $this->_mboxFile); + + if (strpos($this->getName(), 'Unix')){ + $this->_mboxOriginalFileLinux = __DIR__ . '/../_files/test.mbox/INBOX.unix'; + $this->_mboxFileUnix = $this->_tmpdir . 'INBOX.unix'; + copy($this->_mboxOriginalFileLinux, $this->_mboxFileUnix); + } } public function tearDown() { unlink($this->_mboxFile); + + if ($this->_mboxFileUnix){ + unlink($this->_mboxFileUnix); + } } public function testLoadOk() @@ -155,6 +166,14 @@ public function testFetchTopBody() } */ + public function testFetchMessageHeaderLinuxUnix() + { + $mail = new Storage\Mbox(array('filename' => $this->_mboxFileUnix, 'messageEOL' => "\n")); + + $subject = $mail->getMessage(1)->subject; + $this->assertEquals('Simple Message', $subject); + } + public function testFetchMessageHeader() { $mail = new Storage\Mbox(array('filename' => $this->_mboxFile)); @@ -171,6 +190,15 @@ public function testFetchMessageBody() list($content, ) = explode("\n", $content, 2); $this->assertEquals('Fair river! in thy bright, clear flow', trim($content)); } + + public function testFetchMessageBodyUnix() + { + $mail = new Storage\Mbox(array('filename' => $this->_mboxFileUnix, 'messageEOL' => "\n")); + + $content = $mail->getMessage(3)->getContent(); + list($content, ) = explode("\n", $content, 2); + $this->assertEquals('Fair river! in thy bright, clear flow', trim($content)); + } public function testFailedRemove() {