Skip to content

Commit e77a1db

Browse files
tomsommernikic
authored andcommitted
Fix bug #69061
Make mail.log append correct PHP_EOL and remove timestamp when sending to syslog.
1 parent 4bf7ef0 commit e77a1db

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ PHP NEWS
4545
. Fixed bug #72974 (imap is undefined service on AIX). (matthieu.sarter)
4646
. Fixed bug #72979 (money_format stores wrong length AIX). (matthieu.sarter)
4747
. Fixed bug #73374 (intval() with base 0 should detect binary). (Leigh)
48+
. Fixed bug #69061 (mail.log = syslog contains double information).
49+
(Tom Sommer)
4850

4951
- ZIP:
5052
. Fixed bug #70103 (ZipArchive::addGlob ignores remove_all_path option). (cmb,

ext/standard/mail.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -286,34 +286,35 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
286286
return val; \
287287

288288
if (mail_log && *mail_log) {
289-
char *tmp;
290-
time_t curtime;
291-
size_t l;
292-
zend_string *date_str;
289+
char *logline;
293290

294-
time(&curtime);
295-
date_str = php_format_date("d-M-Y H:i:s e", 13, curtime, 1);
296-
297-
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);
298-
299-
zend_string_free(date_str);
291+
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);
300292

301293
if (hdr) {
302-
php_mail_log_crlf_to_spaces(tmp);
294+
php_mail_log_crlf_to_spaces(logline);
303295
}
304296

305297
if (!strcmp(mail_log, "syslog")) {
306-
/* Drop the final space when logging to syslog. */
307-
tmp[l - 1] = 0;
308-
php_mail_log_to_syslog(tmp);
309-
}
310-
else {
311-
/* Convert the final space to a newline when logging to file. */
312-
tmp[l - 1] = '\n';
313-
php_mail_log_to_file(mail_log, tmp, l);
298+
php_mail_log_to_syslog(logline);
299+
} else {
300+
/* Add date when logging to file */
301+
char *tmp;
302+
time_t curtime;
303+
zend_string *date_str;
304+
size_t len;
305+
306+
307+
time(&curtime);
308+
date_str = php_format_date("d-M-Y H:i:s e", 13, curtime, 1);
309+
len = spprintf(&tmp, 0, "[%s] %s%s", date_str->val, logline, PHP_EOL);
310+
311+
php_mail_log_to_file(mail_log, tmp, len);
312+
313+
zend_string_free(date_str);
314+
efree(tmp);
314315
}
315316

316-
efree(tmp);
317+
efree(logline);
317318
}
318319

319320
if (PG(mail_x_header)) {

0 commit comments

Comments
 (0)