procmail
[Top] [All Lists]

Re: bouncing emails

2004-10-08 02:56:24
Some time around 10/07/2004 11:21:31, I think I heard Raphael Mack say:
Hello,

I use procmail to deliver mails locally called by postfix. If the mailbox
cannot be written because of a exceeded quota procmail generates a 
bounce-message. Is there a way to change the content of that mail?
I try to catch a few spam mails by procmail - is there a way to bounce
without telling too much about the users mailbox and email-adresse?

Rapha

Hello:
        This is the recipe I use.  Notice that you can make it say absolutely 
anything.  This will bounce messages addressed to non-existing mailboxes.  You 
can change the conditionals to bounce whatever messages you like.  Also, notice 
that you can change the body to say whatever you want.  I believe it is good to 
stick with the RFC and bounce The Right Way.  I also do not believe that 
bouncing spam messages helps; I used to do it at some point in time and I 
honestly think it made things worse! not to mention the increase in line noise 
to which you are contributing.

        dZ.


# Based on the bounce code from spambouncer by Catherine A. Hampton,
#                               http://www.spambouncer.org/
#
# Modified by paul(_at_)it(_dot_)ca for MIME support
# Modified further by dZ mainly to get the error message right
# ---------------------------------------------------------------------------

OLDLOGFILE=$LOGFILE
OLDVERBOSE=$VERBOSE
OLDLOGABSTRACT=$LOGABSTRACT

VERBOSE=off
LOGFILE=bounce.log
#LOGABSTRACT=all
FORMAIL=/usr/bin/formail
RM=/bin/rm
DQ='"'

# Gather some information from the original message
# ---------------------------------------------------------------------------

# MYHOST  = Our local domain name.
# MSGFROM = Original sender
# MSGTO   = Final recipient
# MSGDATE = Date the message was sent
# MSGHOST = The hostname of the original sender
# MSGMX   = The originating mail exchanger (the one who connected to us)
# MSGPM   = Postmaster address of origin

MYHOST=techunlimited.net
MSGFROM=`${FORMAIL} -I"Reply-To:" -rt -x To: | expand | sed -e 's/^[ ]*//g' -e 
's/[ ]*$//g'`
MSGTO=`${FORMAIL} -x To: | expand | sed -e 's/^[ ]*//g' -e 's/[ ]*$//g'`
MSGDATE=`date | expand | sed -e 's/^[ ]*//g' -e 's/[ ]*$//g'`
MSGHOST=`echo "${MSGFROM}" | awk -F@ '{ print $2 }'`
MSGMX=`formail -u Received: -cx Received: | expand | sed -e 's/^[ ]*from[ 
]*//g' -e 's/[ ].*//g'`
MSGPM="postmaster(_at_)${MSGHOST}"

# BOUNCE ROUTINE
:0
*  $RECIP ?? ^^(_dot_)*(_at_)$DOMAIN
*  ! FROM ?? ^^MAILER-DAEMON(_at_)$MYHOST
*$ ! X-Loop:(_dot_)*MAILER-DAEMON(_at_)$MYHOST
{
        :0
        { BOUNCEPID=`echo $$` }

        :0 c:
        bouncetemp.${BOUNCEPID}

        :0
        * ^Errors-to:[  ]\/.*
        { MSGERROR=$MATCH }

        :0
        {
                # For FreeBSD, maybe Linux too:
                MIMEBREAK="`echo \"$MSGDATE $$\" | /usr/bin/md5sum | sed -e 
's/[ ]*-$//g'`/${MYHOST}"
                # For Solaris (could be better):
                #MIMEBREAK="${BOUNCEPID}`date '+%s'"
        }

        :0 : bouncetemp.${BOUNCEPID}.lock
        | ( ${FORMAIL} -rt \
                -I"From: MAILER-DAEMON(_at_)$MYHOST (Mail Delivery Subsystem)" \
                -I"Subject: Returned mail: see transcript for details" \
                -I"Auto-Submitted: auto-generated (failure)" \
                -I"MIME-Version: 1.0" \
                -I"Content-Type: multipart/report; report-type=delivery-status; 
boundary=${DQ}${MIMEBREAK}${DQ}" \
                -A"Bcc: ${MSGERROR}" \
                -A"X-Loop: MAILER-DAEMON(_at_)${MYHOST}";\
                 printf "\nThis is a MIME-encapsulated message\n";\
                 printf "\n--%s\n\n" "${MIMEBREAK}";\
                 printf "The original message was received at %s\n" 
"${MSGDATE}";\
                 printf "from %s\n" "${MSGFROM}";\
                 printf "\n   ----- The following addresses had permanent fatal 
errors -----\n";\
                 printf "<%s>\n" "${MSGTO}";\
                 printf "    (reason: 550 unknown user <%s>)\n\n" "${MSGTO}";\
                 printf "   ----- Transcript of session follows -----\n";\
                 printf ".... while talking to %s.:\n" "${MSGMX}";\
                 printf ">>> RCPT TO: <%s>\n" "${MSGTO}";\
                 printf "<<< 550 unknown user <%s>\n" "${MSGTO}";\
                 printf "550 5.1.1 <%s>... User unknown\n" "${MSGTO}";\
                 printf "\n--%s\nContent-Type: message/delivery-status\n\n" 
"${MIMEBREAK}";\
                 printf "Reporting-MTA: dns; %s\n" "${MYHOST}";\
                 printf "Received-From-MTA: DNS; %s\n" "${MSGMX}";\
                 printf "Arrival-Date: %s\n\n" "${MSGDATE}";\
                 printf "Final-Recipient: RFC822; %s\n" "${MSGTO}";\
                 printf "Action: failed\nStatus: 5.1.1\n";\
                 printf "Diagnostic-Code: SMTP; 550 unknown user <%s>\n";\
                 printf "Last-Attempt-Date: %s\n" "`date`";\
                 printf "\n--%s\nContent-Type: message/rfc822\n\n" 
"${MIMEBREAK}";\
                 cat bouncetemp.${BOUNCEPID};\
                 printf "\n--%s--\n\n" "${MIMEBREAK}";\
                 ${RM} -f bouncetemp.${BOUNCEPID} \
        ) | ${SENDMAIL} -od -t

}

#################################################
LOGFILE=$OLDLOGFILE
VERBOSE=$OLDVERBOSE
LOGABSTRACT=$OLDLOGABSTRACT



____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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