procmail
[Top] [All Lists]

Re: Ignoring and/or Bouncing mail?

1996-08-11 01:01:08
    > I'm trying to set-up procmail to /dev/null any mail from known spammers, I
    > have the following:
    > 
    > ---
    > :0
    > * ^From(_dot_)*crjr1(_at_)(_dot_)*netcom(_dot_)com
    > /dev/null
    > 
    > :0
    > * ^From(_dot_)*ndr(_at_)(_dot_)*akamail(_dot_)com
    > /dev/null
    > 
    > :0
    > * ^From(_dot_)*rlj(_at_)(_dot_)*pobox(_dot_)com
    > /dev/null
    > 
    > [...]
    > ---
    > 
    > Which works, but looks like it can be improved.  Is there anyway to 
    > combine all of these into one recipe?  I tried:

You can combine them into one regexp:

    :0
    * 
^From.*(crjr1(_at_)(_dot_)*netcom(_dot_)com|ndr(_at_)(_dot_)*akamail(_dot_)com|rlj(_at_)(_dot_)*pobox(_dot_)com)
    /dev/null

If you get too many addresses, you can continue and indent them:

    :0
    * ^From.*(crjr1(_at_)(_dot_)*netcom(_dot_)com|\
                ndr(_at_)(_dot_)*akamail(_dot_)com|\
                ....                            # and so on...
                rlj(_at_)(_dot_)*pobox(_dot_)com)
    /dev/null

If your regexp gets really big, you may want to set LINEBUF to a larger
value:

    LINEBUF=2048

Alternatively, you can place the "bad" addresses in a file, let's call it
"badguys", and use the '-f' option of fgrep:

    SENDER=`formail -rtzxTo:`           # get the SENDER's address
    :0:badguys.lock
    * ? echo "$SENDER" | fgrep -s -f badguys
    /dev/null

The reason why I put the lock on "badguys" is so that you can use the 
following procedure to safely update the file without possibly causing
the fgrep perform falsely:

    lockfile badguys.lock
    vi badguys
    rm -f badguys.lock

Let's suppose that when you get a new SPAM mail from someone and you
want to automatically update the "badguys" file with the sender, so
that you will be bothered no more.  The following recipe file will
perform the update:

    DELIVERED=yes               # don't really deliver the mail anywhere
    SENDER=`formail -rtzxTo:`   # get the sender of the mail
    # see if the address is already on the list
    LOCKFILE=badguys.lock       # protect the file
    :0
    * !? echo "$SENDER"  | fgrep -f badguys
    | echo "$SENDER" >> badguys

Place this recipe in a file, let's call it "addbadguy", and, when you 
get a piece of mail from a new bad guy, just feed it to the addbadguy 
recipe, like this:

 MH-style:

    show | procmail -m addbadguy

 BSD-mail-style:

    save | procmail -m addbadguy

If you want to make it even more concise, place a shebang at the front:

    #!/usr/local/bin/procmail -m

(make the procmail path reflect where it really lives on your system),
make the script executable, and then feed the mail like this:

    show | addbadguy

    > Also, instead of just tossing these in /dev/null, I would prefer to have
    > them bounce to the sender so that maybe they'd take me off their lists
    > thinking I disappeared.  Any help on how to do this would be appreciated.

Well, auto-bouncing is possibly dangerous, and can cause more harm than good,
if not done correctly.  But, we should all be master of our own fate, so..

After recognizing a badbuy, you can form a reply:

    SENDER=`formail -rtzxTo:`
    :0                          # If this is a badguy, auto-respond
    * ? echo "$SENDER" | fgrep -f badguys
    {                           # this is a bad buy, make a reply

        :0fh                    # form a reply header
        | formail -rt   -I"From: $USER(_at_)$HOST (Call Me Upset)" \
                        -I"Reply-To: nobody" \
                        -I"Precedence: junk" \
                        -I"Subject: Your recent spamming to me"

        # Notice that I set "From:" correctly, but override it with 
        # "Reply-To: nobody" so that any replies will go nowhere.
        # On many (most?) Unix systems, "nobody" is an alias to "/dev/null".

        :0fb                    # form the body
        | echo "You recent unsolicited e-mail to me is not appreciated." ;    \
          echo "All future e-mail from you will be ignored by me (not even" ; \
          echo "seen, actually), but will generate this response." ;          \
          echo "It is, therefore, in your own best interest to not even " ;   \
          echo "bother sending me any more e-mail." ;                         \
          echo "Thank you. -- $USER's Mail-Agent." ;                          \
          echo "" ;                                                           \
          echo "---- Original Message ----" ;                                 \
          cat -

        :0                      # feed the reply to the mailer
        ! -oi -t

        DELIVERED=yes           # pretend we delivered the mail
        HOST=_done_             # stop processing now
    }

_____________________________________________________________________
Alan Stebbens <stebbens(_at_)sgi(_dot_)com>      http://reality.sgi.com/stebbens
Digital TV, Silicon Interactive Group,  Silicon Graphics, Inc.  (SGI)
M/S:9L991,     2011 N. Shoreline Blvd.,     Mountain View, CA   94043
PGP Key Fingerprint: 94 A7 4B AB 1C F0 4D 92  DD BC B5 D7 11 A0 DC B3

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