ZF-6069: Wrong header encoding

Issue Type: Bug Created: 2009-03-19T10:51:43.000+0000 Last Updated: 2009-09-18T02:37:30.000+0000 Status: Resolved Fix version(s): Reporter: Christian (cptbrauser) Assignee: Benjamin Eberlei (beberlei) Tags: - Zend_Mail

Related issues: Attachments:


Zend_Mail::_encodeHeader() does not work correctly for some combinations of charset and string length.

As described in RFC 2047: An 'encoded-word' may not be more than 75 characters long, including 'charset', 'encoding', 'encoded-text', and delimiters. If it is desirable to encode more text than will fit in an 'encoded-word' of 75 characters, multiple 'encoded-word's (separated by CRLF SPACE) may be used.

This CRLF SPACE was added only for the message itself, but not including meta prefix and postfix (charset, encoding) as it should. Try to send a mail using charset="utf-8" (1. constructor parameter for Zend_Mail) and a subject like this:

Neue Nachricht im Stat@las: RE: RE: Nachrichten im Postausgang löschen

You'll get

<pre class="highlight">
=?utf-8?Q?Neue=20Nachricht=20im=20Stat@las:=20RE=5F=20RE=5F=20Nachrichten=20im=20Postausgang=20l=C3=B6sche= n?=

As you can see, there's a whitespace at the end of this string. This is in fact a CRLF created by Zend_Mime::encodeQuotedPrintable($value) in _encodeHeader() after exactly 76 chars:

Neue Nachricht im Stat@las: RE: RE: Nachrichten im Postausgang l=C3=B6sche= n

The following bugfix works, but I think it's not that beautiful:

<pre class="highlight">
    protected function _encodeHeader($value)
        if (Zend_Mime::isPrintable($value)) {
            return $value;
        } else {
            $quotedValue  = Zend_Mime::encodeQuotedPrintable($value, 9999); // do NOT add CRLF now
            $quotedValue  = str_replace(array('?', ' ', '_'), array('=3F', '=20', '=5F'), $quotedValue);
            $encodedValue = '=?' . $this->_charset . '?Q?' . $quotedValue . '?=';
            $encodedValue = wordwrap($encodedValue); // add CRLF now
            return $encodedValue;

(sorry, missing new lines here in code, no idea how to fix that)

wordwrap() is used instead of chunk_split(), because it may destroy an entity occurence at position 76 of the string.

Edit: See a discussion here (German):


Posted by old of Satoru Yoshida ( on 2009-04-04T03:25:48.000+0000

add code tag in the discription

Posted by Benjamin Eberlei (beberlei) on 2009-06-12T13:22:01.000+0000

Which version was used to get this bug?

It seems it is not 1.8, which includes a bugfix for these problems. Can you verify this problem still occurs?

Posted by Benjamin Eberlei (beberlei) on 2009-09-18T02:37:27.000+0000

Veryfing the code in the bug comment I saw that this snippet is from a version < 1.8 of Zend Framework, however the Mail HEader encoding Bug was fixed with 1.8.2 or something, so please upgrade to that specific version and re-open the issue if this is still occurring.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.