Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.8.9

Bug #17311 Wrong UTF-8 Subject depending on linebreak
Submitted: 2010-04-13 20:05 UTC
From: reitzmichnicht Assigned: alec
Status: Closed Package: Mail_Mime (version 1.7.0)
PHP Version: 5.2.6 OS: Linux Debian Lenny
Roadmaps: 1.8.0    

 [2010-04-13 20:05 UTC] reitzmichnicht (Michael Reitz)
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?=


 [2010-04-14 06:49 UTC] alec (Aleksander Machniak)
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-17 14:50 UTC] jemguess (Jem Guess)
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-06-13 12:10 UTC] dune2 (Stanimir Dzharkalov)
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; }
 [2010-06-24 13:55 UTC] jszczypk (Janusz Szczypka)
For PHP 5 we can use icon_mime_encode. I have check that it works ok with breaking UTF-8 string.
 [2010-07-01 10:59 UTC] alec (Aleksander Machniak)
iconv_mime_encode has got some bugs eg. So we'll probably use some custom code with mbstring functions, that are working also with PHP4.
 [2010-07-06 09:43 UTC] alec (Aleksander Machniak)
-Status: Open +Status: Closed -Assigned To: +Assigned To: alec -Roadmap Versions: +Roadmap Versions: 1.8.0
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. Implemented using mbstring functions.