From bb18f4b02906661c27bf1880386fce0e2501a44c Mon Sep 17 00:00:00 2001
From: Bob Vincent <bobvin@pillars.net>
Date: Fri, 22 Apr 2011 14:28:33 -0400
Subject: [PATCH] Issue #131737 by scor, v1nce, AmrMostafa, Pancho, mrfelton, nvanhove, malc0mn, dhthwy: Return-Path overwritten by the PHP mail() function.

---
 modules/system/system.mail.inc |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/modules/system/system.mail.inc b/modules/system/system.mail.inc
index ef50642c55a9db8c36ceb9a976f5f0d78096a3fc..020c6dba953dc62af4c65dc77ddaaae8b1549037 100644
--- a/modules/system/system.mail.inc
+++ b/modules/system/system.mail.inc
@@ -66,7 +66,11 @@ class DefaultMailSystem implements MailSystemInterface {
     // but some MTAs incorrectly replace LF with CRLF. See #234403.
     $mail_headers = join("\n", $mimeheaders);
     if (isset($message['Return-Path']) && !ini_get('safe_mode')) {
-      $mail_result = mail(
+      $old_from = ini_get('sendmail_from');
+      // On Windows PHP will use the value of sendmail_from for the Return-Path
+      // header.
+      ini_set('sendmail_from', $message['Return-Path']);
+      $mail_result = @mail(
         $message['to'],
         $mail_subject,
         $mail_body,
@@ -74,12 +78,17 @@ class DefaultMailSystem implements MailSystemInterface {
         // Pass the Return-Path via sendmail's -f command.
         '-f ' . $message['Return-Path']
       );
+
+      if (!empty($old_from)) {
+        // Set sendmail_from back to its previous value.
+        ini_set('sendmail_from', $old_from);
+      }
     }
     else {
       // The optional $additional_parameters argument to mail() is not allowed
       // if safe_mode is enabled. Passing any value throws a PHP warning and
       // makes mail() return FALSE.
-      $mail_result = mail(
+      $mail_result = @mail(
         $message['to'],
         $mail_subject,
         $mail_body,
-- 
1.7.1

