ZF2-372: [Mail] addHeaders() throws exception on invalid headers


Invalid headers should ideally be ignored (discuss?), previous version of Zend would not throw an exception when a header such as the first one shown below was set. This header gets set by Postfix.

Array ( [from thu jun 21 16] => 42:48 2012 [return-path] => [x-original-to] => [delivered-to] => [message-id] => [date] => Thu, 21 Jun 2012 16:40:28 +0100 [from] => Test Person [user-agent] => Mozilla/5.0 ( Windows NT 6.1; WOW64; rv:12.0 ) Gecko/20120428 Thunderbird/12.0.1 [mime-version] => 1.0 [to] => [subject] => Test [content-type] => text/plain; charset=ISO-8859-1; format=flowed [content-transfer-encoding] => 7bit )


Error thrown is;

library/Zend/Mail/Header/GenericHeader.php:102 - Header name must start with a letter, and consist of only letters, numbers and dashes

After discussion on IRC with DASPRiD, suggestion was to have an option 'Ignore invalid headers'

Invalid headers should throw an exception. Unknown headers should be implemented with GenericHeader

For me [from thu jun 21 16] it's not a From invalid header, its a header called "from thu jun 21 16"

Our use case is a email being received from a pipe where custom headers such as the above may be inserted by the MTA. We don't want to have to pre-process the headers before calling addHeaders().

How do you propose this is implemented within GenericHeader, considering how the header "[from thu jun 21 16]" is so specific to the environment?

I checked the standard again and the first header can't be a valid field name because has spaces.

I think that, in your case, ignore the first line from the input was enough.

Anyway I opened this PR

Replacement Pull request created

Fixed in latest master (162c087bf203942a53498fc82539d0b26356ebee) from PR1878