Skip to content

Commit 3cc121c

Browse files
committed
ext/standard/mail.c: Some refactoring to php_mail()
1 parent 069e0f3 commit 3cc121c

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

ext/standard/mail.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ PHP_FUNCTION(mail)
265265
headers_str = php_trim(headers_str, NULL, 0, 2);
266266
} else if (headers_ht) {
267267
headers_str = php_mail_build_headers(headers_ht);
268-
if (EG(exception)) {
268+
if (headers_str == NULL) {
269269
RETURN_THROWS();
270270
}
271271
}
@@ -408,14 +408,9 @@ static int php_mail_detect_multiple_crlf(const char *hdr) {
408408

409409

410410
/* {{{ php_mail */
411-
PHPAPI int php_mail(const char *to, const char *subject, const char *message, const char *headers, const char *extra_cmd)
411+
PHPAPI bool php_mail(const char *to, const char *subject, const char *message, const char *headers, const char *extra_cmd)
412412
{
413-
#ifdef PHP_WIN32
414-
int tsm_err;
415-
char *tsm_errmsg = NULL;
416-
#endif
417413
FILE *sendmail;
418-
int ret;
419414
char *sendmail_path = INI_STR("sendmail_path");
420415
char *sendmail_cmd = NULL;
421416
char *mail_log = INI_STR("mail.log");
@@ -464,7 +459,7 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co
464459
}
465460

466461
if (EG(exception)) {
467-
MAIL_RET(0);
462+
MAIL_RET(false);
468463
}
469464

470465
char *line_sep = PG(mail_mixed_lf_and_crlf) ? "\n" : "\r\n";
@@ -486,11 +481,14 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co
486481

487482
if (hdr && php_mail_detect_multiple_crlf(hdr)) {
488483
php_error_docref(NULL, E_WARNING, "Multiple or malformed newlines found in additional_header");
489-
MAIL_RET(0);
484+
MAIL_RET(false);
490485
}
491486

492487
if (!sendmail_path) {
493488
#ifdef PHP_WIN32
489+
int tsm_err;
490+
char *tsm_errmsg = NULL;
491+
494492
/* handle old style win smtp sending */
495493
if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, hdr, subject, to, message, NULL, NULL, NULL) == FAILURE) {
496494
if (tsm_errmsg) {
@@ -499,11 +497,11 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co
499497
} else {
500498
php_error_docref(NULL, E_WARNING, "%s", GetSMErrorText(tsm_err));
501499
}
502-
MAIL_RET(0);
500+
MAIL_RET(false);
503501
}
504-
MAIL_RET(1);
502+
MAIL_RET(true);
505503
#else
506-
MAIL_RET(0);
504+
MAIL_RET(false);
507505
#endif
508506
}
509507
if (extra_cmd != NULL) {
@@ -547,7 +545,7 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co
547545
signal(SIGCHLD, sig_handler);
548546
}
549547
#endif
550-
MAIL_RET(0);
548+
MAIL_RET(false);
551549
}
552550
#endif
553551
fprintf(sendmail, "To: %s%s", to, line_sep);
@@ -556,7 +554,7 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co
556554
fprintf(sendmail, "%s%s", hdr, line_sep);
557555
}
558556
fprintf(sendmail, "%s%s%s", line_sep, message, line_sep);
559-
ret = pclose(sendmail);
557+
int ret = pclose(sendmail);
560558

561559
#if PHP_SIGCHILD
562560
if (sig_handler) {
@@ -576,9 +574,9 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co
576574
#endif
577575
#endif
578576
{
579-
MAIL_RET(0);
577+
MAIL_RET(false);
580578
} else {
581-
MAIL_RET(1);
579+
MAIL_RET(true);
582580
}
583581
} else {
584582
php_error_docref(NULL, E_WARNING, "Could not execute mail delivery program '%s'", sendmail_path);
@@ -587,10 +585,10 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co
587585
signal(SIGCHLD, sig_handler);
588586
}
589587
#endif
590-
MAIL_RET(0);
588+
MAIL_RET(false);
591589
}
592590

593-
MAIL_RET(1); /* never reached */
591+
MAIL_RET(true); /* never reached */
594592
}
595593
/* }}} */
596594

ext/standard/php_mail.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
PHP_MINFO_FUNCTION(mail);
2121

2222
PHPAPI zend_string *php_mail_build_headers(HashTable *headers);
23-
PHPAPI extern int php_mail(const char *to, const char *subject, const char *message, const char *headers, const char *extra_cmd);
23+
PHPAPI extern bool php_mail(const char *to, const char *subject, const char *message, const char *headers, const char *extra_cmd);
2424

2525
#define PHP_MAIL_BUILD_HEADER_CHECK(target, s, key, val) \
2626
do { \

0 commit comments

Comments
 (0)