Issues

ZF-3588: Incorrect encoding of unicode subjects

Issue Type: Bug Created: 2008-07-06T08:15:57.000+0000 Last Updated: 2009-05-04T05:28:29.000+0000 Status: Resolved Fix version(s): Reporter: Eran Galperin (erangalp) Assignee: Nico Edtinger (nico) Tags: - Zend_Mail

Related issues: - ZF-1688

Attachments:

Description

When using Zend_Mail with utf-8 encoding and hebrew characters, the subject is incorrectly encoded causing artifacts to appear. I've tracked this to the protected method _encodeHeader(), line 393 in Zend_Mail:

<pre class="highlight">
protected function _encodeHeader($value)
    {
      if (Zend_Mime::isPrintable($value)) {
          return $value;
      } else {
          $quotedValue = Zend_Mime::encodeQuotedPrintable($value);
          $quotedValue = str_replace(array('?', ' '), array('=3F', '=20'), $quotedValue);
          return '=?' . $this->_charset . '?Q?' . $quotedValue . '?=';
      }
    }

Replacing the quoting method to encodeBase64() of Zend_Mime seems to fix the issue. Meaning:

<pre class="highlight">
protected function _encodeHeader($value)
    {
      if (Zend_Mime::isPrintable($value)) {
          return $value;
      } else {
            return '=?' . $this->_charset . '?B?' . Zend_Mime::encodeBase64($value) . '?=';
      }
    }

Will return a correctly formatted utf-8 subject. I'm not an expert on Mime so I can't tell if this is the best solution. However it should be fixed to correctly format utf-8 subjects

Comments

Posted by S├ębastien Gallet (haijin) on 2008-08-01T00:42:29.000+0000

That issue is also present in 1.5.3 and 1.6.0 rc1.

Here is another fix without using the base64 encoding. It's not perfect either but it corrects the issue.

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

Posted by Levan Cheishvili (levan) on 2009-05-04T05:28:27.000+0000

It is still not working with some hebrew letters / or combinations of letters in ZF 1.7.1. I am using Zend_Mail from ZF 1.7.1. I had to apply the above given patch, and now it is working. When are you going to update ZF with this patch?

Have you found an issue?

See the Overview section for more details.

Copyright

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

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

Contacts