aharvey                                  Thu, 22 Apr 2010 02:22:49 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=298291

Log:
Fix for bug #51604 (newline in end of header is shown in start of message).
Patch by Daniel Egeberg.

Bug: http://bugs.php.net/51604 (Assigned) newline in end of header is shown in 
start of message
      
Changed paths:
    U   php/php-src/branches/PHP_5_2/NEWS
    U   php/php-src/branches/PHP_5_2/ext/standard/mail.c
    A   php/php-src/branches/PHP_5_2/ext/standard/tests/mail/bug51604.phpt
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/standard/mail.c
    A   php/php-src/branches/PHP_5_3/ext/standard/tests/mail/bug51604.phpt
    U   php/php-src/trunk/ext/standard/mail.c
    A   php/php-src/trunk/ext/standard/tests/mail/bug51604.phpt

Modified: php/php-src/branches/PHP_5_2/NEWS
===================================================================
--- php/php-src/branches/PHP_5_2/NEWS	2010-04-22 01:07:48 UTC (rev 298290)
+++ php/php-src/branches/PHP_5_2/NEWS	2010-04-22 02:22:49 UTC (rev 298291)
@@ -21,6 +21,8 @@
   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)

Modified: php/php-src/branches/PHP_5_2/ext/standard/mail.c
===================================================================
--- php/php-src/branches/PHP_5_2/ext/standard/mail.c	2010-04-22 01:07:48 UTC (rev 298290)
+++ php/php-src/branches/PHP_5_2/ext/standard/mail.c	2010-04-22 02:22:49 UTC (rev 298291)
@@ -95,7 +95,7 @@
    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 @@
 	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 @@
 		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);
 	}

Added: php/php-src/branches/PHP_5_2/ext/standard/tests/mail/bug51604.phpt
===================================================================
--- php/php-src/branches/PHP_5_2/ext/standard/tests/mail/bug51604.phpt	                        (rev 0)
+++ php/php-src/branches/PHP_5_2/ext/standard/tests/mail/bug51604.phpt	2010-04-22 02:22:49 UTC (rev 298291)
@@ -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 = 'u...@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: u...@company.com
+Subject: Test Subject
+KHeaders
+
+A Message
+===DONE===

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS	2010-04-22 01:07:48 UTC (rev 298290)
+++ php/php-src/branches/PHP_5_3/NEWS	2010-04-22 02:22:49 UTC (rev 298291)
@@ -30,6 +30,8 @@
   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 #51590 (JSON_ERROR_UTF8 is undefined). (Felipe)
 - Fixed bug #51562 (query timeout in mssql can not be changed per query).
   (ejsmont dot artur at gmail dot com)

Modified: php/php-src/branches/PHP_5_3/ext/standard/mail.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/mail.c	2010-04-22 01:07:48 UTC (rev 298290)
+++ php/php-src/branches/PHP_5_3/ext/standard/mail.c	2010-04-22 02:22:49 UTC (rev 298291)
@@ -97,7 +97,7 @@
    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 = 0;
 	int subject_len, extra_cmd_len = 0, i;
@@ -122,6 +122,7 @@
 	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);
@@ -173,12 +174,16 @@
 		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);
 	}

Added: php/php-src/branches/PHP_5_3/ext/standard/tests/mail/bug51604.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/tests/mail/bug51604.phpt	                        (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/standard/tests/mail/bug51604.phpt	2010-04-22 02:22:49 UTC (rev 298291)
@@ -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 = 'u...@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: u...@company.com
+Subject: Test Subject
+KHeaders
+
+A Message
+===DONE===

Modified: php/php-src/trunk/ext/standard/mail.c
===================================================================
--- php/php-src/trunk/ext/standard/mail.c	2010-04-22 01:07:48 UTC (rev 298290)
+++ php/php-src/trunk/ext/standard/mail.c	2010-04-22 02:22:49 UTC (rev 298291)
@@ -97,7 +97,7 @@
    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 = 0;
 	int subject_len, extra_cmd_len = 0, i;
@@ -122,6 +122,7 @@
 	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);
@@ -173,12 +174,16 @@
 		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);
 	}

Added: php/php-src/trunk/ext/standard/tests/mail/bug51604.phpt
===================================================================
--- php/php-src/trunk/ext/standard/tests/mail/bug51604.phpt	                        (rev 0)
+++ php/php-src/trunk/ext/standard/tests/mail/bug51604.phpt	2010-04-22 02:22:49 UTC (rev 298291)
@@ -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 = 'u...@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: u...@company.com
+Subject: Test Subject
+KHeaders
+
+A Message
+===DONE===
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to