procmail
[Top] [All Lists]

Re: filtering mail for recipients only within certain domains

1999-09-23 21:53:16
"Eric C. Hagberg" <hagberg(_at_)ms(_dot_)com> writes:
Well, I needed to figure this one out, so I came up with what I think
is a reasonable solution, though perhaps a little crude. Thought I'd
pass it along for comments or suggestions...

DOMAINRX = "(hotmail|aol)\.com"

:0
* 1^1 ^TO_\/.*
* -1^1 MATCH ??@
*$ 1^1 MATCH ??(_at_)$DOMAINRX
* -1^1 ^TO_.*
* 1^0
hotmail_or_aol_only

:0
otherdomains



This set of rules gives (hopefully) messages with just "@hotmail.com"
or "@aol.com" recipient addresses in the headers filtering into
"hotmail_or_aol_only" and messages with those addresses outside those
domains (though possibly containing some aol or hotmail addresses)
going into "otherdomains."

The way it does this is to count (negatively) the number of addresses
by matching the "@"s in the recipient headers, and then incrementing
that count for each address that matches DOMAINRX. It also increments
that counter by one (just once). This should give the desired positive
score for messages which contain only the desired domains... unless my
logic is badly flawed.

The one big flaw in the above recipe is that it only counts the
addresses in the _first_ header field that matches the ^TO_ expression.
If you want to count the commas in all of the header fields that ^TO_
matches then you need to use a recursive INCLUDERC to loop across them.
This was discussed a couple years ago on the list in a thread with the
subject "Counting score program exit code and negation".  David Tamkin
and I worked out the neccesary recipes and you can find them summarized
in the following post in the archive:

http://www.xray.mpe.mpg.de/mailing-lists/procmail/1997-02/msg00094.html

with a bugfix found in David followup:

http://www.xray.mpe.mpg.de/mailing-lists/procmail/1997-02/msg00095.html 


Philip Guenther