procmail
[Top] [All Lists]

Re: Killing mail by country

2000-01-03 04:44:06
At 10:41 PM 12/30/99 -0700, Bill McClatchie wrote:
My spam filters be getting a bit large for what I want to do.

Mainly, block email from countries where the spam is coming these days.  
And then tell me why the email was offensive.  What I have is a series of
filters that look like this:

:0
* ^Received:.*\.cn[    ]
{
LOG= "Reason: I don't know anyone in china. $N"

:0
/dev/null

Well, someday you might; or you might post to usenet or something
and get a response from China... generally it's safer to toss in a
folder (I now have one called "spam.asia"  :-) and then deleting
manually is usually trivial after a glance at the subjects.  This
leaves mistaken advance guesses about what you want/don't want
as still recoverable, as well as a change in needs sometime later
when you forget to update your .procmailrc .

}

Now, I know I can do something like:

* ^Received:.*\.\/(cn|nl|jp)[^         ][      ]

And then do

LOG= "Reason: I don't know anyone in $MATCH. $N"

Is there an easy way to find the correct country for the value in $MATCH?
I know I can do it with something like:

COUNTRY=|`grep $MATCH list-of-countries | awk '{print $2}'`

(BTW, you'll match 'nl' to 'finland' doing that.  Use a "^" anchor. )

I don't think you should EVER need grep-piped-to-awk, for procmail or
anything else... awk has all the functionality of grep and more.

    COUNTRY=|`awk '{if($1=="'$MATCH'") print $2}' list-of-countries`
or
    COUNTRY=|`awk '$1=="'$MATCH'" {print $2}' list-of-countries`
or the more grep-like:
    COUNTRY=|`awk '/^'$MATCH'/ {print $2}' list-of-countries`

(none of these tested; warning: I've been known to make typos on
mixed quote marks before :)

Or use sed or perl to do the same thing.  Is there a better way to do
this?

How about creating a few files such as "jp.countryname"
containing "japan", etc., and then
    LOG= "Reason: I don't know anyone in `cat $MATCH.countryname`.$N"

Happy 2000,
Stan

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