Bug->Doc #63266 [Opn->Ver]: imap_utf8 may not convert to UTF-8

From: Date: Thu, 08 Oct 2020 14:05:48 +0000
Subject: Bug->Doc #63266 [Opn->Ver]: imap_utf8 may not convert to UTF-8
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17970@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63266&edit=1

 ID:                 63266
 Updated by:         cmb@php.net
 Reported by:        Development at JivanAmara dot net
-Summary:            imap_utf8 returns bad utf8 string
+Summary:            imap_utf8 may not convert to UTF-8
-Status:             Open
+Status:             Verified
-Type:               Bug
+Type:               Documentation Problem
 Package:            IMAP related
 Operating System:   Linux (Ubuntu / Redhat)
 PHP Version:        Irrelevant
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

PHP's imap_utf8() is just a thin wrapper over libc-client's
utf8_mime2text() function.  If the given charset is no supported
by libc-client, utf8_mime2text does not fail, but returns the
string unmodified.  To me that looks like a bug in libc-client,
but that's out of scope for PHP anyway.

Thus, there is nothing we can do (besides re-implementing that
function based on mbstring or iconv, what is not going to happen).
Therefore I'm changing to doc problem.


Previous Comments:
------------------------------------------------------------------------
[2012-10-12 04:43:09] 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



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=63266&edit=1


Thread (2 messages)

« previous php.doc.bugs (#17970) next »