php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63266 imap_utf8 returns bad utf8 string
Submitted: 2012-10-12 04:43 UTC Modified: -
Votes:4
Avg. Score:4.0 ± 1.7
Reproduced:3 of 4 (75.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: Development at JivanAmara dot net Assigned:
Status: Open Package: IMAP related
PHP Version: Irrelevant OS: Linux (Ubuntu / Redhat)
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-10-12 04:43 UTC] Development at JivanAmara dot net
Description:
------------
MIME 'from' header "=?gb18030?B?zfW+/L3c?=" is not converted to utf-8.  Instead 
the gb18030 encoding is returned.

I expect in versions < 5.4.0 a warning indicating unsupported character set and 
an empty string returned.

I expect in versions >= 5.4.0 a correctly converted utf-8 encoding of the text.

Behavior has been checked with versions 5.2.9, 5.3.?, 5.4.6


Test script:
---------------
<?php
$from = '=?gb18030?B?zfW+/L3c?=';

$from_imap_utf8 = imap_utf8($from);
echo "imap_utf8: $from_imap_utf8", "\n";

$from_obj = imap_mime_header_decode($from);
$charset = $from_obj[0]->charset;
$text = $from_obj[0]->text;
$text_utf8 = mb_convert_encoding($text, 'UTF-8', $charset);
echo "decode/convert: $text_utf8", "\n";

echo "Correct conversion: ", $from_imap_utf8 == $text_utf8 ? "Yes" : "No", "\n";
?>


Expected result:
----------------
For versions >= 5.4.0 I expect the script to output:
 imap_utf8: 王军杰
 decode/convert: 王军杰
 Correct conversion: Yes

For versions < 5.4.0 I expect the script to output:
 PHP Warning:  imap_utf8(): Illegal character encoding specified in <script name> 
on line 4
 imap_utf8: 
 PHP Warning:  mb_convert_encoding(): Illegal character encoding specified in 
<script name> on line 10
 decode/convert: 
 Correct conversion: Yes


Actual result:
--------------
For versions >= 5.4.0 I see:
 imap_utf8: �����
 decode/convert: 王军杰
 Correct conversion: No

For versions < 5.4.0 I see:
 imap_utf8: �����
 PHP Warning:  mb_convert_encoding(): Illegal character encoding specified in 
/home/netcloud/jivan.amara/encoding.php on line 20
 decode/convert: 
 Correct conversion: No


Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 05:01:25 2019 UTC