procmail
[Top] [All Lists]

Re: Grabbing a field in a variable and then matching on this variable...

2000-02-10 04:10:07
On 10 Feb 2000 11:41:53 +0100, Francois Felix Ingrand <felix(_at_)laas(_dot_)fr>
wrote:
:0
* ^Delivered-To:(_dot_)*(_at_)foo\(_dot_)com
{
DELIVERED=`formail -xDelivered-To:`   
        :0 fh
     | formail -i "Delivered-To:"
     :0
     * $DELIVERED matches bar(_at_)foo(_dot_)com
     !  a
     * $DELIVERED matches bloo(_at_)foo(_dot_)com
     :0
     !  b
...
}
So my basic question is: can I have a rule to match a procmail variable
against a regexp.

Yes, and the solution is slightly simpler than what you have, although
the syntax is a bit awkward.

The key to it all is the \/ grabbing operator. With that, we don't
need the call to formail, and if we turn your pseudocode into actual
Procmail syntax, we get

    :0 # The \/ says, "if we have a match, save the part that follows"
    * ^Delivered-To:[   ]*\/[^  ]+(_at_)foo\(_dot_)com
    {
        # The string that matched the regex after \/ is now in $MATCH

        # Keep a copy in DELIVERED
        DELIVERED=$MATCH

        # Rename the Delivered-To: field to Old-Delivered-To:
        :0fwh  # added a w flag -- always a good idea
        | formail -i "Delivered-To:"

        # Now deliver according to what was in Delivered-To:
        :0
        * DELIVERED ?? bar(_at_)foo\(_dot_)com
        ! a

        :0
        * DELIVERED ?? bloo(_at_)foo(_dot_)com
        ! b
    ...
    }

If your upstream can guarantee that there will always be a
Delivered-To: and that it will always contain something predictable,
this is a valid and working way to use a single account (such as a POP
account) for multiple recipients. Even if the recipient was Bcc:ed,
the Delivered-To: header should contain the correct recipient address.

(The above solution does not work correctly if there can be several
Delivered-To: headers in a single message, signifying that it should
be passed on to several users. Probably these should be exploded into
separate messages already at the upstream, and each should have a
single Delivered-To: header. You may want to try to verify that this
is indeed how it works in your case.)

The canonical example of grabbing a field and comparing it to
something is probably the rule for rejecting spam by comparing From:
to Reply-To: (discarding any matches as probable spam). You should be
able to find that in the list's archives.

Hope this helps,

/* era */

-- 
 Too much to say to fit into this .signature anyway: <http://www.iki.fi/era/>
  Fight spam in Europe: <http://www.euro.cauce.org/> * Sign the EU petition

<Prev in Thread] Current Thread [Next in Thread>