diff options
-rwxr-xr-x | ext/mailparse/mailparse.c | 42 | ||||
-rw-r--r-- | ext/mailparse/tests/004.phpt | 44 | ||||
-rw-r--r-- | ext/mailparse/tests/005.phpt | 40 |
3 files changed, 118 insertions, 8 deletions
diff --git a/ext/mailparse/mailparse.c b/ext/mailparse/mailparse.c index 4a102e2831..ed8672c886 100755 --- a/ext/mailparse/mailparse.c +++ b/ext/mailparse/mailparse.c @@ -246,7 +246,7 @@ PHP_FUNCTION(mailparse_uudecode_all) } else { /* write to the output file */ - php_stream_puts(outstream, buffer); + php_stream_write_string(outstream, buffer); } } php_stream_close(outstream); @@ -438,13 +438,39 @@ PHP_FUNCTION(mailparse_stream_encode) deststream ); - while(!php_stream_eof(srcstream)) { - len = php_stream_read(srcstream, buf, bufsize); - if (len > 0) - { - int i; - for (i=0; i<len; i++) - mbfl_convert_filter_feed(buf[i], conv); + if (enc == mbfl_no_encoding_qprint) { + /* If the qp encoded section is going to be digitally signed, + * it is a good idea to make sure that lines that begin "From " + * have the letter F encoded, so that MTAs do not stick a > character + * in front of it and invalidate the content/signature */ + while(!php_stream_eof(srcstream)) { + if (NULL != php_stream_gets(srcstream, buf, bufsize)) { + int i; + + len = strlen(buf); + + if (strncmp(buf, "From ", 5) == 0) { + mbfl_convert_filter_flush(conv); + php_stream_write(deststream, "=46rom ", 7); + i = 5; + } else { + i = 0; + } + + for (; i<len; i++) + mbfl_convert_filter_feed(buf[i], conv); + } + } + + } else { + while(!php_stream_eof(srcstream)) { + len = php_stream_read(srcstream, buf, bufsize); + if (len > 0) + { + int i; + for (i=0; i<len; i++) + mbfl_convert_filter_feed(buf[i], conv); + } } } diff --git a/ext/mailparse/tests/004.phpt b/ext/mailparse/tests/004.phpt new file mode 100644 index 0000000000..de9e4b6fbd --- /dev/null +++ b/ext/mailparse/tests/004.phpt @@ -0,0 +1,44 @@ +--TEST-- +Check uudecode_all +--SKIPIF-- +<?php if (!extension_loaded("mailparse")) print "skip"; ?> +--POST-- +--GET-- +--FILE-- +<?php +$text = <<<EOD +To: fred@bloggs.com + +hello, this is some text hello. +blah blah blah. + +begin 644 test.txt +/=&AI<R!I<R!A('1E<W0* +` +end + +EOD; + +$fp = tmpfile(); +fwrite($fp, $text); + +$data = mailparse_uudecode_all($fp); + +echo "BODY\n"; +readfile($data[0]["filename"]); +echo "UUE\n"; +readfile($data[1]["filename"]); + +unlink($data[0]["filename"]); +unlink($data[1]["filename"]); + +?> +--EXPECT-- +BODY +To: fred@bloggs.com + +hello, this is some text hello. +blah blah blah. + +UUE +this is a test diff --git a/ext/mailparse/tests/005.phpt b/ext/mailparse/tests/005.phpt new file mode 100644 index 0000000000..b67cef48dc --- /dev/null +++ b/ext/mailparse/tests/005.phpt @@ -0,0 +1,40 @@ +--TEST-- +Check quoted-printable encoding generates S/MIME safe content +--SKIPIF-- +<?php if (!extension_loaded("mailparse")) print "skip"; ?> +--POST-- +--GET-- +--FILE-- +<?php +$text = <<<EOD +To: fred@bloggs.com + +blah blah blah From blah $ " & £ blah blah blah blah blah +From the first of the month, things will be different! +blah blah blah From blah +Frome is a town in Somerset. +EOD; + +$fp = tmpfile(); +fwrite($fp, $text); +rewind($fp); + +$fpdest = tmpfile(); + +mailparse_stream_encode($fp, $fpdest, "quoted-printable"); + +rewind($fpdest); + +fpassthru($fpdest); + +fclose($fp); +fclose($fpdest); +?> +--EXPECT-- +To: fred@bloggs.com + +blah blah blah From blah $ " & =A3 blah blah blah blah blah +=46rom the first of the month, things will be different! +blah blah blah From blah +Frome is a town in Somerset. + |