diff --git a/tests/MailMimeParser/Header/AddressHeaderTest.php b/tests/MailMimeParser/Header/AddressHeaderTest.php index 0e95f24d..b46954ad 100644 --- a/tests/MailMimeParser/Header/AddressHeaderTest.php +++ b/tests/MailMimeParser/Header/AddressHeaderTest.php @@ -103,6 +103,17 @@ public function testSingleAddressWithEscapedToken() : void $this->assertEquals('koolaid@dontdrinkit.com', $addresses[0]->getValue()); } + public function testSingleAddressWithComplexEscapedTokensAndComma() : void + { + $header = new AddressHeader($this->consumerService, 'From', '"\'\"\\\\\"Test, Recipient\\\\\"\"\'" '); + $this->assertEquals('success5@simulator.amazonses.com', $header->getValue()); + $this->assertEquals('\'"\"Test, Recipient\""\'', $header->getPersonName()); + $addresses = $header->getParts(); + $this->assertCount(1, $addresses); + $this->assertEquals('\'"\"Test, Recipient\""\'', $addresses[0]->getName()); + $this->assertEquals('success5@simulator.amazonses.com', $addresses[0]->getValue()); + } + public function testMultipleAddresses() : void { $header = new AddressHeader( diff --git a/tests/MailMimeParser/Header/Consumer/QuotedStringConsumerTest.php b/tests/MailMimeParser/Header/Consumer/QuotedStringConsumerTest.php index 523b1f94..8f12005c 100644 --- a/tests/MailMimeParser/Header/Consumer/QuotedStringConsumerTest.php +++ b/tests/MailMimeParser/Header/Consumer/QuotedStringConsumerTest.php @@ -47,4 +47,23 @@ public function testConsumeTokens() : void $this->assertCount(1, $ret); $this->assertEquals('Will end at ', $ret[0]); } + + public function testEscapedTokens() : void + { + $value = 'Will not end at \" quote'; + + $ret = $this->quotedStringConsumer->__invoke($value); + $this->assertNotEmpty($ret); + $this->assertCount(1, $ret); + $this->assertEquals('Will not end at " quote', $ret[0]); + } + + public function testMoreEscapedTokens() : void + { + $value = 'Will not end at \\\\\" quote'; + $ret = $this->quotedStringConsumer->__invoke($value); + $this->assertNotEmpty($ret); + $this->assertCount(1, $ret); + $this->assertEquals('Will not end at \" quote', $ret[0]->getValue()); + } } diff --git a/tests/MailMimeParser/IntegrationTests/EmailFunctionalTest.php b/tests/MailMimeParser/IntegrationTests/EmailFunctionalTest.php index b4c7a437..ffe8e7d7 100644 --- a/tests/MailMimeParser/IntegrationTests/EmailFunctionalTest.php +++ b/tests/MailMimeParser/IntegrationTests/EmailFunctionalTest.php @@ -84,6 +84,18 @@ private function runEmailTestForMessage($message, array $props, $failMessage) : $this->assertEquals($props['To']['name'], $to->getPersonName(), $failMessage); } $this->assertEquals($props['To']['email'], $to->getValue(), $failMessage); + } elseif (isset($props['To']) && is_array($props['To']) && isset($props['To'][0]) && isset($props['To'][0]['email'])) { + $to = $message->getHeader('To'); + $addresses = $to->getParts(); + $this->assertCount(count($props['To']), $addresses); + for ($c = 0; $c < count($props['To']); ++$c) { + $exp = $props['To'][$c]; + $act = $addresses[$c]; + if ($exp['name']) { + $this->assertEquals($exp['name'], $act->getName()); + } + $this->assertEquals($exp['email'], $act->getValue()); + } } if (isset($props['From']['email'])) { @@ -1747,6 +1759,28 @@ public function testParseEmailGitHub_115() : void ]); } + public function testParseEmailGitHub_224() : void + { + $this->runEmailTest('github-224', [ + 'From' => [ + 'name' => 'Doug Sauder', + 'email' => 'doug@example.com' + ], + 'To' => [ + [ + 'name' => '\'Test Recipient\'', + 'email' => '"success1"@simulator.amazonses.com' + ], + [ + 'name' => '\'"\"Test, Recipient\""\'', + 'email' => 'success5@simulator.amazonses.com' + ], + ], + 'Subject' => 'Die Hasen und die Frösche (Microsoft Outlook 00)', + 'text' => 'HasenundFrosche.txt', + ]); + } + public function testRewriteEmailContentm0001() : void { $handle = \fopen($this->messageDir . '/m0001.txt', 'r'); diff --git a/tests/_data/emails/github-224.txt b/tests/_data/emails/github-224.txt new file mode 100644 index 00000000..6a085dfe --- /dev/null +++ b/tests/_data/emails/github-224.txt @@ -0,0 +1,32 @@ +From: "Doug Sauder" +To: "'Test Recipient'" <"success1"@simulator.amazonses.com>, "'\"\\\"Test, Recipient\\\"\"'" , +Subject: Die Hasen und die Frösche (Microsoft Outlook 00) +Date: Wed, 17 May 2000 19:08:29 -0400 +Message-ID: +MIME-Version: 1.0 +contenttype: invalid/application +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 8bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) +Importance: Normal +X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 + +Die Hasen und die Frösche + +Die Hasen klagten einst über ihre mißliche Lage; "wir leben", sprach ein +Redner, "in steter Furcht vor Menschen und Tieren, eine Beute der Hunde, der +Adler, ja fast aller Raubtiere! Unsere stete Angst ist ärger als der Tod +selbst. Auf, laßt uns ein für allemal sterben." + +In einem nahen Teich wollten sie sich nun ersäufen; sie eilten ihm zu; +allein das außerordentliche Getöse und ihre wunderbare Gestalt erschreckte +eine Menge Frösche, die am Ufer saßen, so sehr, daß sie aufs schnellste +untertauchten. + +"Halt", rief nun eben dieser Sprecher, "wir wollen das Ersäufen noch ein +wenig aufschieben, denn auch uns fürchten, wie ihr seht, einige Tiere, +welche also wohl noch unglücklicher sein müssen als wir." +