]> granicus.if.org Git - php/commitdiff
make quoted-printable encoding safe for use with digital signatures. Added some tests
authorWez Furlong <wez@php.net>
Thu, 28 Mar 2002 00:43:44 +0000 (00:43 +0000)
committerWez Furlong <wez@php.net>
Thu, 28 Mar 2002 00:43:44 +0000 (00:43 +0000)
ext/mailparse/mailparse.c
ext/mailparse/tests/004.phpt [new file with mode: 0644]
ext/mailparse/tests/005.phpt [new file with mode: 0644]

index 4a102e283155f95523502cbc08d744c29a95c854..ed8672c886a0ba297d41f301600e1d4a192a69ee 100755 (executable)
@@ -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 (file)
index 0000000..de9e4b6
--- /dev/null
@@ -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 (file)
index 0000000..b67cef4
--- /dev/null
@@ -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.
+