procmail
[Top] [All Lists]

Re: filter based on body keywords?

2005-04-29 05:35:15
Am 2005-04-29 13:55:07, schrieb Ernest Byaruhanga:
Hi all,

I am trying to implement a filter based on keywords on the body of 
the email.

Basically this is what i want to do:

Keywords: WORD1, WORD2, WORD3, KEYWORD5, BOB

My filter should see if the content of all email to 
john(_at_)example(_dot_)com 
contains:

WORD1 or WORD2 or WORD3 or KEYWORD5 or BOB, and then deliver the 
good mail to john(_at_)example(_dot_)com(_dot_) Otherwise, the email missing 
any of 
the above keywords should go to the "spam" mailbox.

Has anyone does this before? I am a procmail newbie and am trying 
not to re-invent the wheel :-)

Yes me, but only in a BASH script becasue I am not a procmail Geek

__( example )_______________________________________________
#!/bin/bash

cat /dev/stdin >tmpfile

KEYWORDFILE=/path/to/key_word_file

NUM=`cat $KEYWORDFILE |wc --words`

let RETVAL=0

for KEYWORD in `cat $KEYWORDFILEkey_word_file` ; do
    grep $KEYWORD tmpfile >/dev/null 2>&1
    if [ $? == "0" ] ; then let RETVAL=RETVAL+1 ; fi
done

if [ $RETVAL -lt $NUM ] ; then
    exit 1
else
    exit 0
fi
____________________________________________________________

and use the "Exit Status" to determiner the Delivery status.

Any reply will be greatly appreciated.

regards,
ernest

Greetings
Michelle

-- 
Linux-User #280138 with the Linux Counter, http://counter.li.org/
Michelle Konzack   Apt. 917                  ICQ #328449886
                   50, rue de Soultz         MSM LinuxMichi
0033/3/88452356    67100 Strasbourg/France   IRC #Debian (irc.icq.com)

____________________________________________________________
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>