Zend Framework

Incorrect encoding of unicode subjects

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: 1.5.2
  • Fix Version/s: None
  • Component/s: Zend_Mail
  • Labels:
    None

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:

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:

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

Issue Links

Activity

Hide
Sébastien Gallet added a comment -

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.

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 . '?=';
      }
    }
Show
Sébastien Gallet added a comment - 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.
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 . '?=';
      }
    }
Hide
Levan Cheishvili added a comment -

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?

Show
Levan Cheishvili added a comment - 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?

People

Vote (4)
Watch (5)

Dates

  • Created:
    Updated:
    Resolved: