#!/bin/sh # # per-domain.sh # # Example of applying different Anomy config files # based on recipient domain. # # Looks in the $ANOMY directory for file named # .conf. If it exists, Anomy is # run using that config file instead of the default. # # Example: to filter mail addressed to 'example.com' # using a different anomy config file, create a config # file named '/usr/local/anomy/example.com.conf' # # From http://advosys.ca/papers/postfix-filtering.html # Advosys Consulting Inc., Ottawa # # For use with: # Postfix 20010228 or later # Anomy Sanitizer revision 1.49 or later # SpamAssassin 2.42 or later # # Note: Modify the file locations to match your particular # server and installation of SpamAssassin. # File locations: # (CHANGE AS REQUIRED TO MATCH YOUR SERVER) INSPECT_DIR=/var/spool/filter SENDMAIL="/usr/lib/sendmail -i" ANOMY=/usr/local/anomy SANITIZER=$ANOMY/bin/sanitizer.pl SPAMASSASSIN=/usr/bin/spamassassin # Location of default anomy config (to use when no domain matches): ANOMY_CONF=$ANOMY/anomy.conf # Optional file file for debugging: ANOMY_LOG=/dev/null export ANOMY # Exit codes from EX_TEMPFAIL=75 EX_UNAVAILABLE=69 cd $INSPECT_DIR || { echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; } # Clean up when done or when aborting. trap "rm -f out.$$" 0 1 2 3 15 # Extract domain from recipient parameter: DOMAIN=`echo $4 | sed -e 's/^.*\@\(.*\)$/\1/g'` # Redfine ANOMY_CONF variable if a domain-specific # .conf file exists: if [ -e $ANOMY/$DOMAIN.conf ] then ANOMY_CONF=$ANOMY/$DOMAIN.conf fi cat | $SPAMASSASSIN -x | $SANITIZER \ $ANOMY_CONF 2>>$ANOMY_LOG > out.$$ || \ { echo Message content rejected; exit $EX_UNAVAILABLE; } $SENDMAIL "$@" < out.$$ exit $?