#!/bin/bash # # qmail -- checkattach # Author: Noel G. Mistula # Date: 28 June 1999 Version: 0.1 # Modified: 7 July 1999 Version: 0.3 # Modified: 7 May 2000 Version: 0.4 # Modified: 7 Dec 2001 Version: 0.5 # Modified: 14 Dec 2001 Version: 0.6 # Modified: 8 Jan 2002 Version: 0.7 # Modified: 26 Apr 2002 Version: 0.8 # # # This is release under the GNU/GPL. # This is a very crude script, use at your own risk. # # Updated 12.07.01 by Kyle Christensen # # Directions: # 1. Change DOMAIN var to your domain (or $1 if you want to pass the parameter into the # script from your .qmail-default) # 2. Customize the bounce msg # 3. Add/Remove file extensions # 4. If you want logging, make sure $MAILLOG is chowned g+w to vchkpw # 5. When you are done editing it, put "| /path/to/checkattach" in the .qmail-default for the # domain you are filtering attachments for ABOVE the line that specifies your normal delivery # practices. # DOMAIN=aviationlearning.com DATE=`date +"%a,%e %b %Y %T %z (%Z)"` HOSTNAME=`hostname -s` MAILLOG="/var/log/maillog" TS=`date +"%b %e %T"` TO=`echo $RECIPIENT|awk -F$DOMAIN- '{print $2}'` printmsg() { # printmsg now makes vpopmail'd to: addresses more readable, and makes the reply msg more # userfriendly echo "Received: $DATE" echo "From: MAILER-DAEMON@$DOMAIN" echo "Subject: Delivery failure notification" echo "Sender: MAILER-DAEMON@$DOMAIN" echo "To: $SENDER" echo "I'm sorry but your recent email to $TO couldn't be delivered." echo "Our mailserver doesn't accept emails with .$ATTACHTYPE file attachments for security reasons." echo "If you intended to attach this file, please zip up the attachment and resend your message." echo "" echo "-The $DOMAIN team" } checktype() { case $ATTACHTYPE in BAS | BAT | COM | CMD | EML | EXE | INF | INI | LNK | PIF | REG | SCP | SCR | SHS | VBE | VBS | WSF | WSH) # Note: I am using exit 99 instead of exit 100 (no longer bouncing emails) # because local emails double-bounce and end up getting delivered to # postmaster, which is dumb. # echo "$TS $HOSTNAME qmail: Checkattach debug: from $SENDER : $ATTACHMENT" >> /var/log/maillog ATTACHNAME=`echo $SPLIT | awk -F: '{print $'$CUR'}'` echo "$TS $HOSTNAME qmail: Bounced bad attachment ($ATTACHNAME) from $SENDER to $TO" >> $MAILLOG printmsg | /var/qmail/bin/qmail-inject "$SENDER" exit 99 ;; *) ;; esac } ATTACHMENT=`grep "name=" -` # For each file in $ATTACHMENT, run checktype SPLIT=`echo $ATTACHMENT | sed -e 's/name=/"/g' -e 's/" */:/g'` CNT=`echo $SPLIT|awk -F: '{print NF}'` CUR=1 while [ $CUR -lt $CNT ]; do ATTACHTYPE=`echo $SPLIT | awk -F: '{print $'$CUR'}'|gawk 'BEGIN {FS="."}; {print toupper($NF)}' | cut -c -3` checktype $ATTACHTYPE CUR=`expr $CUR + 1` done exit 0