php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45213 imap_utf7_encode() computes wrong UTF-7 data
Submitted: 2008-06-09 13:17 UTC Modified: 2009-05-04 13:38 UTC
From: thomas dot jarosch at intra2net dot com Assigned:
Status: Closed Package: IMAP related
PHP Version: 5.*, 6CVS (2009-04-27) OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: thomas dot jarosch at intra2net dot com
New email:
PHP Version: OS:

 

 [2008-06-09 13:17 UTC] thomas dot jarosch at intra2net dot com
Description:
------------
Hello together,

I tried to encode german umlauts using imap_utf7_encode(),
but the computed string is not understood by the cyrus IMAP server.

This is pretty much related to bug #15630, but now I had the
help of a coworker who is pretty fast decoding base64 by hand :-)

UTF-7 is defined to encode special characters as two byte UTF-16 stream.
Normally the ISO-8859-1 string "t?st" should be encoded into t&AOQ-st,
which corresponds to 0x00, 0xe4.

The current code in PHP 5.2.6 encodes it to t&5A-st,
which is 0xe4 without the leading 0x00.

Would be nice if that could be resolved since it's
not compatible with most IMAP implementations.
Bug #15630 is around since 2002.

Cheers,
Thomas


Reproduce code:
---------------
echo imap_utf7_encode("t?st");

Expected result:
----------------
t&AOQ-st

Actual result:
--------------
t&5A-st

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-27 19:07 UTC] jani@php.net
Here is short and reliable test:

# sapi/cli/php -r '$tst = mb_convert_encoding("t?st", "ISO-8859-1", 
"UTF8"); echo $tst, "\n"; echo imap_utf7_encode($tst), "\n",  
mb_convert_encoding($tst, "UTF7-IMAP", "ISO-8859-1"), "\n";'

 [2009-04-27 20:31 UTC] pajoye@php.net
Should we not simply rely on iconv in 5.2/5.3 and ICU in HEAD?
 [2009-04-28 07:53 UTC] thomas dot jarosch at intra2net dot com
As far as I know, iconv does not support IMAP modified UTF7 out of
the box. Atleast my version 1.9.1 does not and I have a patch for
exactly that. Though we can't rely on people having a patched iconv
version.

The c-client IMAP library has support for UTF8 <-> modified UTF7.
Maybe that would be an option?
 [2009-05-02 18:03 UTC] pajoye@php.net
I added imap_utf8_to_mutf7 and imap_mutf7_to_utf8 to php 5.3 and 6.0. 5.2 can't accept new features, you can easily backport the two functions from 5.3. However I won't fix the utf7_encode/decode functions as they should actually use the imap API and UTF-8. 
 [2009-05-04 13:38 UTC] thomas dot jarosch at intra2net dot com
Sounds good. Thanks!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 00:01:30 2024 UTC