From dd19478e010f417640a11d66d5300efd25286032 Mon Sep 17 00:00:00 2001 From: Keloran Date: Wed, 11 Apr 2012 09:28:02 +0100 Subject: [PATCH 1/3] fix imap_send -r param not actually getting used in the function --- ext/imap/php_imap.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index 32161f3b6c17..2a3f7b148edc 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -4016,7 +4016,40 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char * if (!INI_STR("sendmail_path")) { return 0; } - sendmail = popen(INI_STR("sendmail_path"), "w"); + + char *sendmail_path = INI_STR("sendmail_path"); + char *appended_sendmail_path = NULL; + int rpath_length = strlen(rpath); + int sendmail_length = strlen(sendmail_path); + char *force_extra_parameters = INI_STR("mail.force_extra_parameters"); + char *extra_cmd = NULL; + + if (force_extra_parameters) { + extra_cmd = php_escape_shell_cmd(force_extra_parameters); + } + + if (rpath && rpath[0]) { + appended_sendmail_path = emalloc(sendmail_length + 3 + rpath_length + 1); + strncpy(appended_sendmail_path, sendmail_path, 50); + strncat(appended_sendmail_path, " -f", 3); + strncat(appended_sendmail_path, rpath, rpath_length); + sendmail_path = appended_sendmail_path; + } + + if (extra_cmd) { + spprintf(&sendmail_p[ath, 0, "%s %s", sendmail_path, extra_cmd); + } + + sendmail = popen(sendmail_path, "w"); + + if (appended_sendmail_path) { + efree(appended_sendmail_path); + } + + if (extra_cmd) { + efree(extra_cmd); + } + if (sendmail) { if (rpath && rpath[0]) fprintf(sendmail, "From: %s\n", rpath); fprintf(sendmail, "To: %s\n", to); From 1b7d73d640d552b0307debde11c7445dfa57a1ff Mon Sep 17 00:00:00 2001 From: Keloran Date: Wed, 11 Apr 2012 09:32:43 +0100 Subject: [PATCH 2/3] fix for spelling mistake --- ext/imap/php_imap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index 2a3f7b148edc..12ddc38e18d5 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -4037,7 +4037,7 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char * } if (extra_cmd) { - spprintf(&sendmail_p[ath, 0, "%s %s", sendmail_path, extra_cmd); + spprintf(&sendmail_path, 0, "%s %s", sendmail_path, extra_cmd); } sendmail = popen(sendmail_path, "w"); From 5c292567447a95e09050f93fba535327db485818 Mon Sep 17 00:00:00 2001 From: Keloran Date: Wed, 11 Apr 2012 14:02:31 +0100 Subject: [PATCH 3/3] add braces to bring in line with standard --- ext/imap/php_imap.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index 12ddc38e18d5..d8a982a91c5d 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -4051,16 +4051,29 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char * } if (sendmail) { - if (rpath && rpath[0]) fprintf(sendmail, "From: %s\n", rpath); + if (rpath && rpath[0]) { + fprintf(sendmail, "From: %s\n", rpath); + } + fprintf(sendmail, "To: %s\n", to); - if (cc && cc[0]) fprintf(sendmail, "Cc: %s\n", cc); - if (bcc && bcc[0]) fprintf(sendmail, "Bcc: %s\n", bcc); + + if (cc && cc[0]) { + fprintf(sendmail, "Cc: %s\n", cc); + } + + if (bcc && bcc[0]) { + fprintf(sendmail, "Bcc: %s\n", bcc); + } + fprintf(sendmail, "Subject: %s\n", subject); + if (headers != NULL) { fprintf(sendmail, "%s\n", headers); } + fprintf(sendmail, "\n%s\n", message); ret = pclose(sendmail); + if (ret == -1) { return 0; } else {