[Top] [All Lists]

Separate incoming mail into 4 categories

2007-01-04 09:40:12

I am trying to develop a simple mechanism to separate the incoming mail
into four categories by using a from_list and a to_list. From_list
contains the fully qualified e-mail addresses of the known senders and
the to_list contain the addresses of the known recipients.

The logic is as following:

 if it is in the (to_list) then
   it is forwarded to a match_both mailbox if the it is also match
   otherwise goes to match_to mailbox
If it is not in to_list but match from_list, it goes to match_from
  otherwise it goes to match_neither.

Since the To: address sometimes has a <> sometime does not, the program
checks both type..

This program looks like working superfically but not exactly; the
problem seem to do with how grep -f works. After use gawk to yank out
the mail address like kflee(_at_)penit(_dot_)com, the match of this against the
list seem behave inconsistently.

What I like to do is to match the address exactly (ignore the case)
including the domain but the grep seem to match part as it consider the
part before @ as separated entities. Is there a simple way to get grep
to match whole line in the list, one line at a time?

# The important thing to note is that the control to_list and from_list
#  must not contain blank line as it will also be matched with blank

# Those mails that has a To: xx <abc(_at_)domain(_dot_)com> format, ie, mail
#   inside a pair of angle brackets

* ^To:.*<.+>
* $ ? grep ^To:.* |gawk -F '<' '//{print $2}' |gawk -F \> '//{print $1}'
|grep -f to_list
        :0 wi 
        * ^From:.*<.+>
        * $ ? grep ^From:.* |gawk -F '<' '//{print $2}' |gawk -F \>
'//{print $1}' |grep -f from_list
        ! $MATCH_BOTH

        ! $MATCH_TO

# those mail without <> to contain its To: mail address 
#   the From: xxx <xxxx> seems alwasy have an angle bracket pair!

* $ ? grep ^To:.* |gawk '//{print $2}' |grep -f to_list
        :0 wi 
        * ^From:.*
        * $ ? grep ^From:.* |gawk -F '<' '//{print $2}' |gawk -F \>
'//{print $1}' |grep -f from_list
        ! $MATCH_BOTH

        ! $MATCH_TO

* ^From:.*
* ? grep $MATCH -f from_list 


Any suggestion will be appreciated?


procmail mailing list   Procmail homepage:

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