From 94a89bf480fae2b8c4353ab7a9f21f705e237946 Mon Sep 17 00:00:00 2001 From: Martin Jansen Date: Mon, 24 Dec 2012 11:11:28 +0100 Subject: [PATCH 1/2] Add a timestamp to the mail log. This patch is loosely based on the one in bug #52126 but instead of using a UNIX timestamp it uses the date format also being used by error_log et al. --- ext/standard/mail.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ext/standard/mail.c b/ext/standard/mail.c index 364f7fc3999a..6d2a21f589d3 100644 --- a/ext/standard/mail.c +++ b/ext/standard/mail.c @@ -21,10 +21,12 @@ #include #include #include +#include #include "php.h" #include "ext/standard/info.h" #include "ext/standard/php_string.h" #include "ext/standard/basic_functions.h" +#include "ext/date/php_date.h" #if HAVE_SYSEXITS_H #include @@ -246,8 +248,15 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char return val; \ if (mail_log && *mail_log) { - char *tmp; - int l = spprintf(&tmp, 0, "mail() on [%s:%d]: To: %s -- Headers: %s\n", zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C), to, hdr ? hdr : ""); + char *tmp, *date_str; + time_t curtime; + + time(&curtime); + date_str = php_format_date("d-M-Y H:i:s e", 13, curtime, 1 TSRMLS_CC); + + int l = spprintf(&tmp, 0, "[%s] mail() on [%s:%d]: To: %s -- Headers: %s\n", date_str, zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C), to, hdr ? hdr : ""); + + efree(date_str); if (hdr) { php_mail_log_crlf_to_spaces(tmp); From 6ccabf8d3619b149d8117b49f4fbd3e5d6592888 Mon Sep 17 00:00:00 2001 From: Martin Jansen Date: Sun, 6 Jan 2013 08:59:10 +0100 Subject: [PATCH 2/2] Add unit test for mail.log ini setting. --- ext/standard/tests/mail/mail_log.phpt | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 ext/standard/tests/mail/mail_log.phpt diff --git a/ext/standard/tests/mail/mail_log.phpt b/ext/standard/tests/mail/mail_log.phpt new file mode 100644 index 000000000000..86346ec307ef --- /dev/null +++ b/ext/standard/tests/mail/mail_log.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test mail() function : mail.log ini setting +--INI-- +sendmail_path=tee /tmp/mail.out >/dev/null +mail.log = /tmp/mail.log +--SKIPIF-- + +--FILE-- + 0); +clearstatcache(); + +echo file_get_contents($logfile); +?> +Done +--CLEAN-- + +--EXPECTF-- +bool(true) +bool(true) +bool(true) +[%d-%s-%d %d:%d:%d UTC] mail() on [%smail_log.php:%d]: To: test@example.com -- Headers: X-Test: 1 +Done