]> granicus.if.org Git - php/commitdiff
Fix for bug #51604 (newline in end of header is shown in start of message).
authorAdam Harvey <aharvey@php.net>
Thu, 22 Apr 2010 02:22:49 +0000 (02:22 +0000)
committerAdam Harvey <aharvey@php.net>
Thu, 22 Apr 2010 02:22:49 +0000 (02:22 +0000)
Patch by Daniel Egeberg.

NEWS
ext/standard/mail.c
ext/standard/tests/mail/bug51604.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 7ac95193e6b66f705d5b29e52dfb49c1f4248fd9..bef365400d2c2f8aeaae306d923f87f43371a0e2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,8 @@ PHP                                                                        NEWS
   literal). (cbandy at jbandy dot com)
 - Fixed bug #51607 (pg_copy_from does not allow schema in the tablename
   argument). (cbandy at jbandy dot com)
+- Fixed bug #51604 (newline in end of header is shown in start of message).
+  (Daniel Egeberg)
 - Fixed bug #51562 (query timeout in mssql can not be changed per query).
   (ejsmont dot artur at gmail dot com)
 - Fixed bug #51445 (var_dump() invalid/slow *RECURSION* detection). (Felipe)
index c03ccdef2b2f6358237336c304f98b319cdf0047..0a4e6befcea342708eabbc7f6936ebf725e28bea 100644 (file)
@@ -95,7 +95,7 @@ PHP_FUNCTION(ezmlm_hash)
    Send an email message */
 PHP_FUNCTION(mail)
 {
-       char *to=NULL, *message=NULL, *headers=NULL;
+       char *to=NULL, *message=NULL, *headers=NULL, *headers_trimmed=NULL;
        char *subject=NULL, *extra_cmd=NULL;
        int to_len, message_len, headers_len;
        int subject_len, extra_cmd_len, i;
@@ -124,6 +124,7 @@ PHP_FUNCTION(mail)
        MAIL_ASCIIZ_CHECK(message, message_len);
        if (headers) {
                MAIL_ASCIIZ_CHECK(headers, headers_len);
+               headers_trimmed = php_trim(headers, headers_len, NULL, 0, NULL, 2 TSRMLS_CC);
        }
        if (extra_cmd) {
                MAIL_ASCIIZ_CHECK(extra_cmd, extra_cmd_len);
@@ -176,12 +177,16 @@ PHP_FUNCTION(mail)
                extra_cmd = php_escape_shell_cmd(extra_cmd);
        }
 
-       if (php_mail(to_r, subject_r, message, headers, extra_cmd TSRMLS_CC)) {
+       if (php_mail(to_r, subject_r, message, headers_trimmed, extra_cmd TSRMLS_CC)) {
                RETVAL_TRUE;
        } else {
                RETVAL_FALSE;
        }
 
+       if (headers_trimmed) {
+               efree(headers_trimmed);
+       }
+
        if (extra_cmd) {
                efree (extra_cmd);
        }
diff --git a/ext/standard/tests/mail/bug51604.phpt b/ext/standard/tests/mail/bug51604.phpt
new file mode 100644 (file)
index 0000000..a657021
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+Bug #51604 (newline in end of header is shown in start of message)
+--INI--
+sendmail_path=tee mail_bug51604.out >/dev/null
+mail.add_x_header = Off
+--SKIPIF--
+<?php
+if(substr(PHP_OS, 0, 3) == "WIN")
+  die("skip Won't run on Windows");
+?>
+--FILE--
+<?php
+// Initialise all required variables
+$to = 'user@company.com';
+$subject = 'Test Subject';
+$message = 'A Message';
+$additional_headers = "KHeaders\n\n\n\n\n";
+$outFile = "mail_bug51604.out";
+@unlink($outFile);
+
+// Calling mail() with all additional headers
+var_dump( mail($to, $subject, $message, $additional_headers) );
+echo file_get_contents($outFile);
+unlink($outFile);
+
+?>
+===DONE===
+--EXPECT--
+bool(true)
+To: user@company.com
+Subject: Test Subject
+KHeaders
+
+A Message
+===DONE===