Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Imap send #52

Closed
wants to merge 3 commits into from

4 participants

Keloran Stanislav Malyshev Account for PHP Pull Requests Johannes Schlüter
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 Schlüter johannes commented on the diff April 11, 2012
ext/imap/php_imap.c
@@ -4016,18 +4016,64 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char *
4016 4016
 	if (!INI_STR("sendmail_path")) {
4017 4017
 		return 0;
4018 4018
 	}
4019  
-	sendmail = popen(INI_STR("sendmail_path"), "w");
  4019
+	
  4020
+	char *sendmail_path				= INI_STR("sendmail_path");
  4021
+	char *appended_sendmail_path	= NULL;
  4022
+	int	rpath_length				= strlen(rpath);
  4023
+	int sendmail_length				= strlen(sendmail_path);
  4024
+	char *force_extra_parameters	= INI_STR("mail.force_extra_parameters");
  4025
+	char *extra_cmd					= NULL;
1
Johannes Schlüter Owner
johannes added a note April 11, 2012

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 Schlüter johannes commented on the diff April 11, 2012
ext/imap/php_imap.c
((4 lines not shown))
4019  
-	sendmail = popen(INI_STR("sendmail_path"), "w");
  4019
+	
  4020
+	char *sendmail_path				= INI_STR("sendmail_path");
  4021
+	char *appended_sendmail_path	= NULL;
  4022
+	int	rpath_length				= strlen(rpath);
  4023
+	int sendmail_length				= strlen(sendmail_path);
  4024
+	char *force_extra_parameters	= INI_STR("mail.force_extra_parameters");
  4025
+	char *extra_cmd					= NULL;
  4026
+	
  4027
+	if (force_extra_parameters) {
  4028
+		extra_cmd	= php_escape_shell_cmd(force_extra_parameters);
  4029
+	}
  4030
+	
  4031
+	if (rpath && rpath[0]) {
  4032
+		appended_sendmail_path	= emalloc(sendmail_length + 3 + rpath_length + 1);
  4033
+		strncpy(appended_sendmail_path, sendmail_path, 50);
1
Johannes Schlüter Owner
johannes added a note April 11, 2012

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 Schlüter johannes commented on the diff April 11, 2012
ext/imap/php_imap.c
((5 lines not shown))
  4019
+	
  4020
+	char *sendmail_path				= INI_STR("sendmail_path");
  4021
+	char *appended_sendmail_path	= NULL;
  4022
+	int	rpath_length				= strlen(rpath);
  4023
+	int sendmail_length				= strlen(sendmail_path);
  4024
+	char *force_extra_parameters	= INI_STR("mail.force_extra_parameters");
  4025
+	char *extra_cmd					= NULL;
  4026
+	
  4027
+	if (force_extra_parameters) {
  4028
+		extra_cmd	= php_escape_shell_cmd(force_extra_parameters);
  4029
+	}
  4030
+	
  4031
+	if (rpath && rpath[0]) {
  4032
+		appended_sendmail_path	= emalloc(sendmail_length + 3 + rpath_length + 1);
  4033
+		strncpy(appended_sendmail_path, sendmail_path, 50);
  4034
+		strncat(appended_sendmail_path, " -f", 3);
1
Johannes Schlüter Owner
johannes added a note April 11, 2012

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 Schlüter johannes commented on the diff April 11, 2012
ext/imap/php_imap.c
((11 lines not shown))
  4025
+	char *extra_cmd					= NULL;
  4026
+	
  4027
+	if (force_extra_parameters) {
  4028
+		extra_cmd	= php_escape_shell_cmd(force_extra_parameters);
  4029
+	}
  4030
+	
  4031
+	if (rpath && rpath[0]) {
  4032
+		appended_sendmail_path	= emalloc(sendmail_length + 3 + rpath_length + 1);
  4033
+		strncpy(appended_sendmail_path, sendmail_path, 50);
  4034
+		strncat(appended_sendmail_path, " -f", 3);
  4035
+		strncat(appended_sendmail_path, rpath, rpath_length);
  4036
+		sendmail_path			= appended_sendmail_path;
  4037
+	}
  4038
+	
  4039
+	if (extra_cmd) {
  4040
+		spprintf(&sendmail_path, 0, "%s %s", sendmail_path, extra_cmd);
1
Johannes Schlüter Owner
johannes added a note April 11, 2012

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
Stanislav Malyshev

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.

Account for PHP Pull Requests
Collaborator

Comment on behalf of stas at php.net:

closing

Account for PHP Pull Requests php-pulls closed this July 21, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 50 additions and 4 deletions. Show diff stats Hide diff stats

  1. 54  ext/imap/php_imap.c
54  ext/imap/php_imap.c
@@ -4016,18 +4016,64 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char *
4016 4016
 	if (!INI_STR("sendmail_path")) {
4017 4017
 		return 0;
4018 4018
 	}
4019  
-	sendmail = popen(INI_STR("sendmail_path"), "w");
  4019
+	
  4020
+	char *sendmail_path				= INI_STR("sendmail_path");
  4021
+	char *appended_sendmail_path	= NULL;
  4022
+	int	rpath_length				= strlen(rpath);
  4023
+	int sendmail_length				= strlen(sendmail_path);
  4024
+	char *force_extra_parameters	= INI_STR("mail.force_extra_parameters");
  4025
+	char *extra_cmd					= NULL;
  4026
+	
  4027
+	if (force_extra_parameters) {
  4028
+		extra_cmd	= php_escape_shell_cmd(force_extra_parameters);
  4029
+	}
  4030
+	
  4031
+	if (rpath && rpath[0]) {
  4032
+		appended_sendmail_path	= emalloc(sendmail_length + 3 + rpath_length + 1);
  4033
+		strncpy(appended_sendmail_path, sendmail_path, 50);
  4034
+		strncat(appended_sendmail_path, " -f", 3);
  4035
+		strncat(appended_sendmail_path, rpath, rpath_length);
  4036
+		sendmail_path			= appended_sendmail_path;
  4037
+	}
  4038
+	
  4039
+	if (extra_cmd) {
  4040
+		spprintf(&sendmail_path, 0, "%s %s", sendmail_path, extra_cmd);
  4041
+	}
  4042
+	
  4043
+	sendmail = popen(sendmail_path, "w");
  4044
+	
  4045
+	if (appended_sendmail_path) {
  4046
+		efree(appended_sendmail_path);
  4047
+	}
  4048
+	
  4049
+	if (extra_cmd) {
  4050
+		efree(extra_cmd);
  4051
+	}
  4052
+	
4020 4053
 	if (sendmail) {
4021  
-		if (rpath && rpath[0]) fprintf(sendmail, "From: %s\n", rpath);
  4054
+		if (rpath && rpath[0]) {
  4055
+            fprintf(sendmail, "From: %s\n", rpath);
  4056
+        }
  4057
+
4022 4058
 		fprintf(sendmail, "To: %s\n", to);
4023  
-		if (cc && cc[0]) fprintf(sendmail, "Cc: %s\n", cc);
4024  
-		if (bcc && bcc[0]) fprintf(sendmail, "Bcc: %s\n", bcc);
  4059
+
  4060
+		if (cc && cc[0]) {
  4061
+            fprintf(sendmail, "Cc: %s\n", cc);
  4062
+        }
  4063
+
  4064
+		if (bcc && bcc[0]) {
  4065
+            fprintf(sendmail, "Bcc: %s\n", bcc);
  4066
+        }
  4067
+
4025 4068
 		fprintf(sendmail, "Subject: %s\n", subject);
  4069
+
4026 4070
 		if (headers != NULL) {
4027 4071
 			fprintf(sendmail, "%s\n", headers);
4028 4072
 		}
  4073
+
4029 4074
 		fprintf(sendmail, "\n%s\n", message);
4030 4075
 		ret = pclose(sendmail);
  4076
+
4031 4077
 		if (ret == -1) {
4032 4078
 			return 0;
4033 4079
 		} else {
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.