1 diff -urNp -x '*.orig' php-5.2.17.org/ext/standard/mail.c php-5.2.17/ext/standard/mail.c
2 --- php-5.2.17.org/ext/standard/mail.c 2010-07-19 15:38:53.000000000 +0200
3 +++ php-5.2.17/ext/standard/mail.c 2021-10-23 18:57:39.619791815 +0200
11 #include "ext/standard/info.h"
14 #include "php_string.h"
15 #include "safe_mode.h"
17 +#include "zend_operators.h"
18 +#include "zend_globals.h"
21 #include "win32/sendmail.h"
22 @@ -131,6 +135,18 @@ PHP_FUNCTION(mail)
23 MAIL_ASCIIZ_CHECK(extra_cmd, extra_cmd_len);
26 + /* search for To: and Subject: headers which should be specified in proper mail() parameters, not in additional headers */
27 + if (headers != NULL) {
28 + if (strncasecmp(headers, "to:", sizeof("to:") - 1) == 0 || strcasestr(headers, "\nto:")) {
29 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "To: headers aren't allowed in the additional_headers parameter. Use $to parameter for that. Mail not sent.");
32 + if (strncasecmp(headers, "subject:", sizeof("subject:") - 1) == 0 || strcasestr(headers, "\nsubject:")) {
33 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Subject: headers aren't allowed in the additional_headers parameter. Use $subject parameter for that. Mail not sent.");
39 to_r = estrndup(to, to_len);
40 for (; to_len; to_len--) {
41 @@ -276,8 +292,42 @@ PHPAPI int php_mail(char *to, char *subj
45 - fprintf(sendmail, "To: %s\n", to);
46 - fprintf(sendmail, "Subject: %s\n", subject);
49 + if ((to != NULL) && (strlen(to)!=0)) {
50 + fprintf(sendmail, "To: %s\n", to);
52 + if ((subject != NULL) && (strlen(subject)!=0)) {
53 + fprintf(sendmail, "Subject: %s\n", subject);
55 + zend_is_auto_global(ZEND_STRL("_SERVER") TSRMLS_CC);
56 + if (PG(http_globals)[TRACK_VARS_SERVER]) {
57 + zval **remote_addr, **server_name, **server_port,
58 + **script_name, **http_user_agent;
60 + if (zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, "REMOTE_ADDR", sizeof("REMOTE_ADDR"), (void **) &remote_addr)==SUCCESS) {
61 + convert_to_string_ex(remote_addr);
62 + fprintf(sendmail, "HTTP-Posting-Client: %s\n", Z_STRVAL_PP(remote_addr));
64 + if (zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, "SERVER_NAME", sizeof("SERVER_NAME"), (void **) &server_name)==SUCCESS) {
65 + convert_to_string_ex(server_name);
66 + fprintf(sendmail, "HTTP-Posting-URI: %s", Z_STRVAL_PP(server_name));
67 + if (zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, "SERVER_PORT", sizeof("SERVER_PORT"), (void **) &server_port)==SUCCESS) {
68 + convert_to_string_ex(server_port);
69 + fprintf(sendmail, ":%s", Z_STRVAL_PP(server_port));
71 + if (zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, "SCRIPT_NAME", sizeof("SCRIPT_NAME"), (void **) &script_name)==SUCCESS) {
72 + convert_to_string_ex(script_name);
73 + fprintf(sendmail, "%s", Z_STRVAL_PP(script_name));
75 + fprintf(sendmail, "\n");
77 + if (zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, "HTTP_USER_AGENT", sizeof("HTTP_USER_AGENT"), (void **) &http_user_agent)==SUCCESS) {
78 + convert_to_string_ex(http_user_agent);
79 + fprintf(sendmail, "HTTP-Posting-User-Agent: %s\n", Z_STRVAL_PP(http_user_agent));
83 if (headers != NULL) {
84 fprintf(sendmail, "%s\n", headers);