procmail
[Top] [All Lists]

Re: Searchhing for words in external word list?

2008-12-11 09:09:55
Dave [11.Dez.2008 11:02]:

On (09:35 11/12/08), Dave Wood <dave(_at_)unrealize(_dot_)co(_dot_)uk> put 
forth the proposition:
I would like to know if it's possible to search for words contained in an
external file. Something like:

BADWORDS=`cat $HOME/.badwords`

:0
* ^Subject:.*${BADWORDS}*
spam

This doesn't work and I'm guesing that it's looking for a match of all the
output of cat rather than checking each word.

Solved I think. I separated each word with | so my word file looks like
word1|word2|word3 Then used [ ] in the test:

:0
* ^Subject:.*[${BADWORDS}]*
spam

Seems to work now but need more testing.


This is the idea anyway. If anyone has some suggestions on how to do it
that would be great.

Sorry Dave, forgot to List-Reply :(

This is how I do some testing against known email addresses:

---8<---
WHITELIST = $PROCMAILDIR/whitelist
FROM=`formail -xFrom: | sed -e ': stripcomments s/([^()]*)//; t
stripcomments; s/.*<\([^ >]\+\)>.*/\1/; t; s/^ \+//; s/ \+$//'`
:0
* ? fgrep -qxsi "$FROM" "$WHITELIST"
{
LOG = "OK FROM "
:0
$INBOX/
}
---8<---

It uses formail to extract the FROM-field to get the email address in
there, sed to get the address and nothing else and put it into a
variable.
You could use the SUBJECT as well I guess.

Finally, I use fgrep to check if the substracted address is in my
whitelist file. Upon finding, mail is delivered to my inbox and a remark
attached to my log.

The whitelist file contains one argument per line, so no extra "|,;:"
needed - better for sorting or editing I assume.

I am not sure how the second ":0" got in there. Shouldn't it work
without it? I probably took the code from a different block and forgot
to delete it.


JP

--
Time flies like the wind, but fruit flies like bananas.
____________________________________________________________
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