php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #30688
Patch patch2 revision 2011-08-22 13:18 UTC by ava3ar at gmail dot com
Patch Patch-by-Keloran-ava3ar-at-gmail-com revision 2011-08-04 16:18 UTC by pajoye@php.net

Patch patch2 for IMAP related Bug #30688

Patch version 2011-08-22 13:18 UTC

Return to Bug #30688 | Download this patch
Patch Revisions:

Developer: ava3ar@gmail.com

Index: ext/imap/php_imap.c
===================================================================
--- ext/imap/php_imap.c	(revision 314999)
+++ ext/imap/php_imap.c	(working copy)
@@ -4013,15 +4013,50 @@
 	}
 	PHP_IMAP_CLEAN;
 #else
-	if (!INI_STR("sendmail_path")) {
-		return 0;
-	}
-	sendmail = popen(INI_STR("sendmail_path"), "w");
+	 /** Used to make return-path work **/
+        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;
+
+	/* Sendmail cant be found so ignore anything */
+	if (!sendmail_path) { return 0; }
+
+	/* Extra params set in the ini, it needs escaping */
+	if (force_extra_parameters) { extra_cmd = php_escape_shell_cmd(force_extra_parameters); }
+
+        /* Return Path
+	 * This is mainly because force_extra only allows 1 fixed return path
+	 * where as with the rpath option, it can be set dynamiclly
+	 */
+        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, 30);
+            sendmail_path = appended_sendmail_path;
+        }
+
+	/* Add the extra commands from force params, 
+	 * this is used if you want multiple 
+ 	 */
+	if (extra_cmd) { spprintf(&sendmail_path, 0, "%s %s", sendmail_path, extra_cmd); }
+
+        sendmail = popen(sendmail_path, "w");
+	
+	/* Free the memory used by the appeneded sendmail path */
+	if (appended_sendmail_path) { efree(appended_sendmail_path); }
+
+	/* Free the extra cmd used by force params */
+	if (extra_cmd) { efree(extra_cmd); }
+
 	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);
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 20:02:01 2014 UTC