Imap send #52

Closed
wants to merge 3 commits into from

3 participants

@Keloran

This is a cleanup of my imap_mail patch,

it attempts to fix the following bug
https://bugs.php.net/bug.php?id=30688

@johannes johannes commented on the diff Apr 11, 2012
ext/imap/php_imap.c
@@ -4016,18 +4016,64 @@ 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;
@johannes
php.net member

Declarations have to go first in the block to be compliant with ANSI C. Either move the declarations up or put this in a block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@johannes johannes commented on the diff Apr 11, 2012
ext/imap/php_imap.c
- 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);
@johannes
php.net member

Where does the 50 come from?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@johannes johannes commented on the diff Apr 11, 2012
ext/imap/php_imap.c
+
+ 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);
@johannes
php.net member

Instead of using the magic constant 3 one might use sizeof(" -f")-1. If the above magic 50 is fixed one might probably calculate the offset in append_sendmail_path and use strncpy here, too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@johannes johannes commented on the diff Apr 11, 2012
ext/imap/php_imap.c
+ 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_path, 0, "%s %s", sendmail_path, extra_cmd);
@johannes
php.net member

won't this change INI_STR("sendmail_path")? (at least if !rpath || !rpath[0] )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@smalyshev

Looks like this patch is abandoned - no response to comments for a year. I am closing this pull, if somebody is interested in taking it to completion please reopen it.

@php-pulls

Comment on behalf of stas at php.net:

closing

@php-pulls php-pulls closed this Jul 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment