procmail
[Top] [All Lists]

Re: Bozo filters II

1997-02-06 11:14:51
Just to tie up the discussion, here's an rc file that implements a "bozo 
filter" based on substring matches, rather than whole address matches.  
This means you can put 'aol.com' in your bozo file to block all mail from 
aol.com, for example.

This has only been briefly tested, but it seems to work.  I have it send 
mail to an MH directory, which I clean out periodically with a cron 
script.  You could set BOZODEST to /dev/null if you really want to lose 
things.

A quick note: I always use full path names for commands in rc files, 
which is what the "Binaries" section is for.  In my environment, these 
are all defined from rc.main (which is hardlinked to ~/.procmailrc); thus 
the ${VAR:-} syntax.

# rc.bozo
# Lars Kellogg-Stedman <lars(_at_)bu(_dot_)edu>
#
# Rejects messages from certain addresses, using substring matches

# ----------------------------------------------------------------------
# Settings
# ----------------------------------------------------------------------

BOZOFILE=$HOME/.bozo                    # Reject addresses containing
                                        # any string in this file.
BOZOLOG=$LOGFILE                        # Where to log rejects
BOZODEST=$HOME/Mail/rejected/.          # Where to send rejects


# ----------------------------------------------------------------------
# Binaries
# ----------------------------------------------------------------------

TEST=${TEST:-/bin/test}
FORMAIL=${FORMAIL:-/usr/local/bin/formail}
FGREP=${FGREP:-/bin/fgrep}
ECHO=${ECHO:-/bin/echo}
DATE=${DATE:-/bin/date}

# ----------------------------------------------------------------------
# The Bozo Filter
# ----------------------------------------------------------------------

# Defaults, in case something didn't get set up above

BOZOFILE=${BOZOFILE:-$HOME/.bozo}       # Reject addresses containing
                                        # any string in this file.
BOZOLOG=${BOZOLOG:-$LOGFILE}            # Where to log rejects
BOZODEST=${BOZODEST:-/dev/null}         # Where to send rejects

FROM=`$FORMAIL -zx "From:"`
:0
* ? $TEST -f $BOZOFILE
* FROM ?? ? $FGREP -f $BOZOFILE
{
        :0c:
        $BOZODEST

        :0
        | ( $ECHO "bozo: [`$DATE`] rejected message from '$FROM'"; \
            $ECHO "bozo: (message dumped to $BOZODEST)" ) >> $BOZOLOG
}

# Clean up
FROM

---
Lars Kellogg-Stedman * lars(_at_)bu(_dot_)edu * (617)353-8277
Office of Information Technology, Boston University