procmail
[Top] [All Lists]

Re: passing MATCH

1999-08-26 08:22:00
On Sun, 22 Aug 1999 18:34:12 -0500 (CDT), "David W. Tamkin"
<dattier(_at_)Mcs(_dot_)Net> wrote:
|   Thats about how I rewrote it, the only thing missing now is
| instead of the header line being saved to LISTADDRESS, I'm
| looking to save the line that grep is searching for ...
That's what I was saying. You need the line from your file, not the
line from the message. Unfortunately, neither fgrep nor egrep nor
grep has a way to take a pattern list from stdin or to restrict
output to the part of the found line that matches the pattern.

sed can do that, of course, but then you end up with other problems
(such as sed not usually returning a meaningful return code). First,
create a sed script from the MAILINGLISTS file and save that as (say)
mailinglists.sed:

s/.*\(address1\).*/\1/p
s/.*\(address2\).*/\1/p
s/.*\(address3\).*/\1/p
d

Then, change your recipe to something like

    :0h
    LISTADDR=| formail -zcxTo: -xCc: -xResent-To: -xResent-Cc: -x'From ' \
        -x'Sender:' -x Resent-Sender: | sed -f sedscript

    :0:
    * LISTADDR ?? .
    $LISTADDR

Of course, with roughly the same amount of effort, you could create a
Procmail script from the list of addresses, with one recipe like this
per address:

    :0:
    * ^((Resent-)?(To|Cc|Sender):|From ).*address1
    address1

... or your own little Perl or awk script which does it all and does
it correctly. Look at how the formail duplicate checking works, that
should give you an idea of how your own script should interface with
Procmail (i.e. exit with an error if the address wasn't found or it
couldn't save to the corresponding file). There is a bit of an
explanation of how the classic formailex(5) dupe check recipe works in
the FAQ, <http://www.iki.fi/era/procmail/mini-faq.html#formail-dupe>

If you go for the "create a script which needs to be recreated each
time the list of addresses changes", you probably want to learn how to
use make(1) if you aren't familiar with that.

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>