--- php-4.4.1/ext/standard/mail.c.orig Tue Jul 26 18:32:58 2005 +++ php-4.4.1/ext/standard/mail.c Fri Nov 18 15:01:31 2005 @@ -86,7 +86,7 @@ char *subject=NULL, *extra_cmd=NULL; int to_len, message_len, headers_len; int subject_len, extra_cmd_len, i; - char *to_r, *subject_r; + char *to_r, *subject_r, *headers_r; if (PG(safe_mode) && (ZEND_NUM_ARGS() == 5)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "SAFE MODE Restriction in effect. The fifth parameter is disabled in SAFE MODE."); @@ -144,11 +144,45 @@ subject_r = subject; } + if (headers > 0) { + int crlf_flg; + headers_r = estrndup(headers, headers_len); + for (; headers_len; headers_len--) { + if (!isspace((unsigned char) headers_r[headers_len - 1])) { + break; + } + headers_r[headers_len - 1] = '\0'; + } + crlf_flg = 0; + for(i = 0; headers[i]; i++) { + if (iscntrl((unsigned char) headers_r[i])) { + if (crlf_flg == 1){ + if (headers_r[i] == '\r' || headers_r[i] == '\n'){ + headers_r[i] = '\0'; + break; + } + crlf_flg = 0; + } else { + if (headers_r[i] == '\n'){ + crlf_flg = 1; + } else if (headers_r[i] == '\r' && headers_r[i + 1] == '\n'){ + crlf_flg = 1; + i++; + } else if (headers_r[i] == '\r'){ + crlf_flg = 1; + } + } + } + } + } else { + headers_r = headers; + } + if (extra_cmd) { 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_r, extra_cmd TSRMLS_CC)) { RETVAL_TRUE; } else { RETVAL_FALSE;