Skip to content

Commit

Permalink
Merge branch 'hotfix/93-addresslist-semicolon' into develop
Browse files Browse the repository at this point in the history
Forward port #93
  • Loading branch information
weierophinney committed Jun 30, 2020
2 parents 8da3e4a + fbe8139 commit 55fe529
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#93](https://github.com/laminas/laminas-mail/pull/93) fixes an issue whereby an address containing a `;` character was not getting quoted, causing it to be interpreted as an address separator instead of part of the address.

## 2.10.1 - 2020-04-21

Expand Down
6 changes: 4 additions & 2 deletions src/Header/AbstractAddressList.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ public function getFieldValue($format = HeaderInterface::FORMAT_RAW)
$email = $address->getEmail();
$name = $address->getName();

if (! empty($name) && false !== strstr($name, ',')) {
// quote $name if value requires so
if (! empty($name) && (false !== strpos($name, ',') || false !== strpos($name, ';'))) {
// FIXME: what if name contains double quote?
$name = sprintf('"%s"', $name);
}

Expand Down Expand Up @@ -241,7 +243,7 @@ protected static function getComments($value)
* Supposed to be private, protected as a workaround for PHP bug 68194
*
* @param string $value
* @return void
* @return string
*/
protected static function stripComments($value)
{
Expand Down
26 changes: 26 additions & 0 deletions test/Storage/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Exception as GeneralException;
use Laminas\Mail\Exception as MailException;
use Laminas\Mail\Headers;
use Laminas\Mail\Storage;
use Laminas\Mail\Storage\Exception;
use Laminas\Mail\Storage\Message;
Expand Down Expand Up @@ -433,6 +434,31 @@ public function testSpaceInFieldName()
$this->assertEquals(Mime\Decode::splitHeaderField($header, 'baz'), 42);
}

/**
* splitMessage with Headers as input fails to process AddressList with semicolons
*
* @see https://github.com/laminas/laminas-mail/pull/93
*/
public function testHeadersLosesNameQuoting()
{
$headerList = [
'From: "Famous bearings |;" <skf@example.com>',
'Reply-To: "Famous bearings |:" <skf@example.com>',
];

// create Headers object from array
Mime\Decode::splitMessage(implode("\r\n", $headerList), $headers1, $body);
$this->assertInstanceOf(Headers::class, $headers1);
// create Headers object from Headers object
Mime\Decode::splitMessage($headers1, $headers2, $body);
$this->assertInstanceOf(Headers::class, $headers2);

// test that same problem does not happen with Storage\Message internally
$message = new Message(['headers' => $headers2, 'content' => (string)$body]);
$this->assertEquals('"Famous bearings |;" <skf@example.com>', $message->from);
$this->assertEquals('Famous bearings |: <skf@example.com>', $message->replyTo);
}

/**
* @group Laminas-372
*/
Expand Down

0 comments on commit 55fe529

Please sign in to comment.