Updated patch for 'ext/imap/php_imap.c'.

Gamid Isayev

--- php_imap.c  5 Aug 2002 21:53:09 -0000       1.134
+++ php_imap.c  8 Aug 2002 18:52:47 -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 == '-') {
@@ -2211,29 +2214,42 @@
         outlen = 0;
         state = ST_NORMAL;
         endp = (inp = in) + inlen;
-       while (inp < endp) {
+       while (inp < endp || state != ST_NORMAL) {
                 if (state == ST_NORMAL) {
-                       if (SPECIAL(*inp)) {
+                       if (*inp == 0x00 && *(inp+1) < 0x80) {
+                               /* ASCII character */
+                               outlen++;               // for ASCII char
+                               if (*(inp+1) == '&')
+                                       outlen++;       // for '-'
+                               inp += 2;
+                       } else {
+                               /* begin encoding */
                                 state = ST_ENCODE0;
-                               outlen++;
-                       } else if (*inp++ == '&') {
+                               outlen++;       // for '&'
+                       }
+               } else if (inp == endp || (*inp == 0x00 && *(inp+1) < 
0x80)) {
+                       /* flush overflow and terminate region */
+                       if (state != ST_ENCODE0) {
                                 outlen++;
                         }
-                       outlen++;
-               } else if (!SPECIAL(*inp)) {
+                       outlen++;       // for '-'
                         state = ST_NORMAL;
                 } else {
-                       /* ST_ENCODE0 -> ST_ENCODE1     - two chars
-                        * ST_ENCODE1 -> ST_ENCODE2     - one char
-                        * ST_ENCODE2 -> ST_ENCODE0     - one char
-                        */
-                       if (state == ST_ENCODE2) {
-                               state = ST_ENCODE0;
-                       }
-                       else if (state++ == ST_ENCODE0) {
-                               outlen++;
+                       switch (state) {
+                               case ST_ENCODE0:
+                                       outlen++;
+                                       state = ST_ENCODE1;
+                                       break;
+                               case ST_ENCODE1:
+                                       outlen++;
+                                       state = ST_ENCODE2;
+                                       break;
+                               case ST_ENCODE2:
+                                       outlen += 2;
+                                       state = ST_ENCODE0;
+                               case ST_NORMAL:
+                                       break;
                         }
-                       outlen++;
                         inp++;
                 }
         }
@@ -2250,14 +2266,17 @@
         endp = (inp = in) + inlen;
         while (inp < endp || state != ST_NORMAL) {
                 if (state == ST_NORMAL) {
-                       if (SPECIAL(*inp)) {
+                       if (*inp == 0x00 && *(inp+1) < 0x80) {
+                               /* ASCII character */
+                               inp++;
+                               if ((*outp++ = *inp++) == '&')
+                                       *outp++ = '-';
+                       } else {
                                 /* begin encoding */
                                 *outp++ = '&';
                                 state = ST_ENCODE0;
-                       } else if ((*outp++ = *inp++) == '&') {
-                               *outp++ = '-';
                         }
-               } else if (inp == endp || !SPECIAL(*inp)) {
+               } else if (inp == endp || (*inp == 0x00 && *(inp+1) < 
0x80)) {
                         /* flush overflow and terminate region */
                         if (state != ST_ENCODE0) {
                                 *outp++ = B64(*outp);


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

Reply via email to