ZF2-507: Invalid Date header set in mail Message

Description

Here is the code from Zend\Mail\Message :

 
public function getHeaders()
{
        if (null === $this->headers) {
            $this->setHeaders(new Headers());
            $this->headers->addHeaderLine('Date', date('r'));
        }
        return $this->headers;
}

The Date header is added as a GenericHeader. When using UTF-8 encoding, the date header will be converted. This will break the message because date header MUST be in ASCII.

This can be resolved by setting a proper Zend\Mail\Header\Date instance when creating the message headers.

Here is a test case to reproduce the bug :


    /**
     * @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);
    }

Comments

Merged to release, and will be merged to 2.0.1 and master branches shortly.