Bug #17311 [Com]: Wrong UTF-8 Subject depending on linebreak
| From: | dune2 | Date: | Sun, 13 Jun 2010 13:17:00 +0000 |
| Subject: | Bug #17311 [Com]: Wrong UTF-8 Subject depending on linebreak | ||
| References: | 1 | Groups: | php.pear.bugs |
| Request: | Send a blank email to pear-bugs+get-3932@lists.php.net to get a copy of this message | ||
Edit report at http://pear.php.net/bugs/bug.php?id=17311&edit=1
ID: 17311
Comment by: dune2
Reported By: s dot dzharkalov at clickdot dot bg
Summary: Wrong UTF-8 Subject depending on linebreak
Status: Open
Type: Bug
Package: Mail_Mime
Operating System: Linux Debian Lenny
Package Version: 1.7.0
PHP Version: 5.2.6
New Comment:
Jem,
base64 does not fix the problem on itself, you were lucky enough no to
hit the linebreak when using base64.
Here is a simple fix for the base64 part, avoiding splitting the
characters on linebreak.
Someone can use it to fix the QP part also.
File: mimePart.php
Function: encodeHeaderValue
replace the
if ($encoding == 'base64') {
....
}
with the following
if ($encoding == 'base64') {
// Generate the header using the specified params and
dynamicly
// determine the maximum length of such strings.
// 75 is the value specified in the RFC.
$prefix = '=?' . $charset . '?B?';
$suffix = '?=';
$maxLength = 75 - strlen($prefix . $suffix) - 2;
$maxLength1stLine = $maxLength - $prefix_len;
// We can cut base4 every 4 characters, so the real max
// we can get must be rounded down.
$maxLength = $maxLength - ($maxLength % 4);
$maxLength1stLine = $maxLength1stLine - ($maxLength1stLine
% 4);
$cutpoint = $maxLength1stLine;
$value_out = $value;
$output = '';
$start = 0;
for ($i=1; $i<=mb_strlen($value, $charset); $i++) {
$current_value = base64_encode(mb_substr($value, $start, $i-$start,
$charset));
if (strlen($current_value) >= $cutpoint || $i == mb_strlen($value,
$charset)) {
if (strlen($current_value) == $cutpoint || $i == mb_strlen($value,
$charset)) {
$part = $current_value;
$start = $i;
} else {
$part = $previous_value;
$start = $i-1;
}
if ($output) {
$output .= $eol . ' ';
}
$output .= $prefix . $part . $suffix;
$cutpoint = $maxLength;
}
$previous_value == $current_value;
}
$value = $output;
}
Previous Comments:
------------------------------------------------------------------------
[2010-04-17 15:50:25] jemguess
I have adjusted 'head_encoding' for using UTF-8 Asian Text.It's working
for me. Hope it works for you.
// What encoding to use for the headers
// Options: quoted-printable or base64
'head_encoding' => 'base64'
------------------------------------------------------------------------
[2010-04-14 07:49:02] alec
Looks you're right, as for RFC2047: "Each 'encoded-word' MUST represent
an integral number of characters. A multi-octet character may not be
split across adjacent 'encoded-word's." This will require use of
mbstring module.
------------------------------------------------------------------------
[2010-04-13 21:05:07] reitzmichnicht
Description:
------------
Normally the UTF-8 subject is correct, but when the utf-8 char occurs
exactly on the linebreak, the subject is destroyed like this:
Update: Microsoft Windows-Tool zum Entfernen b?
Test script:
---------------
$mime = new Mail_mime();
$header['Subject'] = "Update: Microsoft Windows-Tool zum Entfernen
bösartiger Software 3.6";
$mail_object =& Mail::factory('mail');
$body = $mime->get(array(
"html_charset" => "UTF-8",
"text_charset" => "UTF-8",
"head_charset" => "UTF-8"
));
$header = $mime->headers($header);
$mail_object->send($to , $header, $body);
Expected result:
----------------
Subject:
=?UTF-8?Q?Update=3A_Microsoft_Windows-Tool_zum_Entfernen_b=C3=B6?=
=?UTF-8?Q?sartiger_Software_3=2E6?=
Actual result:
--------------
Subject:
=?UTF-8?Q?Update=3A_Microsoft_Windows-Tool_zum_Entfernen_b=C3?=
=?UTF-8?Q?=B6sartiger_Software_3=2E6?=
------------------------------------------------------------------------
--
Edit this bug report at http://pear.php.net/bugs/bug.php?id=17311&edit=1