Skip to content

Commit

Permalink
Issue with parsing quoted address names #224
Browse files Browse the repository at this point in the history
  • Loading branch information
zbateson committed Sep 6, 2023
1 parent 7ef9809 commit 9f76ca7
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/MailMimeParser/Header/AddressHeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ public function testSingleAddressWithEscapedToken() : void
$this->assertEquals('[email protected]', $addresses[0]->getValue());
}

public function testSingleAddressWithComplexEscapedTokensAndComma() : void
{
$header = new AddressHeader($this->consumerService, 'From', '"\'\"\\\\\"Test, Recipient\\\\\"\"\'" <[email protected]>');
$this->assertEquals('[email protected]', $header->getValue());
$this->assertEquals('\'"\"Test, Recipient\""\'', $header->getPersonName());
$addresses = $header->getParts();
$this->assertCount(1, $addresses);
$this->assertEquals('\'"\"Test, Recipient\""\'', $addresses[0]->getName());
$this->assertEquals('[email protected]', $addresses[0]->getValue());
}

public function testMultipleAddresses() : void
{
$header = new AddressHeader(
Expand Down
19 changes: 19 additions & 0 deletions tests/MailMimeParser/Header/Consumer/QuotedStringConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
34 changes: 34 additions & 0 deletions tests/MailMimeParser/IntegrationTests/EmailFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down Expand Up @@ -1747,6 +1759,28 @@ public function testParseEmailGitHub_115() : void
]);
}

public function testParseEmailGitHub_224() : void
{
$this->runEmailTest('github-224', [
'From' => [
'name' => 'Doug Sauder',
'email' => '[email protected]'
],
'To' => [
[
'name' => '\'Test Recipient\'',
'email' => '"success1"@simulator.amazonses.com'
],
[
'name' => '\'"\"Test, Recipient\""\'',
'email' => '[email protected]'
],
],
'Subject' => 'Die Hasen und die Frösche (Microsoft Outlook 00)',
'text' => 'HasenundFrosche.txt',
]);
}

public function testRewriteEmailContentm0001() : void
{
$handle = \fopen($this->messageDir . '/m0001.txt', 'r');
Expand Down
32 changes: 32 additions & 0 deletions tests/_data/emails/github-224.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
From: "Doug Sauder" <[email protected]>
To: "'Test Recipient'" <"success1"@simulator.amazonses.com>, "'\"\\\"Test, Recipient\\\"\"'" <[email protected]>,
Subject: Die Hasen und die Fr�sche (Microsoft Outlook 00)
Date: Wed, 17 May 2000 19:08:29 -0400
Message-ID: <[email protected]>
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."

0 comments on commit 9f76ca7

Please sign in to comment.