Skip to content

Commit 36ba96e

Browse files
committed
Merge branch 'PHP-7.1'
2 parents a3115b0 + e77a1db commit 36ba96e

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

ext/standard/mail.c

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

491491
if (mail_log && *mail_log) {
492-
char *tmp;
493-
time_t curtime;
494-
size_t l;
495-
zend_string *date_str;
492+
char *logline;
496493

497-
time(&curtime);
498-
date_str = php_format_date("d-M-Y H:i:s e", 13, curtime, 1);
499-
500-
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);
501-
502-
zend_string_free(date_str);
494+
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);
503495

504496
if (hdr) {
505-
php_mail_log_crlf_to_spaces(tmp);
497+
php_mail_log_crlf_to_spaces(logline);
506498
}
507499

508500
if (!strcmp(mail_log, "syslog")) {
509-
/* Drop the final space when logging to syslog. */
510-
tmp[l - 1] = 0;
511-
php_mail_log_to_syslog(tmp);
512-
}
513-
else {
514-
/* Convert the final space to a newline when logging to file. */
515-
tmp[l - 1] = '\n';
516-
php_mail_log_to_file(mail_log, tmp, l);
501+
php_mail_log_to_syslog(logline);
502+
} else {
503+
/* Add date when logging to file */
504+
char *tmp;
505+
time_t curtime;
506+
zend_string *date_str;
507+
size_t len;
508+
509+
510+
time(&curtime);
511+
date_str = php_format_date("d-M-Y H:i:s e", 13, curtime, 1);
512+
len = spprintf(&tmp, 0, "[%s] %s%s", date_str->val, logline, PHP_EOL);
513+
514+
php_mail_log_to_file(mail_log, tmp, len);
515+
516+
zend_string_free(date_str);
517+
efree(tmp);
517518
}
518519

519-
efree(tmp);
520+
efree(logline);
520521
}
521522

522523
if (PG(mail_x_header)) {

0 commit comments

Comments
 (0)