From:             tokul at users dot sourceforge dot net
Operating system: Linux Debian Etch
PHP version:      5.2CVS-2008-03-30 (snap)
PHP Bug Type:     mbstring related
Bug description:  mb_encode_mimeheader incorrectly folds iso-2022 text

Description:
------------
mb_encode_mimeheader incorrectly folds iso-2022 texts. rfc 2047 chapter 3
second paragraph says that folded string must be reverted to ASCII. Code
just splits ISO-2022 string without adding appropriate escapes.

Code works as expected only when mbstring.internal_encoding is set to
correct value. This dependency of mb_encode_mimeheader() is not documented
and catches all users that are not used to mb_encode_mimeheader() quirks.

Reproduce code:
---------------
/** See
http://etext.lib.virginia.edu/japanese/hyakunin/frames/hyakuframes.html */
$string = "\xe7\xa7\x8b\xe3\x81\xae\xe7\x94\xb0\xe3\x81\xae\x20"
 ."\xe3\x81\x8b\xe3\x82\x8a\xe3\x81\xbb\xe3\x81\xae\xe5\xba\xb5"
 ."\xe3\x81\xae\x20\xe8\x8b\xab\xe3\x82\x92\xe3\x81\x82"
 ."\xe3\x82\x89\xe3\x81\xbf\x20\x20\xe3\x82\x8f\xe3\x81\x8c"
 ."\xe8\xa1\xa3\xe6\x89\x8b\xe3\x81\xaf\x20\xe9\x9c\xb2"
 ."\xe3\x81\xab\xe3\x81\xac\xe3\x82\x8c\xe3\x81\xa4\xe3\x81\xa4";

$string_iso2022 = mb_convert_encoding($string,'iso-2022-jp','utf-8');
echo mb_encode_mimeheader($string_iso2022,'iso-2022-jp','b');

Expected result:
----------------
=?ISO-2022-JP?B?GyRCPSkkTkVEJE4bKEIgGyRCJCskaiRbJE4wQyROGyhCIBskQkZRGyhC?=
=?ISO-2022-JP?B?GyRCJHIkIiRpJF8bKEIgIBskQiRvJCwwYTxqJE8bKEIgGyRCTyobKEI=?=
=?ISO-2022-JP?B?GyRCJEskTCRsJEQkRBsoQg==?=

Actual result:
--------------
=?ISO-2022-JP?B?GyRCPSkkTkVEJE4bKEIgGyRCJCskaiRbJE4wQyROGyhCIBskQkZRJHIk?=

=?ISO-2022-JP?B?IiRpJF8bKEIgIBskQiRvJCwwYTxqJE8bKEIgGyRCTyokSyRMJGwkRCRE?=
 =?ISO-2022-JP?B?GyhC?=

-- 
Edit bug report at http://bugs.php.net/?id=44570&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44570&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44570&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44570&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=44570&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=44570&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=44570&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=44570&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=44570&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=44570&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=44570&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=44570&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=44570&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=44570&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=44570&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=44570&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=44570&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=44570&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44570&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=44570&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=44570&r=mysqlcfg

Reply via email to