Penpals and Envelope From != Header From

Stef Simoens stef+au at bgs.org
Tue Jun 12 23:07:52 CEST 2012


Hello,

I just registered on this list, so hello to all of you :-)
I use Amavis and I love the "penpals" feature. 

Penpals works great to catch "bounces", because undeliverable e-mail will always be sent to the "Return-Path" / Envelope From.
It also works great in normal sending/replying (because the "Envelope From" is equal to the "Header From").

However, penpals doesn't work when the "Envelope From" differs from the "From" or the "Reply-To" e-mail headers.
Currently, Amavis only stores the "Envelope From" (as msgs.sid) and the recipients of a message (as msgsrcpt.rid). The "Header From"/"Header Reply-To" is not stored.
A (good) e-mail client should use the Reply-To (if present) or the From when hitting the "Reply" button; and Amavis will not find any penpal link because the "recipient" of the reply (recipient id/rid of the incoming e-mail) isn't equal to the "envelope from" (sid of the original outgoing e-mail) and the current SQL query checks if the recipient of the incoming reply equals the sender of the original outgoing e-mail.
I'm not sure if this is intentional, or just "not yet developed".

I wrote a small patch that adds the check if the sender of the reply is the recipient of the outgoing e-mail. I know that this might not be the case in case of forwarding, but it's just to help the penpals algorithm a bit more.
Tested with my local set-up.
The SQL impact should be limited, as both sid and rid are indexed fields.

--- /usr/sbin/amavisd.orig	2012-06-04 00:17:50.000000000 +0200
+++ /usr/sbin/amavisd	2012-06-12 21:43:58.380743445 +0200
@@ -1324,7 +1324,7 @@
     'sel_penpals_msgid' =>  # with a nonempty list of message-id references
       "SELECT msgs.time_num, msgs.mail_id, subject, message_id, rid".
       " FROM msgs JOIN msgrcpt USING (partition_tag,mail_id)".
-      " WHERE sid=? AND msgs.content!='V' AND ds='P' AND message_id IN (%m)".
+      " WHERE (sid=? OR rid=?) AND msgs.content!='V' AND ds='P' AND message_id IN (%m)".
         " AND rid!=sid".
       " ORDER BY rid=? DESC, msgs.time_num DESC",  # LIMIT 1
   );
@@ -21784,7 +21784,7 @@
   if (defined($sel_penpals_msgid) && @$message_id_list && defined($sid)) {
     # list of refs to Message-ID is nonempty, try reference or recipient match
     my($n) = scalar(@$message_id_list);  # number of keys
-    my(@args) = ($sid,$rid);  my(@pos_args);  local($1);
+    my(@args) = ($sid,$rid,$rid);  my(@pos_args);  local($1);
     my($sel_taint) = substr($sel_penpals_msgid,0,0);   # taintedness
     $sel_penpals_msgid =~
            s{ ( %m | \? ) }  # substitute %m for keys and ? for next arg

A better would probably be to have Amavis store the (calculated) From/Reply-To like it stores the envelope-from and the recipients. However, I'm not familiar enough with the code for that. I would be willing to work on that, if this feature would be appreciated.

Kind regards

--
Stef Simoens
BGS.org hostmaster


More information about the amavis-users mailing list