]> granicus.if.org Git - php/commitdiff
Fix bug #69061
authorTom Sommer <tomsommer@users.noreply.github.com>
Sat, 14 Jan 2017 12:51:12 +0000 (13:51 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 14 Jan 2017 12:53:09 +0000 (13:53 +0100)
Make mail.log append correct PHP_EOL and remove timestamp when
sending to syslog.

NEWS
ext/standard/mail.c

diff --git a/NEWS b/NEWS
index f1b065d020e0247b057a659d43b066f960236ea1..a9d0bdb716ee6a41650e10bddf3044da62712b09 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -45,6 +45,8 @@ PHP                                                                        NEWS
   . Fixed bug #72974 (imap is undefined service on AIX). (matthieu.sarter)
   . Fixed bug #72979 (money_format stores wrong length AIX). (matthieu.sarter)
   . Fixed bug #73374 (intval() with base 0 should detect binary). (Leigh)
+  . Fixed bug #69061 (mail.log = syslog contains double information).
+    (Tom Sommer)
 
 - ZIP:
   . Fixed bug #70103 (ZipArchive::addGlob ignores remove_all_path option). (cmb,
index cce3c7d4ca2b4ef270bb77fd0fdb64fa2653ef2b..26272cd76df9134e8cb5fc027ce2db3898e92dd8 100644 (file)
@@ -286,34 +286,35 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
        return val;     \
 
        if (mail_log && *mail_log) {
-               char *tmp;
-               time_t curtime;
-               size_t l;
-               zend_string *date_str;
+               char *logline;
 
-               time(&curtime);
-               date_str = php_format_date("d-M-Y H:i:s e", 13, curtime, 1);
-
-               l = spprintf(&tmp, 0, "[%s] mail() on [%s:%d]: To: %s -- Headers: %s -- Subject: %s\n", ZSTR_VAL(date_str), zend_get_executed_filename(), zend_get_executed_lineno(), to, hdr ? hdr : "", subject);
-
-               zend_string_free(date_str);
+               spprintf(&logline, 0, "mail() on [%s:%d]: To: %s -- Headers: %s -- Subject: %s", zend_get_executed_filename(), zend_get_executed_lineno(), to, hdr ? hdr : "", subject);
 
                if (hdr) {
-                       php_mail_log_crlf_to_spaces(tmp);
+                       php_mail_log_crlf_to_spaces(logline);
                }
 
                if (!strcmp(mail_log, "syslog")) {
-                       /* Drop the final space when logging to syslog. */
-                       tmp[l - 1] = 0;
-                       php_mail_log_to_syslog(tmp);
-               }
-               else {
-                       /* Convert the final space to a newline when logging to file. */
-                       tmp[l - 1] = '\n';
-                       php_mail_log_to_file(mail_log, tmp, l);
+                       php_mail_log_to_syslog(logline);
+               } else {
+                       /* Add date when logging to file */
+                       char *tmp;
+                       time_t curtime;
+                       zend_string *date_str;
+                       size_t len;
+                       
+                       
+                       time(&curtime);
+                       date_str = php_format_date("d-M-Y H:i:s e", 13, curtime, 1);
+                       len = spprintf(&tmp, 0, "[%s] %s%s", date_str->val, logline, PHP_EOL);
+                       
+                       php_mail_log_to_file(mail_log, tmp, len);
+                       
+                       zend_string_free(date_str);
+                       efree(tmp);
                }
 
-               efree(tmp);
+               efree(logline);
        }
 
        if (PG(mail_x_header)) {