procmail
[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
from_list
   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
char.
#
LOGFILE='/home/kfl_root/log'
VERBOSE=yes
MATCH_TO='match_to(_at_)penit(_dot_)com'
MATCH_FROM='match_from(_at_)penit(_dot_)com'
MATCH_BOTH='match_both(_at_)penit(_dot_)com'
MATCH_NEITHER='match_neither(_at_)penit(_dot_)com'


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


:0  
* ^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

        :0
        ! $MATCH_TO
}

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

:0
* $ ? 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

        :0
        ! $MATCH_TO
}

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


:0
! $MATCH_NEITHER


Any suggestion will be appreciated?

Rgds,
Kfl.


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