Index: includes/mail.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/mail.inc,v
retrieving revision 1.17
diff -u -r1.17 mail.inc
--- includes/mail.inc	7 Nov 2008 16:59:36 -0000	1.17
+++ includes/mail.inc	13 Dec 2008 15:42:15 -0000
@@ -102,10 +102,10 @@
     'X-Mailer'                  => 'Drupal'
   );
   if ($default_from) {
-    // To prevent e-mail from looking like spam, the addresses in the Sender and
-    // Return-Path headers should have a domain authorized to use the originating
-    // SMTP server. Errors-To is redundant, but shouldn't hurt.
-    $headers['From'] = $headers['Sender'] = $headers['Return-Path'] = $headers['Errors-To'] = $default_from;
+    // To prevent e-mail from looking like spam, 'Sender' and 'Return-Path'
+    // should be addresses of a domain authorized to use the originating
+    // SMTP server. 'Errors-To' is redundant, but shouldn't hurt.
+    $headers['From'] = $headers['Sender'] = $headers['Errors-To'] = $headers['Return-Path'] = $default_from;
   }
   if ($from) {
     $headers['From'] = $from;
@@ -122,6 +122,16 @@
   // Invoke hook_mail_alter() to allow all modules to alter the resulting e-mail.
   drupal_alter('mail', $message);
 
+  // If 'Return-Path' isn't already set in php.ini, we pass it separately
+  // as an additional parameter instead of in the header.
+  if (isset($headers['Return-Path'])) {
+    $return_path_set = strpos(ini_get('sendmail_path'), ' -f');
+    if (!$return_path_set) {
+      $message['Return-Path'] = $headers['Return-Path'];
+      unset($headers['Return-Path']);
+    }
+  }
+
   // Concatenate and wrap the e-mail body.
   $message['body'] = is_array($message['body']) ? drupal_wrap_mail(implode("\n\n", $message['body'])) : drupal_wrap_mail($message['body']);
 
@@ -189,7 +199,9 @@
       str_replace("\r", '', $message['body']),
       // For headers, PHP's API suggests that we use CRLF normally,
       // but some MTAs incorrecly replace LF with CRLF. See #234403.
-      join("\n", $mimeheaders)
+      join("\n", $mimeheaders),
+      // Pass the Return-Path via sendmail's -f command.
+      $message['Return-Path'] ? '-f ' . $message['Return-Path'] : ''
     );
   }
 }
