? returnpath_auto.patch
Index: returnpath.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/returnpath/returnpath.info,v
retrieving revision 1.1
diff -f -u -p -r1.1 returnpath.info
--- returnpath.info	24 Apr 2007 12:04:55 -0000	1.1
+++ returnpath.info	4 Apr 2008 13:53:00 -0000
@@ -1,2 +1,3 @@
 name = "Return Path"
 description = Fixed sendmails returnpath in outbound email headers.
+package = Mail
Index: returnpath.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/returnpath/returnpath.module,v
retrieving revision 1.6
diff -f -u -p -r1.6 returnpath.module
--- returnpath.module	22 May 2007 22:21:59 -0000	1.6
+++ returnpath.module	4 Apr 2008 13:53:01 -0000
@@ -8,6 +8,9 @@
  * @author: Mike Carter <www.ixis.co.uk/contact>
  */
 
+/**
+ * Implementation of hook_help().
+ */
 function returnpath_help($section) {
   switch ($section) {
     case 'admin/modules#description':
@@ -15,25 +18,33 @@ function returnpath_help($section) {
   }
 }
 
-
 /*
  * Replaces the default user_mail() and adds the sendmail -f command to the PHP mail() call.
  */
-function drupal_mail_wrapper($mailkey, $to, $subject, $message, $headers) {
-  $matches = array();
-  preg_match("/return-path:?(.*)/i", $headers, $matches);
-  $from = isset($matches[1]) ? "-f{$matches[1]}" : '';
-
+function drupal_mail_wrapper($mailkey, $to, $subject, $message, $from, $headers) {
   $mimeheaders = array();
+  $return_path = '';
   foreach ($headers as $name => $value) {
     $mimeheaders[] = $name .': '. mime_header_encode($value);
+
+    if (strcasecmp('return-path', $name)) {
+      $return_path = $value;
+    }
   }
 
+  // If no explicit Return-path set, use From header and add Return-Path.
+  if (empty($return_path)) {
+    $return_path = $from;
+    $mimeheaders[] = 'Return-Path: '. mime_header_encode($from);
+  }
+
+  $parameters = "-f$return_path";
+
   return mail(
-      $to,
-      mime_header_encode($subject),
-      str_replace("\r", '', $message),
-      join("\n", $mimeheaders),
-      $from
-    );
+    $to,
+    mime_header_encode($subject),
+    str_replace("\r", '', $message),
+    join("\n", $mimeheaders),
+    $parameters
+  );
 }
