diff --git a/src/Message.php b/src/Message.php index c0f151a1..54fe95f5 100644 --- a/src/Message.php +++ b/src/Message.php @@ -103,7 +103,8 @@ public function getHeaders() { if (null === $this->headers) { $this->setHeaders(new Headers()); - $this->headers->addHeaderLine('Date', date('r')); + $date = Header\Date::fromString('Date: ' . date('r')); + $this->headers->addHeader($date); } return $this->headers; } diff --git a/test/MessageTest.php b/test/MessageTest.php index 2cc7e1a2..c40eebde 100644 --- a/test/MessageTest.php +++ b/test/MessageTest.php @@ -632,4 +632,19 @@ public function testSettingNonAsciiEncodingForcesMimeEncodingOfSomeHeaders() $expected = 'Subject: =?UTF-8?Q?This=20is=20a=20subject?='; $this->assertContains($expected, $test); } + + /** + * @group ZF2-507 + */ + public function testDefaultDateHeaderEncodingIsAlwaysAscii() + { + $this->message->setEncoding('utf-8'); + $headers = $this->message->getHeaders(); + $header = $headers->get('date'); + $date = date('r'); + $date = substr($date, 0, 16); + $test = $header->getFieldValue(); + $test = substr($test, 0, 16); + $this->assertEquals($date, $test); + } }