procmail
[Top] [All Lists]

Re: handling multiple forwardees

1996-07-19 22:41:30
Brett Schlank asked,

| The current recipe looks like this:
|          :0
|              * ^TOjim(_at_)mydomain(_dot_)com
|              ! jim(_at_)aol(_dot_)com
|
|          :0
|              * ^TOal(_at_)mydomain(_dot_)com
|              ! al(_at_)aol(_dot_)com
|
|          :0
|              * ^TOcharles(_at_)mydomain(_dot_)com
|              ! chuck4(_at_)aol(_dot_)com
|
| Every once in a while, I (well my boss) needs to send them all memos at the
| same time.  How can procmail handle the multiple names without quitting out
| after the first one (does that make sense?)

It makes perfect sense and is a very common question; it comes up about once
every month or two.

| Would something like this work:
|
|          :0 c
|              * ^TOjim(_at_)mydomain(_dot_)com
|              ! jim(_at_)aol(_dot_)com
|
|          :0 c
|              * ^TOal(_at_)mydomain(_dot_)com
|              ! al(_at_)aol(_dot_)com
|
|          :0 c
|              * ^TOcharles(_at_)mydomain(_dot_)com
|              ! chuck4(_at_)aol(_dot_)com

That would work, with two problems: (1) mail that is forwarded to any or any
two or all of them will fall off the end of those three recipes and a copy
will land in $DEFAULT (which is not your intention, based on the recipes
you've been using heretofore); and (2) you're filtering on the addresses in
the headers, which may or may not match those on the envelope.

| Or am I going to end up with huge mail loops that will eventually bring down
| the server and make my life a living hell?

There's no such risk, but here's a more efficient way to do the job because
it invokes $SENDMAIL only once no matter how many of your trinity get copies
and it doesn't let a copy fall through into $DEFAULT [if you want a copy in
$DEFAULT, add the `c' flag to the "!" recipe].  Also, it includes some loop
detection:

       :0
       * !^FROM_DAEMON
       * !^X-Loop: Brett Schlank's forwarder 
<bschlank(_at_)pacificnet\(_dot_)net>
       * ^TO(jim|al|charles)@mydomain\.com
       {
        FORWARDEES # make sure it goes in unset

        :0
        * ^TOjim(_at_)mydomain\(_dot_)com
        { FORWARDEES=jim(_at_)aol(_dot_)com }

        :0
        * ^TOal(_at_)mydomain\(_dot_)com
        { FORWARDEES="$FORWARDEES al(_at_)aol(_dot_)com" }

        :0
        * ^TOcharles(_at_)mydomain\(_dot_)com
        { FORWARDEES="$FORWARDEES chuck4(_at_)aol(_dot_)com" }

        :0fwh # The condition should be redundant, ideally.
        * FORWARDEES ?? [^ ]
        | formail -I \
          "X-Loop: Brett Schlank's forwarder 
<bschlank(_at_)pacificnet(_dot_)net>"
          :0A
          ! $FORWARDEES
       }

| ALSO, is there anyway for procmail to determine if there are multiple
| recipients in the header?

Here's one way: if there is a comma in an addressee header, or if there are
two or more non-empty addressee headers, we have more than one addressee:

       MULTIPLES
       :0
       * ^TO[a-z].*,.*[a-z]
       { MULTIPLES=yes }
       :0E
       * 1^1 ^TO[a-z]
       * -1^0
       { MULTIPLES=yes }

But remember, it looks for more than one addressee in the headers, not more
than one recipient on the envelope.  There are many circumstances under which
the two can differ.

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