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

--- ext/imap/php_imap.c 5 Aug 2002 21:53:09 -0000       1.134
+++ ext/imap/php_imap.c 7 Aug 2002 15:00:44 -0000
@@ -2077,14 +2077,14 @@
                                 php_error(E_WARNING, "%s(): Invalid 
modified UTF-7 character: `%c'", get_active_function_name(TSRMLS_C), *inp);
                                 RETURN_FALSE;
                         } else if (*inp != '&') {
-                               outlen++;
+                               outlen += 2;
                         } else if (inp + 1 == endp) {
                                 php_error(E_WARNING, "%s(): Unexpected 
end of string", get_active_function_name(TSRMLS_C));
                                 RETURN_FALSE;
                         } else if (inp[1] != '-') {
                                 state = ST_DECODE0;
                         } else {
-                               outlen++;
+                               outlen += 2;
                                 inp++;
                         }
                 } else if (*inp == '-') {
@@ -2134,8 +2134,11 @@
                         if (*inp == '&' && inp[1] != '-') {
                                 state = ST_DECODE0;
                         }
-                       else if ((*outp++ = *inp) == '&') {
-                               inp++;
+                       else {
+                               *outp++ = 0x00;
+                               if ((*outp++ = *inp) == '&') {
+                                       inp++;
+                               }
                         }
                 }
                 else if (*inp == '-') {


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to