Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Critical
-
Resolution: Duplicate
-
Affects Version/s: 1.5.2
-
Fix Version/s: None
-
Component/s: Zend_Mail
-
Labels:None
Description
With the following code, I wish to send an e-mail with Chinese in the subject:
// ZendFramework-1.5.2 $mail = new Zend_Mail('UTF-8'); $mail->setFrom('info@example.org'); $mail->addTo('sam@example.org'); $mail->setSubject('机器视觉组件生产商'); $mail->setBodyText('机器视觉组件生产商 机器视觉组件生产商'); $mail->send();
However, the subject of the sent e-mail is garbled and displayed incorrectly in e-mail client (Thunderbird).
"Subject: =?UTF-8?Q?=E6=9C=BA=E5=99=A8=E8=A7=86=E8=A7=89=E7=BB=84=E4=BB=B6=E7=94=9F=E4=BA=A7= =E5=95=86?="
See full e-mail, which is sent, is below:
From - Sat Aug 9 14:17:45 2008 X-Account-Key: account2 X-UIDL: BNb"!%58"!UQ]!!J>'"! X-Mozilla-Status: 0001 X-Mozilla-Status2: 00000000 Return-Path: <xxx@xxx.org> X-Original-To: yyy@xxx.org Delivered-To: yyy@xxx.org Received: from xxx.xxx.org (localhost [127.0.0.1]) by localhost (Postfix) with ESMTP id B6B67501847 for <yyy@xxx.org>; Sat, 9 Aug 2008 14:14:08 +0200 (CEST) To: <yyy@xxx.org> Subject: =?UTF-8?Q?=E6=9C=BA=E5=99=A8=E8=A7=86=E8=A7=89=E7=BB=84=E4=BB=B6=E7=94=9F=E4=BA=A7= =E5=95=86?= From: "" <info@example.org> Date: Sat, 09 Aug 2008 14:27:55 +0200 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <20080809122755.C0CAB8C056@xxx.xxx.org> =E6=9C=BA=E5=99=A8=E8=A7=86=E8=A7=89=E7=BB=84=E4=BB=B6=E7=94=9F=E4=BA=A7=E5= =95=86 =E6=9C=BA=E5=99=A8=E8=A7=86=E8=A7=89=E7=BB=84=E4=BB=B6=E7=94=9F=E4= =BA=A7=E5=95=86
It seems that the method Zend_Mail::_encodeHeader() is causing the problem.
E-Mail with a Chinese subject is sent correctly, when the following code is used for the method:
protected function _encodeHeader($value) { if (Zend_Mime::isPrintable($value)) { return $value; } else { return '=?' . $this->_charset . '?B?' . base64_encode($value) . '?='; } }
Jacky Chen posted this solution on Fri, 28 Dec 2007 17:21:26 -0800 at:
http://www.mail-archive.com/fw-general@lists.zend.com/msg09005.html
Can his version of Zend_Mail::_encodeHeader() be used to update the official version?
In the meantime, I am subclassing Zend_Mail, overloading Zend_Mail::_encodeHeader() with his version, as I need to send e-mail with Chinese subjects and also From and To addresses - Zend_Mail::_encodeHeader() is used in multiple methods.
Thank you for your kind consideration of this change.
Jonathan Maron
Attachments
Issue Links
| This issue duplicates: | ||||
| ZF-1688 | Long header lines containing non-printable characters are corrupted |
|
|
|
| This issue is related to: | ||||
| ZF-3641 | Zend_Mail: Wrong MIME header encoding |
|
|
|
| ZF-3865 | Zend_Mail::_encodeHeader() encode incorrect |
|
|
|
| ZF-2532 | Wrong encoded of the subject, if the subject is longer than Zend_Mime::LINELENGTH. |
|
|
|
| ZF-3588 | Incorrect encoding of unicode subjects |
|
|
|
| ZF-1950 | Correct method of encodeHeader "From" for Multibyte name senders |
|
|
|
| ZF-1945 | Zend_Mail qp-encodes linefeeds |
|
|
|
| ZF-2043 | Unappealing From header |
|
|
|
This solution would work only for short headers, because the RFC does not allow the encoded words in the headers to be longer than 75 characters. The string has to be split to avoid problems with multibyte characters and therefore has to be split between those characters. I had the same problem and now I have a solution which fixes it for utf-8 string (other charsets later).
I will post a patch in the next few days. It should also close a few other tickets related to Zend_Mail/Zend_Mime.