diff --git a/src/Header/AbstractAddressList.php b/src/Header/AbstractAddressList.php index 97cbd5f1..6f801933 100644 --- a/src/Header/AbstractAddressList.php +++ b/src/Header/AbstractAddressList.php @@ -43,7 +43,9 @@ public static function fromString($headerLine) { $decodedLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8'); // split into name/value - list($fieldName, $fieldValue) = explode(': ', $decodedLine, 2); + list($fieldName, $fieldValue) = explode(':', $decodedLine, 2); + $fieldName = trim($fieldName); + $fieldValue = trim($fieldValue); if (strtolower($fieldName) !== static::$type) { throw new Exception\InvalidArgumentException(sprintf( diff --git a/test/Header/AddressListHeaderTest.php b/test/Header/AddressListHeaderTest.php index 45837f9b..02f501e8 100644 --- a/test/Header/AddressListHeaderTest.php +++ b/test/Header/AddressListHeaderTest.php @@ -105,11 +105,11 @@ public function getStringHeaders() { $value = $this->getExpectedFieldValue(); return array( - array('Cc: ' . $value, 'Zend\Mail\Header\Cc'), - array('Bcc: ' . $value, 'Zend\Mail\Header\Bcc'), - array('From: ' . $value, 'Zend\Mail\Header\From'), - array('Reply-To: ' . $value, 'Zend\Mail\Header\ReplyTo'), - array('To: ' . $value, 'Zend\Mail\Header\To'), + 'cc' => array('Cc: ' . $value, 'Zend\Mail\Header\Cc'), + 'bcc' => array('Bcc: ' . $value, 'Zend\Mail\Header\Bcc'), + 'from' => array('From: ' . $value, 'Zend\Mail\Header\From'), + 'reply-to' => array('Reply-To: ' . $value, 'Zend\Mail\Header\ReplyTo'), + 'to' => array('To: ' . $value, 'Zend\Mail\Header\To'), ); } @@ -133,4 +133,38 @@ public function testDeserializationFromString($headerLine, $class) $address = $list->get('fw-announce@lists.zend.com'); $this->assertEquals('ZF Announce List', $address->getName()); } + + public function getStringHeadersWithNoWhitespaceSeparator() + { + $value = $this->getExpectedFieldValue(); + return array( + 'cc' => array('Cc:' . $value, 'Zend\Mail\Header\Cc'), + 'bcc' => array('Bcc:' . $value, 'Zend\Mail\Header\Bcc'), + 'from' => array('From:' . $value, 'Zend\Mail\Header\From'), + 'reply-to' => array('Reply-To:' . $value, 'Zend\Mail\Header\ReplyTo'), + 'to' => array('To:' . $value, 'Zend\Mail\Header\To'), + ); + } + + /** + * @group 3789 + * @dataProvider getStringHeadersWithNoWhitespaceSeparator + */ + public function testAllowsNoWhitespaceBetweenHeaderAndValue($headerLine, $class) + { + $callback = sprintf('%s::fromString', $class); + $header = call_user_func($callback, $headerLine); + $this->assertInstanceOf($class, $header); + $list = $header->getAddressList(); + $this->assertEquals(3, count($list)); + $this->assertTrue($list->has('zf-devteam@zend.com')); + $this->assertTrue($list->has('zf-contributors@lists.zend.com')); + $this->assertTrue($list->has('fw-announce@lists.zend.com')); + $address = $list->get('zf-devteam@zend.com'); + $this->assertEquals('ZF DevTeam', $address->getName()); + $address = $list->get('zf-contributors@lists.zend.com'); + $this->assertNull($address->getName()); + $address = $list->get('fw-announce@lists.zend.com'); + $this->assertEquals('ZF Announce List', $address->getName()); + } }