procmail
[Top] [All Lists]

Re: Trying to bounce mail after-the-fact with procmail/formail

2001-10-26 16:12:36
At 17:41 2001-10-26 -0400, Rich Kulawiec wrote:
problem.  I'm going to keep pursuing a bounce-'em-from-file solution, too;
it just seems to me like the sort of thing that someone, somewhere, sometime
probably cooked up, and all I need to do is find it. ;-)

You can use the virtusertable for other tricks as well: for those users who frequently have misaddressed messages, you can set an error like:

misspelledusername(_at_)yourdomain(_dot_)tld ERROR: 550 you have misaddressed your message intended for properuseraddress(_at_)yourdomain(_dot_)tld

This would bounce the message to the sender, providing them with what they need to know to properly address the message. No forwarding action required on your part. If the people sending the messages can't address them properly, they'll have to contact their associate via a different method and get the stupid knocked out of them. Seems like less grief for you.

Your biggest problem is going to be dealing with positively identifying the envelope recipient on the generically-delivered messages.

If you're going to do a wildcard bouncer mechanism, then you should at least consider doing it via a separate user account set up on the server for this purpose, so it doesn't intermingle with your usual email. Then, the ONLY mail recieved by that account will be that which is known to be misaddressed.


The following is totally and absolutely untested. $SPAMDIR and $AUTOREPLY should be self-explantory as paths to the related files, and $MAILBOT is the address you want the notification to appear to be from - it could be "mailer-daemon(_at_)yourdomain(_dot_)tld", or "bouncer(_at_)yourdomain(_dot_)tld", or whatever. Arguably, if you set it to something WHICH DOES NOT DELIVER TO THIS HOST ACCOUNT, you should handily avoid reply messages from clueless folk.

# ==========================================================================

# If a SPECIFIC ADDRESS from the misslist appears anywhere within the
# various headers which define recipients, bounce it.  This will only match
# the first such misaddressed user - if the message is multiply addressed,
# the other recipients will not be identified.  This shouldn't pose a big
# problem -- you're still notifying the sender that they can't address their
# mail worth a dang, and if your notification message can advise the sender
# to recheck *ALL* of the recipients.

MISSLIST=$SPAMDIR/miss.dat

# note: instead of grep, I use a tool I wrote called megagrep, which uses an
# AVL tree and other optimizations specifically for dealing with searching
# against a *LARGE* match file.  It also stops on the first match and emits
# the match text, not the source line, so $FAILKEY ands up being a specific
# token I can identify with.  Regular grep doesn't work this way, so live
# with it.

# you could use a utility which finds matching tokens and emits the "correct
# address" token instead, then you could administer a little DB file with
# known translations.

# you may want to elaborate on the headers checked for recipient
# idenfification (say, x-envelope-to: if your server sets such a header)
:0h
FAILKEY=| (formail -xTo: -xCc: -xApparently-To: | grep -i -f $MISSLIST)

# If failkey is nonblank, we matched something.  Oh, goodie.
:0
* ! $FAILKEY ?? ^^^^
{
        # if you're not getting a token, don't bother emitting it in this
        # log message:
        LOG="BADMAIL: Match $FAILKEY in misslist.
"

        # if this X-Loop matches, we're facing a mail-loop, don't respond.
        # you may or may not want to add mailer-daemon handling here as well.
        :0
        * ^X-Loop: $MAILBOT
        /dev/null

        # this bounce doesn't include the message body or the specific
        # addressee, but rather a prepared notification about how their
        # message was misaddressed.
        :0
        | ( formail -rt -A "X-Loop: $MAILBOT" -I "From: $MAILBOT" ;\
           cat $AUTOREPLY/misaddressed.msg ) | $SENDMAIL -t
}

# ==========================================================================

---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail