procmail
[Top] [All Lists]

Re: Forwarding to multiple persons

1998-03-07 19:25:28
On Sat, 7 Mar 1998, Rob Vandeweyer wrote:
I tought about something like that myself. But now what if someone sends a
mail to rob(_at_)i-nieuws(_dot_)vuurwerk(_dot_)nl and to 
otheruser(_at_)i-nieuws(_dot_)vuurwerk(_dot_)nl(_dot_)
All non-declared users like otheruser should be forwarded to
robvdw(_at_)glo(_dot_)be, but in this script that doesn't happen. This is the 
point
where I'm stuck ...

Hmmmm. I didn't get that from the original question, although you may
have made that clear. What we need to do is figure out if there are
_other_ recipients mentioned, I presume we are only looking for those
having your virtual domain. This gets a bit tricky, because procmail isn't
very good at that sort of thing. I have to resort to shell commands.
Everytime forwarding is done, we'll add the address we forwarded for to
the var DONE.

# Clone and forward.
        :0cw
        * ^TO_\/rob(_at_)i-nieuws(_dot_)vuurwerk(_dot_)nl
        ! robvdw(_at_)glo(_dot_)be
        
        :0a
        { DONE="$MATCH" }

# Clone and forward.
        :0cw
        * ^TO_\/rik(_at_)i-nieuws(_dot_)vuurwerk(_dot_)nl
        ! riktheys(_at_)village(_dot_)uunet(_dot_)be

        :0a
        { DONE="$DONE
$MATCH" }

# Clone and forward.
        :0cw
        * ^TO_\/michiel(_at_)i-nieuws(_dot_)vuurwerk(_dot_)nl
        ! mvo(_at_)open(_dot_)net

        :0a
        { DONE="$DONE
$MATCH" }

# Forward if there are any address in the to or cc line that are our
# virtual domain, and that we haven't allready done forwarding for.

    # DOMAIN is our virtual domain name.
        DOMAIN=i-nieuws.vuurwerk.nl

    # Combine the To and Cc fields into one var, and reduce it to a list
    # of addresses that both have our domain, and that we haven't already
    # done forwarding for.
        UNDELIVERED=`formail -xto -xcc\
                |tr ' ' '\12'\
                |fgrep -ie "@$DOMAIN"\
                |fgrep -ive "$DONE"`

# If there are any addresses in UNDELIVERED, then forward.

        :0w
        * $ UNDELIVERED ?? @
        ! robvdw(_at_)glo(_dot_)be

        :0
        * DONE ?? @
        /dev/null

Now, at this point, the only undelivered mail is mail not addressed to
your virtual domain, and it goes to the default mailbox.

Btw, the first address to forward to is the same as the last address to
forward to. This is redundant, and you can eliminate the first pair of
recipes.

This recipe is untested, and may have typos or other errors. You'll need
to test it and correct it if needed. I'd try it with a group of unassigned
usernames first. There is no protection against mail-loops here either, so
be careful not to forward to yourself, or modify the recipe to use X-Loop
fields and test for them in a condition line. One could easily fill
robvdw's mailbox in a few minutes without some means of preventing loops. 
You might want to investigate duplicate-killing as a means to prevent
mail-loops, instead of the X-Loop headerfield scheme. 

David Hunt

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