cvs: php4 /ext/mailparse rfc2045cdecode.c

From: Date: Sat, 19 Jan 2002 14:06:51 +0000
Subject: cvs: php4 /ext/mailparse rfc2045cdecode.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-9093@lists.php.net to get a copy of this message
wez Sat Jan 19 09:06:51 2002 EDT Modified files: /php4/ext/mailparse rfc2045cdecode.c Log: 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. Index: php4/ext/mailparse/rfc2045cdecode.c diff -u php4/ext/mailparse/rfc2045cdecode.c:1.3 php4/ext/mailparse/rfc2045cdecode.c:1.4 --- php4/ext/mailparse/rfc2045cdecode.c:1.3 Mon Jul 30 04:24:29 2001 +++ php4/ext/mailparse/rfc2045cdecode.c Sat Jan 19 09:06:51 2002 @@ -1,4 +1,4 @@ -/* $Id: rfc2045cdecode.c,v 1.3 2001/07/30 08:24:29 zeev Exp $ */ +/* $Id: rfc2045cdecode.c,v 1.4 2002/01/19 14:06:51 wez Exp $ */ /* ** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for ** distribution information. @@ -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 @@ 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 @@ 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 @@ 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);

« previous php.cvs (#9093) next »