Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 3ee2a5e

Browse files
committed
fix AddressList toString method to quote semicolon
1 parent ece418b commit 3ee2a5e

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ All notable changes to this project will be documented in this file, in reverse
2222

2323
### Fixed
2424

25-
- Nothing.
25+
- [#230](https://github.com/zendframework/zend-mail/pull/230) Fix AddressList toString method to quote semicolon
2626

2727
## 2.10.0 - 2018-06-07
2828

src/Header/AbstractAddressList.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ public function getFieldValue($format = HeaderInterface::FORMAT_RAW)
134134
$email = $address->getEmail();
135135
$name = $address->getName();
136136

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

@@ -240,7 +242,7 @@ protected static function getComments($value)
240242
* Supposed to be private, protected as a workaround for PHP bug 68194
241243
*
242244
* @param string $value
243-
* @return void
245+
* @return string
244246
*/
245247
protected static function stripComments($value)
246248
{

test/Storage/MessageTest.php

+27
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Exception as GeneralException;
1111
use PHPUnit\Framework\TestCase;
1212
use Zend\Mail\Exception as MailException;
13+
use Zend\Mail\Headers;
1314
use Zend\Mail\Storage;
1415
use Zend\Mail\Storage\Exception;
1516
use Zend\Mail\Storage\Message;
@@ -24,6 +25,7 @@
2425
class MessageTest extends TestCase
2526
{
2627
protected $file;
28+
2729
protected $file2;
2830

2931
public function setUp()
@@ -432,6 +434,31 @@ public function testSpaceInFieldName()
432434
$this->assertEquals(Mime\Decode::splitHeaderField($header, 'baz'), 42);
433435
}
434436

437+
/**
438+
* splitMessage with Headers as input fails to process AddressList with semicolons
439+
*
440+
* @see https://github.com/zendframework/zend-mail/pull/230
441+
*/
442+
public function testHeadersLosesNameQuoting()
443+
{
444+
$headerList = [
445+
'From: "Famous bearings |;" <[email protected]>',
446+
'Reply-To: "Famous bearings |:" <[email protected]>',
447+
];
448+
449+
// create Headers object from array
450+
Mime\Decode::splitMessage(implode("\r\n", $headerList), $headers1, $body);
451+
$this->assertInstanceOf(Headers::class, $headers1);
452+
// create Headers object from Headers object
453+
Mime\Decode::splitMessage($headers1, $headers2, $body);
454+
$this->assertInstanceOf(Headers::class, $headers2);
455+
456+
// test that same problem does not happen with Storage\Message internally
457+
$message = new Message(['headers' => $headers2, 'content' => (string)$body]);
458+
$this->assertEquals('"Famous bearings |;" <[email protected]>', $message->from);
459+
$this->assertEquals('Famous bearings |: <[email protected]>', $message->replyTo);
460+
}
461+
435462
/**
436463
* @group ZF2-372
437464
*/

0 commit comments

Comments
 (0)