From ec832231ef097fdec1d56c96a2081a2af207b79d Mon Sep 17 00:00:00 2001 From: Maks3w Date: Tue, 8 Sep 2015 17:34:40 +0200 Subject: [PATCH 1/3] Improve test case Add a data provider and compact assertions against current object state. --- test/Storage/MessageTest.php | 52 +++++++++++++++--------------------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/test/Storage/MessageTest.php b/test/Storage/MessageTest.php index 810a352a..b6f3a20a 100644 --- a/test/Storage/MessageTest.php +++ b/test/Storage/MessageTest.php @@ -39,41 +39,19 @@ public function testInvalidFile() $this->fail('no exception raised while loading unknown file'); } - public function testIsMultipart() - { - $message = new Message(['file' => $this->_file]); - - $this->assertTrue($message->isMultipart()); - } - - public function testGetHeader() - { - $message = new Message(['file' => $this->_file]); - - $this->assertEquals($message->subject, 'multipart'); - } - - public function testGetDecodedHeader() - { - $message = new Message(['file' => $this->_file]); - - $this->assertEquals('Peter Müller ', $message->from); - } - - public function testGetHeaderAsArray() + /** + * @dataProvider filesProvider + */ + public function testParseFile($params) { - $message = new Message(['file' => $this->_file]); + $message = new Message($params); - $this->assertEquals($message->getHeader('subject', 'array'), ['multipart']); + $this->assertTrue($message->isMultipart(), 'isMultipart() value not match'); + $this->assertEquals($message->subject, 'multipart', 'subject value not match'); + $this->assertEquals('Peter Müller ', $message->from, 'from value not match'); + $this->assertEquals(['multipart'], $message->getHeader('subject', 'array'), 'getHeader() value not match'); } - public function testGetHeaderFromOpenFile() - { - $fh = fopen($this->_file, 'r'); - $message = new Message(['file' => $fh]); - - $this->assertEquals($message->subject, 'multipart'); - } public function testGetFirstPart() { @@ -428,4 +406,16 @@ public function testStrictParseMessage() $raw = "From foo@example.com Sun Jan 01 00:00:00 2000\n" . $raw; $message = new Message(['raw' => $raw, 'strict' => true]); } + + public function filesProvider() + { + $filePath = __DIR__ . '/../_files/mail.txt'; + + return [ + // Description => [params] + 'resource' => [['file' => fopen($filePath, 'r')]], + 'file path' => [['file' => $filePath]], + 'raw' => [['raw' => file_get_contents($filePath)]], + ]; + } } From 2ed013419690876d46ae08024e6b61642817646e Mon Sep 17 00:00:00 2001 From: Maks3w Date: Tue, 8 Sep 2015 17:44:13 +0200 Subject: [PATCH 2/3] Add test with a blank line on top of the mail message --- test/Storage/MessageTest.php | 2 ++ test/_files/mail_blank_top_line.txt | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 test/_files/mail_blank_top_line.txt diff --git a/test/Storage/MessageTest.php b/test/Storage/MessageTest.php index b6f3a20a..bfd875be 100644 --- a/test/Storage/MessageTest.php +++ b/test/Storage/MessageTest.php @@ -410,12 +410,14 @@ public function testStrictParseMessage() public function filesProvider() { $filePath = __DIR__ . '/../_files/mail.txt'; + $fileBlankLineOnTop = __DIR__ . '/../_files/mail_blank_top_line.txt'; return [ // Description => [params] 'resource' => [['file' => fopen($filePath, 'r')]], 'file path' => [['file' => $filePath]], 'raw' => [['raw' => file_get_contents($filePath)]], + 'file with blank line on top' => [['file' => $fileBlankLineOnTop]], ]; } } diff --git a/test/_files/mail_blank_top_line.txt b/test/_files/mail_blank_top_line.txt new file mode 100644 index 00000000..56a53e93 --- /dev/null +++ b/test/_files/mail_blank_top_line.txt @@ -0,0 +1,28 @@ + +To: foo@example.com +Subject: multipart +Date: Sun, 01 Jan 2000 00:00:00 +0000 +From: =?UTF-8?Q?"Peter M=C3=BCller"?= +ContENT-type: multipart/alternative; boUNDary="crazy-multipart" +Message-ID: +MIME-version: 1.0 + +multipart message +--crazy-multipart +Content-type: text/plain + +The first part +is horizontal + +--crazy-multipart +Content-type: text/x-vertical + +T s p i v +h e a s e +e c r r + o t t + n i + d c + a + l +--crazy-multipart-- From ef645872c579e3ca4c765d4091fc09e4a76b76c7 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Tue, 8 Sep 2015 17:45:20 +0200 Subject: [PATCH 3/3] Workaround to messages with a blank line on top --- src/Storage/Message.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Storage/Message.php b/src/Storage/Message.php index 82550952..5d886c86 100644 --- a/src/Storage/Message.php +++ b/src/Storage/Message.php @@ -42,6 +42,8 @@ public function __construct(array $params) } else { $params['raw'] = stream_get_contents($params['file']); } + + $params['raw'] = ltrim($params['raw']); } if (!empty($params['flags'])) {