#15630 [Com]: imap_utf7_decode appears to be broken
| From: | gamid at isayev dot net | Date: | Mon, 29 Jul 2002 19:51:06 +0000 |
| Subject: | #15630 [Com]: imap_utf7_decode appears to be broken | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-15517@lists.php.net to get a copy of this message | ||
ID: 15630
Comment by: gamid@isayev.net
Reported By: robert.marchand@umontreal.ca
Status: Bogus
Bug Type: IMAP related
Operating System: SGI Irix 6.5
PHP Version: 4.1.1
New Comment:
This is the updated patch for 'ext/imap/php_imap.c':
--- php_imap.c Mon Jul 29 15:17:45 2002
+++ php_imap.c Mon Jul 29 15:18:27 2002
@@ -2215,14 +2215,14 @@
php_error(E_WARNING, "imap_utf7_decode:
Invalid modified UTF-7 character: `%c'", *inp);
RETURN_FALSE;
} else if (*inp != '&') {
- outlen++;
+ outlen += 2;
} else if (inp + 1 == endp) {
php_error(E_WARNING, "imap_utf7_decode:
Unexpected end of string");
RETURN_FALSE;
} else if (inp[1] != '-') {
state = ST_DECODE0;
} else {
- outlen++;
+ outlen += 2;
inp++;
}
} else if (*inp == '-') {
@@ -2272,8 +2272,11 @@
if (*inp == '&' && inp[1] != '-') {
state = ST_DECODE0;
}
- else if ((*outp++ = *inp) == '&') {
- inp++;
+ else {
+ *outp++ = 0x00;
+ if ((*outp++ = *inp) == '&') {
+ inp++;
+ }
}
}
else if (*inp == '-') {
Previous Comments:
------------------------------------------------------------------------
[2002-07-29 10:33:50] gamid@isayev.net
I have the same problem with imap_utf7_decode() in PHP v4.2.2
Script 'test_utf7.php3' is attached to this posting to illustrate this
problem.
According PHP documentation imap_utf7_decode() returns "the decoded
8bit data", but documentation says nothing about encoding of returned
"8bit data". When I try decode folder with name 'test&AN9ZJw-',
imap_utf7_decode() returns following string:
0x74, 0x65, 0x73, 0x74, 0x00, 0xDF, 0x59, 0x27
It looks as UTF-16 (UCS-2) string with missed '0x00' for ASCII
characters. If I'm right and imap_utf7_decode() returns UTF-16 string,
this string should be represented as:
0x00, 0x74, 0x00, 0x65, 0x00, 0x73, 0x00, 0x74, 0x00, 0xDF, 0x59, 0x27
To fix this this problem I wrote patch for ext/imap/php_imap.c and
attache it to this posting.
Best regards,
Gamid Isayev
--- test_utf7.php3 ------------------------------------
<HTML>
<HEAD>
<TITLE>Test UTF7</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=utf-8">
</HEAD>
<BODY>
<?
$folder = 'test&AN9ZJw-';
echo "folder (modified UTF-7): $folder<BR><BR>\n";
echo "<strong>mb_convert_encoding test</strong><BR>\n";
$test = $folder;
$test = mb_convert_encoding($test, "UTF-8", "UTF7-IMAP");
echo " folder decoded: [$test]<BR>\n";
$test = mb_convert_encoding($test, "UTF7-IMAP", "UTF-8");
echo "encoded again: [", $test, "]<BR>\n";
$test = mb_convert_encoding($test, "UTF-8", "UTF7-IMAP");
echo "decoded again: [", $test, "]<BR><BR>\n";
echo "<strong>imap_utf7_decode test</strong><BR>\n";
$test = $folder;
$test = imap_utf7_decode($test);
echo "folder decoded: [", $test, "]<BR>\n";
$test = imap_utf7_encode($test);
echo "encoded again: [", $test, "]<BR>\n";
$test = imap_utf7_decode($test);
echo "decoded again: [", $test, "]<BR><BR>\n";
?>
</BODY>
</HTML>
--- end of test_utf7.php3 -----------------------------
--- ext/imap/php_imap.c -------------------------------
--- php_imap.c Fri Jul 26 17:25:10 2002
+++ php_imap.c Fri Jul 26 17:26:28 2002
@@ -2215,7 +2215,7 @@
php_error(E_WARNING, "imap_utf7_decode:
Invalid modified UTF-7 character: `%c'", *inp);
RETURN_FALSE;
} else if (*inp != '&') {
- outlen++;
+ outlen += 2;
} else if (inp + 1 == endp) {
php_error(E_WARNING, "imap_utf7_decode:
Unexpected end of string");
RETURN_FALSE;
@@ -2272,8 +2272,11 @@
if (*inp == '&' && inp[1] != '-') {
state = ST_DECODE0;
}
- else if ((*outp++ = *inp) == '&') {
- inp++;
+ else {
+ *outp++ = 0x00;
+ if ((*outp++ = *inp) == '&') {
+ inp++;
+ }
}
}
else if (*inp == '-') {
--- end of ext/imap/php_imap.c ------------------------
------------------------------------------------------------------------
[2002-06-27 00:15:20] sniper@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately your version of PHP is too old -- the problem
might already be fixed. Please download a new PHP
version from http://www.php.net/downloads.php
If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.
------------------------------------------------------------------------
[2002-02-19 15:56:22] robert.marchand@umontreal.ca
Hi,
when trying to use the IMP Webmail client with an Exchange 2000
Server, folders
with accents in the name are mangled. It appears that the Exchange
Imapd server
sends modified utf-7 names as explained in rfc 2060. IMP use a call to
the
imap_utf7_decode function. It should work but it does'nt.
Here's a sample:
What Exchange send: "&AMk-l&AOk-ments envoy&AOk-s"
What it means: Éléments envoyés.
What IMP show: <nothing>
My setting is:
SGI Irix 6.5
Imap-2001a
PHP 4.1.1
IMP 2.2.7
I have setup a small script that show the problem:
<?php
error_reporting(63);
$folder = '&AMk-l&AOk-ments envoy&AOk-s';
$plain = 'Boîte de réception';
$unicode = mb_convert_encoding($plain, "UNICODE", "ISO-8859-1");
$br = "<br>";
echo "<html><head><title>test
UTF7</title></head><body>";
echo "folder (modified UTF-7): ", $folder, $br;
echo "plain (Latin1): ", $plain, $br, $br;
echo "<strong>mb_convert_encoding test</strong>", $br;
$test = mb_convert_encoding($folder, "auto", "UTF7-IMAP");
echo " folder decoded: ", $test, $br;
$test = mb_convert_encoding($test, "UTF7-IMAP", "ISO-8859-1");
echo " encoded again: ", $test, $br;
$test = mb_convert_encoding($test, "auto", "UTF7-IMAP");
echo " decoded again: ", $test, $br, $br;
$test = mb_convert_encoding($plain, "UTF7-IMAP", "ISO-8859-1");
echo " plain encoded: ", $test, $br;
$test = mb_convert_encoding($test, "auto", "UTF7-IMAP");
echo " decoded: ", $test, $br, $br;
echo "<strong>imap_utf7_decode test</strong>", $br;
$test = imap_utf7_decode($folder);
echo "folder decoded: ", $test, $br;
$test = imap_utf7_encode($test);
echo " encoded again: ", $test, $br;
$test = imap_utf7_decode($test);
echo " decoded again: ", $test, $br, $br;
$test = imap_utf7_encode($plain);
echo " plain encoded: ", $test, $br;
//$test = imap_utf7_encode($unicode);
//echo "unicode encoded: ", $test, $br;
$test = imap_utf7_decode($test);
echo " decoded: ", $test, $br;
echo "</body></html>";
?>
And here is the output:
folder (modified UTF-7): &AMk-l&AOk-ments envoy&AOk-s
plain (Latin1): Boîte de réception
mb_convert_encoding test
folder decoded: Éléments envoyés
encoded again: &AMk-l&AOk-ments envoy&AOk-s
decoded again: Éléments envoyés
plain encoded: Bo&AO4-te de r&AOk-ception
decoded: Boîte de réception
imap_utf7_decode test
folder decoded: Ælàments envoyàs
encoded again: &A8l-l&A+p-ments envoy&AfM-s
decoded again: Àlùments envoyðs
plain encoded: Bo&7s-te de r&6g-ception
decoded: Boïte de rîception
--------------
As you see I've found a work around by using the function
mb_convert_encoding.
Is imap_utf7_* really broken or what?
Thanks.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=15630&edit=1