procmail
[Top] [All Lists]

Re: Bouncing Spam(mail)

1996-09-13 18:48:01
    > Lately, I've been experimenting with a recipe to bounce unwanted mail 
    > back to it's sender.  However, I haven't had much success.  Here's the 
    > recipe that I thought would do the trick:
    > 
    > .procmailrc:
    > DUMP=/dev/null
    > 
    > rc.idiots:
    > 
    > :0
    > * ^(.*-)?(From|Sender):(_dot_)*soandso(_at_)spam\(_dot_)com
    > ! soandso(_at_)spam\(_dot_)com; $DUMP
    > 
    > This seemed right at first, since I would like to bounce the mail back 
    > and THEN delete it, but I got the response in my log that said it had 
    > saved the message in the folder "/usr/lib/sendmail 
soandso(_at_)spam(_dot_)com; 
    > /dev/null".  I'm not sure what's going wrong, since I'm following the man 
    > instructions as best as I can.  Do I need to put it into /dev/null first, 
    > or am I way off base here?  

First, I'll make my usual claim: it is generally a bad idea to
auto-bounce email, and you should attempt this only after great caution
and careful preparation.   Given that, here are some points:

1. You don't need to escape the '.' on the action line; regexps are not
   parsed in this context.

2. What is the "(.*-)?" pattern for?  For Resent?  If so, make your
   regexp more explicit, otherwise a badly worded Subject could wreak
   havoc :

        To: you
        From: yourfriend
        Subject: Your email about "Resent-From: soandso(_at_)spam(_dot_)com"

        ...

    Will get bounced back to yourfriend; not what you intended.

3. Why append "; $DUMP" to your action?  It doesn't work as you
   intended.  The resulting shell command will look like this:

    sendmail soandso(_at_)spam(_dot_)com ; /dev/null

Do you want to drop the mail into /dev/null after bouncing?
If so, do this:

    :0w
    * ^(Resent-)?(From|Sender):(.*[^a-zA-Z0-9])?\/soandso(_at_)spam\(_dot_)com
    ! $MATCH

This will forward the mail back to the sender, with no changes in the
headers, except that the destination MTAs will probably add a
"Received-by:" or two.

You probably also don't want to auto-bounce email to a mailer-daemon, or
a loop may result; so insert another condition:

    :0w
    * ^(Resent-)?(From|Sender):(.*[^a-zA-Z0-9])?\/soandso(_at_)spam\(_dot_)com
    * !^FROM_MAILER
    ! $MATCH

Finally, by virtue of sendmail successfully delivering the mail,
procmail will also consider to have delivered the mail, and processing
will stop.  So, there is no need to explicitly drop the mail into
/dev/null. 

If you wish to have the possibility of saving the mail in a folder, you
will need to modify the recipe a bit:

    :0wc
    * ^(Resent-)?(From|Sender):(.*[^a-zA-Z0-9])?\/soandso(_at_)spam\(_dot_)com
    * !^FROM_MAILER
    ! $MATCH

    # If the mail was successfully forwarded back, keep it in this
    # folder so I can check its contents now and then.
    :0a
    bounced-mail

Alan

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