]> granicus.if.org Git - php/commitdiff
Make the decoder less strict to allow for brain-dead mailers that mark
authorWez Furlong <wez@php.net>
Sat, 19 Jan 2002 14:06:52 +0000 (14:06 +0000)
committerWez Furlong <wez@php.net>
Sat, 19 Jan 2002 14:06:52 +0000 (14:06 +0000)
messages as 7bit but then include 8bit chars in the body.
Thanks to Dan Fitzpatrick for bringing this to my attention.

ext/mailparse/rfc2045cdecode.c

index 8ec5d5de7610bd4e65073e9cca8eefad20941522..b4fc739bb5905a0c25783ec3425b5101a746d868 100755 (executable)
@@ -7,15 +7,21 @@
 #include       "php.h"
 #include "php_mailparse.h"
 
+#define DEBUG_RFC2045_DECODE   0
+
 
 static int op_func(int c, void *dat)
 {
        struct rfc2045 * p = (struct rfc2045*)dat;
 
+       
        rfc2045_add_workbufch(p, c);
 
        /* drain buffer */
        if (p->workbuflen >= 4096)      {
+#if DEBUG_RFC2045_DECODE
+               zend_printf("op_func buffer is %d; lets drain it\n", p->workbuflen);
+#endif
                (*p->udecode_func)(p->workbuf, p->workbuflen, p->misc_decode_ptr);
                p->workbuflen = 0;
        }
@@ -45,7 +51,7 @@ void rfc2045_cdecode_start(struct rfc2045 *p,
        p->udecode_func=u;
        p->workbuflen=0;
 
-       if (from == mbfl_no_encoding_8bit)
+       if (from == mbfl_no_encoding_8bit || from == mbfl_no_encoding_7bit)
                p->decode_filter = NULL;
        else
                p->decode_filter = mbfl_convert_filter_new(
@@ -63,8 +69,13 @@ int rfc2045_cdecode_end(struct rfc2045 *p)
                mbfl_convert_filter_flush(p->decode_filter);
                mbfl_convert_filter_delete(p->decode_filter);
                p->decode_filter = NULL;
-               if (p->workbuflen > 0)
+               if (p->workbuflen > 0)  {
+#if DEBUG_RFC2045_DECODE
+                       zend_printf("cdecode end: there are %d bytes remaining; drain it\n",
+                                               p->workbuflen);
+#endif
                        (*p->udecode_func)(p->workbuf, p->workbuflen, p->misc_decode_ptr);
+               }
        }
        return 0;
 }
@@ -77,14 +88,39 @@ int rfc2045_cdecode(struct rfc2045 *p, const char *s, size_t l)
 
                if (p->decode_filter)
                {
+#if DEBUG_RFC2045_DECODE
+                       zend_printf("cdecode: with filter %d bytes\n", l);
+#endif
                        for (i=0; i<l; i++)
                        {
-                               if (mbfl_convert_filter_feed(s[i], p->decode_filter) < 0)
+                               if (mbfl_convert_filter_feed(s[i], p->decode_filter) < 0)       {
+#if DEBUG_RFC2045_DECODE
+                                       int j;
+
+                                       zend_printf("returning -1 on %d byte == %d (%c)! context is\n",
+                                                       i, (unsigned char)s[i], s[i]);
+
+                                       for (j = i - 10; j < i + 10; j++)       {
+                                               zend_printf("  byte %d  was %d  '%c'\n",
+                                                               j, (unsigned char)s[j], s[j]
+                                                               );
+                                       }
+#else
+                                       TSRMLS_FETCH();
+                                       zend_error(E_WARNING, "%s() - filter conversion failed. Input message is probably incorrectly encoded\n",
+                                               get_active_function_name(TSRMLS_C)
+                                                       );
+#endif 
                                        return -1;
+                               }
                        }
                }
-               else
+               else    {
+#if DEBUG_RFC2045_DECODE
+                       zend_printf("cdecode: no filter %d bytes\n", l);
+#endif
                        return ((*p->udecode_func)(s,l,p->misc_decode_ptr));
+               }
 
        }
        return (0);