cvs: php4 /ext/mailparse mailparse.c /ext/mailparse/tests 004.phpt 005.phpt
| From: | Wez Furlong | Date: | Thu, 28 Mar 2002 00:43:43 +0000 |
| Subject: | cvs: php4 /ext/mailparse mailparse.c /ext/mailparse/tests 004.phpt 005.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-10733@lists.php.net to get a copy of this message | ||
wez Wed Mar 27 19:43:43 2002 EDT
Added files:
/php4/ext/mailparse/tests 004.phpt 005.phpt
Modified files:
/php4/ext/mailparse mailparse.c
Log:
make quoted-printable encoding safe for use with digital signatures. Added some tests
Index: php4/ext/mailparse/mailparse.c
diff -u php4/ext/mailparse/mailparse.c:1.23 php4/ext/mailparse/mailparse.c:1.24
--- php4/ext/mailparse/mailparse.c:1.23 Mon Mar 18 13:54:25 2002
+++ php4/ext/mailparse/mailparse.c Wed Mar 27 19:43:42 2002
@@ -17,7 +17,7 @@
| the support routines for this extension were based upon. |
+----------------------------------------------------------------------+
*/
-/* $Id: mailparse.c,v 1.23 2002/03/18 18:54:25 wez Exp $ */
+/* $Id: mailparse.c,v 1.24 2002/03/28 00:43:42 wez Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -246,7 +246,7 @@
}
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 @@
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);
+ }
}
}
Index: php4/ext/mailparse/tests/004.phpt
+++ php4/ext/mailparse/tests/004.phpt
--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
Index: php4/ext/mailparse/tests/005.phpt
+++ php4/ext/mailparse/tests/005.phpt
--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.