procmail
[Top] [All Lists]

Re: forwarding to multiple users based on...

1996-06-04 11:44:21
"D. Emilio Grimaldo T." <grimaldo(_at_)ehv(_dot_)sc(_dot_)philips(_dot_)com> 
writes:
   How can I bounce a mail to multiple recipients (addresses are stored
   in a file) based on the contents of a header? in this case the header
   would have something like airheads-l to indicate the rule that the
   list of recipients is in the airheads.list file. I have tried many
   things including the sour recipe below but nothing works.


Just to check, make sure you're running at least 3.10: that's when $MATCH
appeared.


:0
* ^X-To: \/[-a-z]*-l
* ^X-Loop: project_acct(_at_)my(_dot_)domain(_dot_)nl
* ^FROM_DAEMON

This is major problem right now.  You probably meant to say:

:0
*   ^X-To: \/[-a-z]*-l
* ! ^X-Loop: project_acct(_at_)my(_dot_)domain(_dot_)nl
* ! ^FROM_DAEMON

Reversing the conditions has a _large_ effect.


{
   :0 fhw
   * ^X-To: \/[-a-z]*-l
   | formail -A "X-MailList: $MATCH"

No need to do the matching again, $MATCH is already set.  Also, don't forget
to add the X-Loop header

{
    :0 fhw
    | formail -A "X-MailList: $MATCH" -A "X-Loop: 
project_acct(_at_)my(_dot_)domain(_dot_)nl"



   LISTNAME="$MATCH"

   :0 ah
   ! `cat /user/project_acct/.procmail/lists/$LISTNAME.list`
}

Why the 'h' flag?  That'll send just the header of the message to the
mailing list, which is sorta silly.  The 'a' flag is extraneous here,
as the previous condition is sure to match.

Also, there's no need to save $MATCH into another variable: $MATCH is
only set/reset when procmail processes a (matching!) regexp containing
the \/ operator.

With one other tweak, I'd then rewrite the above as:

XLOOP = project_acct(_at_)my(_dot_)domain(_dot_)nl
:0
*     ^X-To: \/[-a-z]*-;
* $ ! ^X-Loop: $\XLOOP
*   ! ^FROM_DAEMON
{
    :0 fhw
    | formail -A "X-MailList: $MATCH" -A "X-Loop: $XLOOP"

    :0
    ! `cat /user/project_acct/.procmail/lists/$MATCH/.list`
}


(I like the cleanliness of storing the X-Loop value in a variable.  One
less place to have a typing error, and the $\ expansion escapes the periods
for me in the regexp.)


If the list gets really long then you may hit a limit on how many
arguments can be passed in an execve, in which case you should move to
real mailinglist software like Smartlist.


Philip Guenther

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