From: Adam Harvey Date: Thu, 22 Apr 2010 02:22:49 +0000 (+0000) Subject: Fix for bug #51604 (newline in end of header is shown in start of message). X-Git-Tag: php-5.3.3RC1~282 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=592daf8453f5b7435a0304375146523a6eaee420;p=php Fix for bug #51604 (newline in end of header is shown in start of message). Patch by Daniel Egeberg. --- diff --git a/NEWS b/NEWS index 8187f27888..92ca9f91d8 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,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 #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) diff --git a/ext/standard/mail.c b/ext/standard/mail.c index ab65f164e7..d9deb5c84a 100644 --- a/ext/standard/mail.c +++ b/ext/standard/mail.c @@ -97,7 +97,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 = 0; int subject_len, extra_cmd_len = 0, i; @@ -122,6 +122,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); @@ -173,12 +174,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 index 0000000000..a657021025 --- /dev/null +++ b/ext/standard/tests/mail/bug51604.phpt @@ -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-- + +--FILE-- + +===DONE=== +--EXPECT-- +bool(true) +To: user@company.com +Subject: Test Subject +KHeaders + +A Message +===DONE===