php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #51604
Patch php_bug51604.diff revision 2010-04-21 14:00 UTC by degeberg@php.net

Patch php_bug51604.diff for Mail related Bug #51604

Patch version 2010-04-21 14:00 UTC

Return to Bug #51604 | Download this patch
Patch Revisions:

Developer: degeberg@php.net

Index: ext/standard/tests/mail/mail_bug51604.phpt
===================================================================
--- ext/standard/tests/mail/mail_bug51604.phpt	(revision 0)
+++ ext/standard/tests/mail/mail_bug51604.phpt	(revision 0)
@@ -0,0 +1,35 @@
+--TEST--
+fixes bug #51604
+--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===
Index: ext/standard/mail.c
===================================================================
--- ext/standard/mail.c	(revision 298136)
+++ ext/standard/mail.c	(working copy)
@@ -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);
 	}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 17:01:32 2024 UTC