[mod] VERP bounce processing

3rd party code for phpList

[mod] VERP bounce processing

Postby tipichris » 9:23pm, Wed 03 Jun, 2009

I've created a patch to provide VERP bounce processing. This currently works only if phpmailer is being used.

An additional parameter has been added to PHPlistMailer which should be the unique id of the user being mailed. Two additional config parameters must be set:

Code: Select all
# Do we use VERP
define ("USE_VERP",1);

# This should match the recipient delimiter / address extension delimiter configured
# in your mail server. For Postfix, this is the value of recipient_delimiter and defaults
# to +. Other systems may vary
define ("VERP_DELIMITER", '+');


The behaviour is as follows: given a value of $message_envelope of phplist-bounce@example.com, a user unique ID of abcdef1234567890 and a message id of 253 the return path will be set to

phplist-bounce+abcdef1234567890===253@example.com

Bounces sent to this address can then easily be identified as relating to a particular user and message.

The system requires that the mail server to which bounces are directed honours the use of address extensions and places messages to phplist-bounce+abcdef1234567890===253 in the phplist-bounce mailbox

I was going to attach this, but it won't let me. So here it is:

Code: Select all
--- lists/admin/processbounces.php.orig   Wed Jun  3 20:00:35 2009
+++ lists/admin/processbounces.php   Wed Jun  3 20:50:55 2009
@@ -94,9 +94,29 @@
 
   $body= imap_body ($link,$num);
   $msgid = 0;$user = 0;

+  if(USE_VERP) {
+    // assume the original return path is in the To: header of the bounce
+    $to = $headerinfo->to;
+   foreach ($to as $rcpt) {
+     $bouncemb = $rcpt->mailbox;
+     list($mebox, $mehost) = explode("@", $GLOBALS["message_envelope"], 2);
+     // does this look like one of our VERP addresses?
+     if (preg_match("/" . $mebox . "/i", $bouncemb)) {
+      list($guff, $verpstr) = explode(VERP_DELIMITER, $bouncemb);
+      if ($verpstr) {
+        list($user, $msgid) = explode('===', $verpstr);      
+        break;
+      }
+     }
+   }
+  }

+  if (!$msgid) {
   preg_match ("/X-MessageId: (.*)/i",$body,$match);
   if (is_array($match) && isset($match[1]))
     $msgid= trim($match[1]);
+  }
   if (!$msgid) {
     # older versions use X-Message
     preg_match ("/X-Message: (.*)/i",$body,$match);
@@ -104,9 +124,11 @@
       $msgid= trim($match[1]);
   }
 
+  if (!$user) {
   preg_match ("/X-ListMember: (.*)/i",$body,$match);
   if (is_array($match) && isset($match[1]))
     $user = trim($match[1]);
+  }
   if (!$user) {
     # older version use X-User
     preg_match ("/X-User: (.*)/i",$body,$match);
--- lists/admin/class.phplistmailer.php.orig   Tue Jun  2 21:36:20 2009
+++ lists/admin/class.phplistmailer.php   Wed Jun  3 20:26:23 2009
@@ -22,7 +22,7 @@
                   'swf'  => 'application/x-shockwave-flash'
                   );
 
-    function PHPlistMailer($messageid,$email) {
+    function PHPlistMailer($messageid,$email,$uid=null) {
     #  parent::PHPMailer();
       parent::SetLanguage('en', dirname(__FILE__) . '/phpmailer/language/');
       $this->addCustomHeader("X-Mailer: phplist v".VERSION);
@@ -51,8 +51,15 @@
       //$ip = gethostbyname($this->Host);
 
       if ($GLOBALS["message_envelope"]) {
+       if ($uid && USE_VERP) {
+        list($mebox, $mehost) = explode("@", $GLOBALS["message_envelope"], 2);
+        $verprp = $mebox . VERP_DELIMITER . $uid . "===" . $messageid .  '@' . $mehost;
+        $this->Sender = $verprp;
+        $this->addCustomHeader("Errors-To: ". $verprp);
+      } else {
         $this->Sender = $GLOBALS["message_envelope"];
         $this->addCustomHeader("Errors-To: ".$GLOBALS["message_envelope"]);
+      }
       }
     }
 
--- lists/admin/sendemaillib.php.orig   Sun May 31 21:58:10 2009
+++ lists/admin/sendemaillib.php   Tue Jun  2 21:54:14 2009
@@ -599,7 +599,7 @@
             "List-Owner: <mailto:".getConfig("admin_address").">"
     ));
   } else {
-    $mail = new PHPlistMailer($messageid,$destinationemail);
+    $mail = new PHPlistMailer($messageid,$destinationemail,$userdata['uniqid']);
     if ($forwardedby) {
       $mail->add_timestamp();
     }

tipichris
phpLister
 
Posts: 11
Joined: 9:03pm, Wed 03 Jun, 2009

Re: [mod] VERP bounce processing

Postby carol » 2:07pm, Thu 04 Jun, 2009

Great contribution!
carol
PL Geek
 
Posts: 138
Joined: 12:57pm, Wed 28 Jan, 2009
Location: São Paulo, Brasil

Re: [mod] VERP bounce processing

Postby awitko » 7:14pm, Wed 21 Oct, 2009

Nice. Anyone applied this or a similar solution to a list-unsubscribe mailto option.

Please see viewtopic.php?f=7&t=24474
awitko
phpList newbie
 
Posts: 3
Joined: 2:33pm, Thu 17 Sep, 2009


Return to Contributions: Plug-ins, Add-ons, Mods

Who is online

Users browsing this forum: No registered users and 0 guests