Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:14218 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31025 invoked by uid 1010); 28 Dec 2004 11:58:29 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 31001 invoked from network); 28 Dec 2004 11:58:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Dec 2004 11:58:29 -0000 X-Host-Fingerprint: 213.228.1.85 h2g2.staff.proxad.net Linux 2.4/2.6 Received: from ([213.228.1.85:33992] helo=h2g2.staff.proxad.net) by pb1.pair.com (ecelerity HEAD (r3992M)) with SMTP id 4F/D6-27805-46A41D14 for ; Tue, 28 Dec 2004 06:58:28 -0500 Received: from localhost (localhost [127.0.0.1]) by h2g2.staff.proxad.net (Postfix) with ESMTP id 30D6E856 for ; Tue, 28 Dec 2004 12:58:26 +0100 (CET) Received: from h2g2.staff.proxad.net ([127.0.0.1]) by localhost (h2g2 [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 25761-06 for ; Tue, 28 Dec 2004 12:58:25 +0100 (CET) Received: by h2g2.staff.proxad.net (Postfix, from userid 1000) id 73E86852; Tue, 28 Dec 2004 12:58:25 +0100 (CET) Date: Tue, 28 Dec 2004 12:58:25 +0100 To: internals@lists.php.net Message-ID: <20041228115825.GA25679@h2g2.staff.proxad.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="xHFwDpU9dbj6ez1V" Content-Disposition: inline User-Agent: Mutt/1.4i X-Virus-Scanned: by amavisd-new-20030616-p7 (Debian) at h2g2.staff.proxad.net Subject: Patch to PHP mail() function From: obeyssac@proxad.net (Olivier Beyssac) --xHFwDpU9dbj6ez1V Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, Please find attached a small patch to the PHP mail() function. It adds two options to php.ini: - mail_add_cgi_headers: add SERVER_NAME, SCRIPT_NAME and REMOTE_ADDR to the mail headers before piping it to sendmail with the X-CGI-VAR prefix), - mail_custom_headers: specify additionnal, site-wide headers (i.e.: "X-Abuse-To: abuse@site.net"). If you include this contribution to the official PHP source tree, please mention this email address and my company name: Online.net. Regards. -- Olivier Beyssac - obeyssac@proxad.net --xHFwDpU9dbj6ez1V Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="mail.diff" diff -urN php-4.3.10.orig/ext/standard/mail.c php-4.3.10/ext/standard/mail.c --- php-4.3.10.orig/ext/standard/mail.c Fri Jan 9 02:35:58 2004 +++ php-4.3.10/ext/standard/mail.c Thu Dec 23 16:25:32 2004 @@ -55,6 +55,16 @@ continue; \ } \ +#define env_fprintf(var, stream) \ + do { \ + char *tmp_env; \ + int tmp_len; \ + \ + if ((tmp_env = sapi_getenv(var, tmp_len TSRMLS_CC)) \ + || (tmp_env = getenv(var))) \ + fprintf(stream, "X-CGI-VAR-%s: %s\n", var, tmp_env); \ + } while (0) + /* {{{ proto int ezmlm_hash(string addr) Calculate EZMLM list hash value. */ PHP_FUNCTION(ezmlm_hash) @@ -177,6 +187,8 @@ FILE *sendmail; int ret; char *sendmail_path = INI_STR("sendmail_path"); + int add_cgi_headers = INI_BOOL("mail_add_cgi_headers"); + char *custom_headers = INI_STR("mail_custom_headers"); char *sendmail_cmd = NULL; if (!sendmail_path) { @@ -227,6 +239,17 @@ #endif fprintf(sendmail, "To: %s\n", to); fprintf(sendmail, "Subject: %s\n", subject); + + if (add_cgi_headers) { + /* Add CGI variables (if available) to the headers */ + env_fprintf("SERVER_NAME", sendmail); + env_fprintf("SCRIPT_NAME", sendmail); + env_fprintf("REMOTE_ADDR", sendmail); + } + + if (custom_headers) + fprintf(sendmail, "%s\n", custom_headers); + if (headers != NULL) { fprintf(sendmail, "%s\n", headers); } @@ -262,7 +285,9 @@ PHP_MINFO_FUNCTION(mail) { char *sendmail_path = INI_STR("sendmail_path"); - + int cgi = INI_BOOL("mail_add_cgi_headers"); + char *custom_headers = INI_STR("mail_custom_headers"); + #ifdef PHP_WIN32 if (!sendmail_path) { php_info_print_table_row(2, "Internal Sendmail Support for Windows", "enabled"); @@ -271,6 +296,8 @@ } #else php_info_print_table_row(2, "Path to sendmail", sendmail_path); + php_info_print_table_row(2, "Add CGI headers", cgi ? "Yes" : "No"); + php_info_print_table_row(2, "Custom headers", custom_headers); #endif } /* }}} */ diff -urN php-4.3.10.orig/main/main.c php-4.3.10/main/main.c --- php-4.3.10.orig/main/main.c Fri Oct 1 16:27:13 2004 +++ php-4.3.10/main/main.c Thu Dec 23 16:27:07 2004 @@ -357,6 +357,8 @@ PHP_INI_ENTRY("precision", "14", PHP_INI_ALL, OnSetPrecision) PHP_INI_ENTRY("sendmail_from", NULL, PHP_INI_ALL, NULL) PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL) + PHP_INI_ENTRY("mail_add_cgi_headers", "0", PHP_INI_SYSTEM, NULL) + PHP_INI_ENTRY("mail_custom_headers", NULL, PHP_INI_SYSTEM, NULL) PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL) PHP_INI_ENTRY("disable_classes", "", PHP_INI_SYSTEM, NULL) --xHFwDpU9dbj6ez1V--