From 8b2a644bd5f8650b2241df1802772dea717859e5 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Thu, 16 Feb 2017 14:48:20 +0100 Subject: [PATCH 01/10] Created first test case --- composer.json | 4 +++- tests/PlancakeEmailParserTest.php | 19 +++++++++++++++++++ tests/bootstrap.php | 2 ++ tests/emails/0.yml | 1 + tests/emails/1.yml | 1 + tests/emails/2.yml | 1 + tests/emails/from_ipad_with_attachment.yml | 1 + tests/emails/subject_on_multiple_lines.yml | 1 + 8 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/PlancakeEmailParserTest.php create mode 100644 tests/bootstrap.php create mode 100644 tests/emails/0.yml create mode 100644 tests/emails/1.yml create mode 100644 tests/emails/2.yml create mode 100644 tests/emails/from_ipad_with_attachment.yml create mode 100644 tests/emails/subject_on_multiple_lines.yml diff --git a/composer.json b/composer.json index 67d6cb5..b9c3bc4 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,9 @@ "ext-mbstring": "*" }, "require-dev": { - "squizlabs/php_codesniffer": "~2.5.1" + "squizlabs/php_codesniffer": "~2.5.1", + "phpunit/phpunit": "^6.0", + "symfony/yaml": "^3.2" }, "autoload": { "psr-0": { "PlancakeEmailParser": "." } diff --git a/tests/PlancakeEmailParserTest.php b/tests/PlancakeEmailParserTest.php new file mode 100644 index 0000000..0ed59f0 --- /dev/null +++ b/tests/PlancakeEmailParserTest.php @@ -0,0 +1,19 @@ +assertEquals($answers['subject'], $email->getSubject()); + } + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..dab2002 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,2 @@ + Date: Thu, 16 Feb 2017 14:54:14 +0100 Subject: [PATCH 02/10] Added testcase for "From: " --- tests/PlancakeEmailParserTest.php | 15 +++++++++++++++ tests/emails/0.yml | 5 ++++- tests/emails/1.yml | 5 ++++- tests/emails/2.yml | 5 ++++- tests/emails/from_ipad_with_attachment.yml | 5 ++++- tests/emails/subject_on_multiple_lines.yml | 5 ++++- 6 files changed, 35 insertions(+), 5 deletions(-) diff --git a/tests/PlancakeEmailParserTest.php b/tests/PlancakeEmailParserTest.php index 0ed59f0..083581c 100644 --- a/tests/PlancakeEmailParserTest.php +++ b/tests/PlancakeEmailParserTest.php @@ -3,6 +3,7 @@ use PHPUnit\Framework\TestCase; class PlancakeEmailParserTest extends TestCase { + public function testSubject() { foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { @@ -16,4 +17,18 @@ public function testSubject() { $this->assertEquals($answers['subject'], $email->getSubject()); } } + + public function testFrom() { + foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { + + $answerFile = str_replace('.txt', '.yml', $testFile); + $answers = \Symfony\Component\Yaml\Yaml::parse( + file_get_contents($answerFile) + ); + + $email = new PlancakeEmailParser(file_get_contents($testFile)); + + $this->assertEquals($answers['from'], $email->getFrom()); + } + } } diff --git a/tests/emails/0.yml b/tests/emails/0.yml index 08782e6..8b8310e 100644 --- a/tests/emails/0.yml +++ b/tests/emails/0.yml @@ -1 +1,4 @@ -subject: 'zażółć gęślą jaźń i zrób próbne zadanie %%tod' \ No newline at end of file +subject: 'zażółć gęślą jaźń i zrób próbne zadanie %%tod' +from: + - name: Pawel + email: pawel@test.com \ No newline at end of file diff --git a/tests/emails/1.yml b/tests/emails/1.yml index b3a97b4..ed28f5c 100644 --- a/tests/emails/1.yml +++ b/tests/emails/1.yml @@ -1 +1,4 @@ -subject: this is a test \ No newline at end of file +subject: this is a test +from: + - name: Dan @ Test.com + email: dan@test.com \ No newline at end of file diff --git a/tests/emails/2.yml b/tests/emails/2.yml index ae483ea..c966ada 100644 --- a/tests/emails/2.yml +++ b/tests/emails/2.yml @@ -1 +1,4 @@ -subject: 'これはテストです' \ No newline at end of file +subject: 'これはテストです' +from: + - name: Dan + email: dan@test.com \ No newline at end of file diff --git a/tests/emails/from_ipad_with_attachment.yml b/tests/emails/from_ipad_with_attachment.yml index 870be5f..c9be966 100644 --- a/tests/emails/from_ipad_with_attachment.yml +++ b/tests/emails/from_ipad_with_attachment.yml @@ -1 +1,4 @@ -subject: Voice Memo \ No newline at end of file +subject: Voice Memo +from: + - name: Dan Occhi + email: dan@example.com \ No newline at end of file diff --git a/tests/emails/subject_on_multiple_lines.yml b/tests/emails/subject_on_multiple_lines.yml index 8d1952f..9d192c6 100644 --- a/tests/emails/subject_on_multiple_lines.yml +++ b/tests/emails/subject_on_multiple_lines.yml @@ -1 +1,4 @@ -subject: 'Re: Testo Del di Soggetto Che Va A Capo In UTF8 ' \ No newline at end of file +subject: 'Re: Testo Del di Soggetto Che Va A Capo In UTF8 ' +from: + - name: '' + email: info@domain.it \ No newline at end of file From aaf612a813588e8e41734d7f5eab7b91964a9c44 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Thu, 16 Feb 2017 14:58:44 +0100 Subject: [PATCH 03/10] Added testcase for "To: " --- tests/PlancakeEmailParserTest.php | 14 ++++++++++++++ tests/emails/0.yml | 5 ++++- tests/emails/1.yml | 5 ++++- tests/emails/2.yml | 5 ++++- tests/emails/from_ipad_with_attachment.yml | 5 ++++- tests/emails/subject_on_multiple_lines.yml | 5 ++++- 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/tests/PlancakeEmailParserTest.php b/tests/PlancakeEmailParserTest.php index 083581c..a1c9abe 100644 --- a/tests/PlancakeEmailParserTest.php +++ b/tests/PlancakeEmailParserTest.php @@ -31,4 +31,18 @@ public function testFrom() { $this->assertEquals($answers['from'], $email->getFrom()); } } + + public function testTo() { + foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { + + $answerFile = str_replace('.txt', '.yml', $testFile); + $answers = \Symfony\Component\Yaml\Yaml::parse( + file_get_contents($answerFile) + ); + + $email = new PlancakeEmailParser(file_get_contents($testFile)); + + $this->assertEquals($answers['to'], $email->getTo()); + } + } } diff --git a/tests/emails/0.yml b/tests/emails/0.yml index 8b8310e..f7562fe 100644 --- a/tests/emails/0.yml +++ b/tests/emails/0.yml @@ -1,4 +1,7 @@ subject: 'zażółć gęślą jaźń i zrób próbne zadanie %%tod' from: - name: Pawel - email: pawel@test.com \ No newline at end of file + email: pawel@test.com +to: + - name: '' + email: dan@test.com \ No newline at end of file diff --git a/tests/emails/1.yml b/tests/emails/1.yml index ed28f5c..187674a 100644 --- a/tests/emails/1.yml +++ b/tests/emails/1.yml @@ -1,4 +1,7 @@ subject: this is a test from: - name: Dan @ Test.com - email: dan@test.com \ No newline at end of file + email: dan@test.com +to: + - name: 'Daniele ' + email: danielet@test.com \ No newline at end of file diff --git a/tests/emails/2.yml b/tests/emails/2.yml index c966ada..a914ae5 100644 --- a/tests/emails/2.yml +++ b/tests/emails/2.yml @@ -1,4 +1,7 @@ subject: 'これはテストです' from: - name: Dan - email: dan@test.com \ No newline at end of file + email: dan@test.com +to: + - name: 'Daniele' + email: daniele@test.com \ No newline at end of file diff --git a/tests/emails/from_ipad_with_attachment.yml b/tests/emails/from_ipad_with_attachment.yml index c9be966..a0fcab2 100644 --- a/tests/emails/from_ipad_with_attachment.yml +++ b/tests/emails/from_ipad_with_attachment.yml @@ -1,4 +1,7 @@ subject: Voice Memo from: - name: Dan Occhi - email: dan@example.com \ No newline at end of file + email: dan@example.com +to: + - name: Inbox_danocch.it_2063@examplebox.com + email: Inbox_danocch.it_2063@examplebox.com \ No newline at end of file diff --git a/tests/emails/subject_on_multiple_lines.yml b/tests/emails/subject_on_multiple_lines.yml index 9d192c6..6fa2cc5 100644 --- a/tests/emails/subject_on_multiple_lines.yml +++ b/tests/emails/subject_on_multiple_lines.yml @@ -1,4 +1,7 @@ subject: 'Re: Testo Del di Soggetto Che Va A Capo In UTF8 ' from: - name: '' - email: info@domain.it \ No newline at end of file + email: info@domain.it +to: + - name: '' + email: bounce@domain-bounce.it \ No newline at end of file From bf67da5a631b5f2fb3a54ccc720e438e58f5f2f9 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Thu, 16 Feb 2017 15:00:58 +0100 Subject: [PATCH 04/10] Added testcase for CC and BCC --- tests/PlancakeEmailParserTest.php | 28 ++++++++++++++++++++++ tests/emails/0.yml | 4 +++- tests/emails/1.yml | 4 +++- tests/emails/2.yml | 4 +++- tests/emails/from_ipad_with_attachment.yml | 4 +++- tests/emails/subject_on_multiple_lines.yml | 4 +++- 6 files changed, 43 insertions(+), 5 deletions(-) diff --git a/tests/PlancakeEmailParserTest.php b/tests/PlancakeEmailParserTest.php index a1c9abe..7a3e199 100644 --- a/tests/PlancakeEmailParserTest.php +++ b/tests/PlancakeEmailParserTest.php @@ -45,4 +45,32 @@ public function testTo() { $this->assertEquals($answers['to'], $email->getTo()); } } + + public function testCc() { + foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { + + $answerFile = str_replace('.txt', '.yml', $testFile); + $answers = \Symfony\Component\Yaml\Yaml::parse( + file_get_contents($answerFile) + ); + + $email = new PlancakeEmailParser(file_get_contents($testFile)); + + $this->assertEquals($answers['cc'], $email->getCc()); + } + } + + public function testBcc() { + foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { + + $answerFile = str_replace('.txt', '.yml', $testFile); + $answers = \Symfony\Component\Yaml\Yaml::parse( + file_get_contents($answerFile) + ); + + $email = new PlancakeEmailParser(file_get_contents($testFile)); + + $this->assertEquals($answers['bcc'], $email->getBcc()); + } + } } diff --git a/tests/emails/0.yml b/tests/emails/0.yml index f7562fe..f203372 100644 --- a/tests/emails/0.yml +++ b/tests/emails/0.yml @@ -4,4 +4,6 @@ from: email: pawel@test.com to: - name: '' - email: dan@test.com \ No newline at end of file + email: dan@test.com +cc: [] +bcc: [] \ No newline at end of file diff --git a/tests/emails/1.yml b/tests/emails/1.yml index 187674a..64fe3d5 100644 --- a/tests/emails/1.yml +++ b/tests/emails/1.yml @@ -4,4 +4,6 @@ from: email: dan@test.com to: - name: 'Daniele ' - email: danielet@test.com \ No newline at end of file + email: danielet@test.com +cc: [] +bcc: [] \ No newline at end of file diff --git a/tests/emails/2.yml b/tests/emails/2.yml index a914ae5..9e3a4bb 100644 --- a/tests/emails/2.yml +++ b/tests/emails/2.yml @@ -4,4 +4,6 @@ from: email: dan@test.com to: - name: 'Daniele' - email: daniele@test.com \ No newline at end of file + email: daniele@test.com +cc: [] +bcc: [] \ No newline at end of file diff --git a/tests/emails/from_ipad_with_attachment.yml b/tests/emails/from_ipad_with_attachment.yml index a0fcab2..f6e6cc5 100644 --- a/tests/emails/from_ipad_with_attachment.yml +++ b/tests/emails/from_ipad_with_attachment.yml @@ -4,4 +4,6 @@ from: email: dan@example.com to: - name: Inbox_danocch.it_2063@examplebox.com - email: Inbox_danocch.it_2063@examplebox.com \ No newline at end of file + email: Inbox_danocch.it_2063@examplebox.com +cc: [] +bcc: [] \ No newline at end of file diff --git a/tests/emails/subject_on_multiple_lines.yml b/tests/emails/subject_on_multiple_lines.yml index 6fa2cc5..69d6cb0 100644 --- a/tests/emails/subject_on_multiple_lines.yml +++ b/tests/emails/subject_on_multiple_lines.yml @@ -4,4 +4,6 @@ from: email: info@domain.it to: - name: '' - email: bounce@domain-bounce.it \ No newline at end of file + email: bounce@domain-bounce.it +cc: [] +bcc: [] \ No newline at end of file From 0b352d1a259447fea595a8d63ac33345557a88d3 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Thu, 16 Feb 2017 15:03:04 +0100 Subject: [PATCH 05/10] Added test for Sender header --- tests/PlancakeEmailParserTest.php | 14 ++++++++++++++ tests/emails/0.yml | 3 ++- tests/emails/1.yml | 3 ++- tests/emails/2.yml | 3 ++- tests/emails/from_ipad_with_attachment.yml | 3 ++- tests/emails/subject_on_multiple_lines.yml | 3 ++- 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/PlancakeEmailParserTest.php b/tests/PlancakeEmailParserTest.php index 7a3e199..442989a 100644 --- a/tests/PlancakeEmailParserTest.php +++ b/tests/PlancakeEmailParserTest.php @@ -73,4 +73,18 @@ public function testBcc() { $this->assertEquals($answers['bcc'], $email->getBcc()); } } + + public function testSender() { + foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { + + $answerFile = str_replace('.txt', '.yml', $testFile); + $answers = \Symfony\Component\Yaml\Yaml::parse( + file_get_contents($answerFile) + ); + + $email = new PlancakeEmailParser(file_get_contents($testFile)); + + $this->assertEquals($answers['sender'], $email->getSender()); + } + } } diff --git a/tests/emails/0.yml b/tests/emails/0.yml index f203372..bd1e8d0 100644 --- a/tests/emails/0.yml +++ b/tests/emails/0.yml @@ -6,4 +6,5 @@ to: - name: '' email: dan@test.com cc: [] -bcc: [] \ No newline at end of file +bcc: [] +sender: [] \ No newline at end of file diff --git a/tests/emails/1.yml b/tests/emails/1.yml index 64fe3d5..ca04380 100644 --- a/tests/emails/1.yml +++ b/tests/emails/1.yml @@ -6,4 +6,5 @@ to: - name: 'Daniele ' email: danielet@test.com cc: [] -bcc: [] \ No newline at end of file +bcc: [] +sender: [] \ No newline at end of file diff --git a/tests/emails/2.yml b/tests/emails/2.yml index 9e3a4bb..7fc2078 100644 --- a/tests/emails/2.yml +++ b/tests/emails/2.yml @@ -6,4 +6,5 @@ to: - name: 'Daniele' email: daniele@test.com cc: [] -bcc: [] \ No newline at end of file +bcc: [] +sender: [] \ No newline at end of file diff --git a/tests/emails/from_ipad_with_attachment.yml b/tests/emails/from_ipad_with_attachment.yml index f6e6cc5..ab17fed 100644 --- a/tests/emails/from_ipad_with_attachment.yml +++ b/tests/emails/from_ipad_with_attachment.yml @@ -6,4 +6,5 @@ to: - name: Inbox_danocch.it_2063@examplebox.com email: Inbox_danocch.it_2063@examplebox.com cc: [] -bcc: [] \ No newline at end of file +bcc: [] +sender: [] \ No newline at end of file diff --git a/tests/emails/subject_on_multiple_lines.yml b/tests/emails/subject_on_multiple_lines.yml index 69d6cb0..3c814a9 100644 --- a/tests/emails/subject_on_multiple_lines.yml +++ b/tests/emails/subject_on_multiple_lines.yml @@ -6,4 +6,5 @@ to: - name: '' email: bounce@domain-bounce.it cc: [] -bcc: [] \ No newline at end of file +bcc: [] +sender: [] \ No newline at end of file From 96a522379ff9b06ba3906a1a81a5568fe1a5b1cc Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Thu, 16 Feb 2017 15:10:23 +0100 Subject: [PATCH 06/10] Added test case for plaintext body --- tests/PlancakeEmailParserTest.php | 14 ++++++++++++++ tests/emails/0.yml | 7 ++++++- tests/emails/1.yml | 3 ++- tests/emails/2.yml | 3 ++- tests/emails/from_ipad_with_attachment.yml | 3 ++- tests/emails/subject_on_multiple_lines.yml | 6 +++++- 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/tests/PlancakeEmailParserTest.php b/tests/PlancakeEmailParserTest.php index 442989a..756df88 100644 --- a/tests/PlancakeEmailParserTest.php +++ b/tests/PlancakeEmailParserTest.php @@ -87,4 +87,18 @@ public function testSender() { $this->assertEquals($answers['sender'], $email->getSender()); } } + + public function testPlainBody() { + foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { + + $answerFile = str_replace('.txt', '.yml', $testFile); + $answers = \Symfony\Component\Yaml\Yaml::parse( + file_get_contents($answerFile) + ); + + $email = new PlancakeEmailParser(file_get_contents($testFile)); + + $this->assertEquals($answers['plainbody'], $email->getPlainBody()); + } + } } diff --git a/tests/emails/0.yml b/tests/emails/0.yml index bd1e8d0..603fd36 100644 --- a/tests/emails/0.yml +++ b/tests/emails/0.yml @@ -7,4 +7,9 @@ to: email: dan@test.com cc: [] bcc: [] -sender: [] \ No newline at end of file +sender: [] +plainbody: This is a nonesense test-email to check Plancake Mail to Inbox feature. + All Polish diacritics included ;-) tag also included for additional tests. + It should look like in the picture attached. + Best regards + Pawel \ No newline at end of file diff --git a/tests/emails/1.yml b/tests/emails/1.yml index ca04380..3c85c4a 100644 --- a/tests/emails/1.yml +++ b/tests/emails/1.yml @@ -7,4 +7,5 @@ to: email: danielet@test.com cc: [] bcc: [] -sender: [] \ No newline at end of file +sender: [] +plainbody: Hope it works! \ No newline at end of file diff --git a/tests/emails/2.yml b/tests/emails/2.yml index 7fc2078..76e9c5c 100644 --- a/tests/emails/2.yml +++ b/tests/emails/2.yml @@ -7,4 +7,5 @@ to: email: daniele@test.com cc: [] bcc: [] -sender: [] \ No newline at end of file +sender: [] +plainbody: $B$=$l$O:nIJ$r4|BT(B \ No newline at end of file diff --git a/tests/emails/from_ipad_with_attachment.yml b/tests/emails/from_ipad_with_attachment.yml index ab17fed..1dbd508 100644 --- a/tests/emails/from_ipad_with_attachment.yml +++ b/tests/emails/from_ipad_with_attachment.yml @@ -7,4 +7,5 @@ to: email: Inbox_danocch.it_2063@examplebox.com cc: [] bcc: [] -sender: [] \ No newline at end of file +sender: [] +plainbody: '' \ No newline at end of file diff --git a/tests/emails/subject_on_multiple_lines.yml b/tests/emails/subject_on_multiple_lines.yml index 3c814a9..39f70e3 100644 --- a/tests/emails/subject_on_multiple_lines.yml +++ b/tests/emails/subject_on_multiple_lines.yml @@ -7,4 +7,8 @@ to: email: bounce@domain-bounce.it cc: [] bcc: [] -sender: [] \ No newline at end of file +sender: [] +plainbody: 'Da: info@domain.it + Oggetto: Grazie!!! + + Nome Cognome' \ No newline at end of file From b7fdd155fd970a3f13154346ab82f7c09a85e0d4 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Thu, 16 Feb 2017 15:39:48 +0100 Subject: [PATCH 07/10] Fixed boundary regex --- PlancakeEmailParser.php | 8 +++----- tests/emails/0.yml | 11 ++++++----- tests/emails/2.yml | 2 +- tests/emails/subject_on_multiple_lines.yml | 10 +++++++--- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/PlancakeEmailParser.php b/PlancakeEmailParser.php index d4e3195..7775660 100644 --- a/PlancakeEmailParser.php +++ b/PlancakeEmailParser.php @@ -412,16 +412,14 @@ public function getBody($returnType = self::PLAINTEXT) } // there could be more than one boundary - preg_match_all('!boundary=(.*?)[;$]!mi', $this->emailRawContent, $matches); + preg_match_all('/boundary=(?:|")([a-zA-Z0-9\(\)_\/+-]+)(?:|")(?:$|;)/mi', $this->emailRawContent, $matches); $boundariesRaw = $matches[1]; $boundaries = array(); foreach ($boundariesRaw as $i => $v) { - // sometimes boundaries are delimited by quotes - we want to remove them - $tempboundary = str_replace(array("'", '"'), '', $v); // actual boundary lines start with -- - $boundaries[] = '--' . $tempboundary; + $boundaries[] = '--' . $v; // or start and end with -- - $boundaries[] = '--' . $tempboundary . '--'; + $boundaries[] = '--' . $v . '--'; } foreach ($this->rawBodyLines as $line) { diff --git a/tests/emails/0.yml b/tests/emails/0.yml index 603fd36..6a48fdb 100644 --- a/tests/emails/0.yml +++ b/tests/emails/0.yml @@ -8,8 +8,9 @@ to: cc: [] bcc: [] sender: [] -plainbody: This is a nonesense test-email to check Plancake Mail to Inbox feature. - All Polish diacritics included ;-) tag also included for additional tests. - It should look like in the picture attached. - Best regards - Pawel \ No newline at end of file +plainbody: | + This is a nonesense test-email to check Plancake Mail to Inbox feature. + All Polish diacritics included ;-) tag also included for additional tests. + It should look like in the picture attached. + Best regards + Pawel \ No newline at end of file diff --git a/tests/emails/2.yml b/tests/emails/2.yml index 76e9c5c..900f869 100644 --- a/tests/emails/2.yml +++ b/tests/emails/2.yml @@ -8,4 +8,4 @@ to: cc: [] bcc: [] sender: [] -plainbody: $B$=$l$O:nIJ$r4|BT(B \ No newline at end of file +plainbody: 'それは作品を期待' \ No newline at end of file diff --git a/tests/emails/subject_on_multiple_lines.yml b/tests/emails/subject_on_multiple_lines.yml index 39f70e3..e804b54 100644 --- a/tests/emails/subject_on_multiple_lines.yml +++ b/tests/emails/subject_on_multiple_lines.yml @@ -8,7 +8,11 @@ to: cc: [] bcc: [] sender: [] -plainbody: 'Da: info@domain.it - Oggetto: Grazie!!! +plainbody: | - Nome Cognome' \ No newline at end of file + + + Da: info@domain.it + Oggetto: Grazie!!! + + Nome Cognome \ No newline at end of file From 95ba89c85dae059d44a6a63cdd5274d5041d6511 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Sat, 18 Feb 2017 13:55:23 +0100 Subject: [PATCH 08/10] Updated comment for the regex --- PlancakeEmailParser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PlancakeEmailParser.php b/PlancakeEmailParser.php index 7775660..d029329 100644 --- a/PlancakeEmailParser.php +++ b/PlancakeEmailParser.php @@ -411,7 +411,7 @@ public function getBody($returnType = self::PLAINTEXT) $contentTypeRegex = '/^Content-Type: ?text\/plain/i'; } - // there could be more than one boundary + // there could be more than one boundary. This also skips the quotes if they are included. preg_match_all('/boundary=(?:|")([a-zA-Z0-9\(\)_\/+-]+)(?:|")(?:$|;)/mi', $this->emailRawContent, $matches); $boundariesRaw = $matches[1]; $boundaries = array(); From ba46a8fb6f2434366d56416f712c5c7b6462aacf Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Sat, 18 Feb 2017 15:10:17 +0100 Subject: [PATCH 09/10] Applied PSR-1/PSR-2 formatting to the unit tests and fixed bootstrap --- tests/PlancakeEmailParserTest.php | 138 ++++++++++++++++-------------- tests/bootstrap.php | 2 +- 2 files changed, 74 insertions(+), 66 deletions(-) diff --git a/tests/PlancakeEmailParserTest.php b/tests/PlancakeEmailParserTest.php index 756df88..6e0e5c7 100644 --- a/tests/PlancakeEmailParserTest.php +++ b/tests/PlancakeEmailParserTest.php @@ -1,104 +1,112 @@ assertEquals($answers['subject'], $email->getSubject()); + $this->assertEquals($answers['subject'], $email->getSubject()); + } } - } - public function testFrom() { - foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { + public function testFrom() + { + foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { - $answerFile = str_replace('.txt', '.yml', $testFile); - $answers = \Symfony\Component\Yaml\Yaml::parse( - file_get_contents($answerFile) - ); + $answerFile = str_replace('.txt', '.yml', $testFile); + $answers = Yaml::parse( + file_get_contents($answerFile) + ); - $email = new PlancakeEmailParser(file_get_contents($testFile)); + $email = new PlancakeEmailParser(file_get_contents($testFile)); - $this->assertEquals($answers['from'], $email->getFrom()); + $this->assertEquals($answers['from'], $email->getFrom()); + } } - } - public function testTo() { - foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { + public function testTo() + { + foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { - $answerFile = str_replace('.txt', '.yml', $testFile); - $answers = \Symfony\Component\Yaml\Yaml::parse( - file_get_contents($answerFile) - ); + $answerFile = str_replace('.txt', '.yml', $testFile); + $answers = Yaml::parse( + file_get_contents($answerFile) + ); - $email = new PlancakeEmailParser(file_get_contents($testFile)); + $email = new PlancakeEmailParser(file_get_contents($testFile)); - $this->assertEquals($answers['to'], $email->getTo()); + $this->assertEquals($answers['to'], $email->getTo()); + } } - } - public function testCc() { - foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { + public function testCc() + { + foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { - $answerFile = str_replace('.txt', '.yml', $testFile); - $answers = \Symfony\Component\Yaml\Yaml::parse( - file_get_contents($answerFile) - ); + $answerFile = str_replace('.txt', '.yml', $testFile); + $answers = Yaml::parse( + file_get_contents($answerFile) + ); - $email = new PlancakeEmailParser(file_get_contents($testFile)); + $email = new PlancakeEmailParser(file_get_contents($testFile)); - $this->assertEquals($answers['cc'], $email->getCc()); + $this->assertEquals($answers['cc'], $email->getCc()); + } } - } - public function testBcc() { - foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { + public function testBcc() + { + foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { - $answerFile = str_replace('.txt', '.yml', $testFile); - $answers = \Symfony\Component\Yaml\Yaml::parse( - file_get_contents($answerFile) - ); + $answerFile = str_replace('.txt', '.yml', $testFile); + $answers = Yaml::parse( + file_get_contents($answerFile) + ); - $email = new PlancakeEmailParser(file_get_contents($testFile)); + $email = new PlancakeEmailParser(file_get_contents($testFile)); - $this->assertEquals($answers['bcc'], $email->getBcc()); + $this->assertEquals($answers['bcc'], $email->getBcc()); + } } - } - public function testSender() { - foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { + public function testSender() + { + foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { - $answerFile = str_replace('.txt', '.yml', $testFile); - $answers = \Symfony\Component\Yaml\Yaml::parse( - file_get_contents($answerFile) - ); + $answerFile = str_replace('.txt', '.yml', $testFile); + $answers = Yaml::parse( + file_get_contents($answerFile) + ); - $email = new PlancakeEmailParser(file_get_contents($testFile)); + $email = new PlancakeEmailParser(file_get_contents($testFile)); - $this->assertEquals($answers['sender'], $email->getSender()); + $this->assertEquals($answers['sender'], $email->getSender()); + } } - } - public function testPlainBody() { - foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { + public function testPlainBody() + { + foreach (glob(__DIR__ . '/emails/*.txt') as $testFile) { - $answerFile = str_replace('.txt', '.yml', $testFile); - $answers = \Symfony\Component\Yaml\Yaml::parse( - file_get_contents($answerFile) - ); + $answerFile = str_replace('.txt', '.yml', $testFile); + $answers = Yaml::parse( + file_get_contents($answerFile) + ); - $email = new PlancakeEmailParser(file_get_contents($testFile)); + $email = new PlancakeEmailParser(file_get_contents($testFile)); - $this->assertEquals($answers['plainbody'], $email->getPlainBody()); + $this->assertEquals($answers['plainbody'], $email->getPlainBody()); + } } - } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index dab2002..2d765e2 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,2 +1,2 @@ Date: Sat, 18 Feb 2017 15:12:29 +0100 Subject: [PATCH 10/10] Added newlines to the yaml files --- tests/emails/0.yml | 4 ++-- tests/emails/1.yml | 2 +- tests/emails/2.yml | 2 +- tests/emails/from_ipad_with_attachment.yml | 2 +- tests/emails/subject_on_multiple_lines.yml | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/emails/0.yml b/tests/emails/0.yml index 6a48fdb..c3c9e35 100644 --- a/tests/emails/0.yml +++ b/tests/emails/0.yml @@ -8,9 +8,9 @@ to: cc: [] bcc: [] sender: [] -plainbody: | +plainbody: |- This is a nonesense test-email to check Plancake Mail to Inbox feature. All Polish diacritics included ;-) tag also included for additional tests. It should look like in the picture attached. Best regards - Pawel \ No newline at end of file + Pawel diff --git a/tests/emails/1.yml b/tests/emails/1.yml index 3c85c4a..c2a5c0e 100644 --- a/tests/emails/1.yml +++ b/tests/emails/1.yml @@ -8,4 +8,4 @@ to: cc: [] bcc: [] sender: [] -plainbody: Hope it works! \ No newline at end of file +plainbody: Hope it works! diff --git a/tests/emails/2.yml b/tests/emails/2.yml index 900f869..4b64f00 100644 --- a/tests/emails/2.yml +++ b/tests/emails/2.yml @@ -8,4 +8,4 @@ to: cc: [] bcc: [] sender: [] -plainbody: 'それは作品を期待' \ No newline at end of file +plainbody: 'それは作品を期待' diff --git a/tests/emails/from_ipad_with_attachment.yml b/tests/emails/from_ipad_with_attachment.yml index 1dbd508..cb22614 100644 --- a/tests/emails/from_ipad_with_attachment.yml +++ b/tests/emails/from_ipad_with_attachment.yml @@ -8,4 +8,4 @@ to: cc: [] bcc: [] sender: [] -plainbody: '' \ No newline at end of file +plainbody: '' diff --git a/tests/emails/subject_on_multiple_lines.yml b/tests/emails/subject_on_multiple_lines.yml index e804b54..881196b 100644 --- a/tests/emails/subject_on_multiple_lines.yml +++ b/tests/emails/subject_on_multiple_lines.yml @@ -8,11 +8,11 @@ to: cc: [] bcc: [] sender: [] -plainbody: | +plainbody: |- Da: info@domain.it Oggetto: Grazie!!! - Nome Cognome \ No newline at end of file + Nome Cognome