From bf7662a241771697ee8a8aecd7b342873ba96b5a Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 19 Jan 2002 14:06:52 +0000 Subject: [PATCH] Make the decoder less strict to allow for brain-dead mailers that mark 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 | 44 ++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/ext/mailparse/rfc2045cdecode.c b/ext/mailparse/rfc2045cdecode.c index 8ec5d5de76..b4fc739bb5 100755 --- a/ext/mailparse/rfc2045cdecode.c +++ b/ext/mailparse/rfc2045cdecode.c @@ -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; idecode_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); -- 2.40.0