procmail
[Top] [All Lists]

Re: Running a script from procmail

2006-09-29 17:52:56
At 22:57 2006-09-29 +0100, Steve A wrote:
I want to be able to examine a text file containing users (one user per
line), and drop any mail if a match is found to that user.  So, this
question is in 3 parts:

1.
To avoid acting on fake headers (and blank envelope From's), should I
match on "X-Original-To:" (which I think is put there by sendmail)
instead of To:?

*ALL* X- headers are nonstandard.  X-Envelope-From: and X-Envelope-To: are 
two commonly added headers, but they're not present by DEFAULT by any 
means.  In addition, the X-Envelope-To: header (when added by optional 
rules in Sendmail) IS NOT ADDED IF THERE ARE MULTIPLE LOCAL RECIPIENTS.

2.
 From the examples I've seen and the procmail documentation, should the
recipe user flags "fwh".  That is assuming I only need to pass the
headers to the external script.

f means filter, which means your external script will be filtering 
(potentially altering) the message.  If this is a condition for discarding, 
you should instead use:

:0
* ? /path/to/some_script args
trash.mbx

If the program exit code is zero, the condition is evaluated as FALSE, and 
if it returns a nonzero, it evaluates as TRUE.  If you extract the header 
value you're looking for, and pass it to your script as an argument, you 
don't need to parse all the headers in your script.

I can use the grep command in an external script and get a return value,
and was thinking of adding an X- header to the message and let procmail
filter it out a later stage.  I'm not sure how to get the header back to
procmail.

Well, if you do run your process as a filter, you'd emit everything back 
out to stdout, and ADD anything you want (or remove other bits).  Formail 
may be an easier option - if you do something like the following, you don't 
need to write ANY code external to procmail, and the whole filter is pretty 
self-sufficient (except of course for the content of the blacklist file, 
but that's a given).


# one address per line - OR partial tokens which will match substrings
# in the piped data.
BLACKLIST=$HOME/Mail/testing/somefile

:0
* $? formail -x"To:" -x"Cc:" | fgrep -i -w -f $BLACKLIST
{
         # we matched something
         :0fwh
         | formail -A"X-YourCustomHeader: somevalue"
}

Note that the emitted address text from formail will still include comments.

Remove the -w parameter from fgrep if you want partial strings in the 
blacklist file to match on non wordbreak boundaries.

---
  Sean B. Straw / Professional Software Engineering

  Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
  Please DO NOT carbon me on list replies.  I'll get my copy from the list.


____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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