This script is a simple content filter wrapper for postfix. It examines the recipient to determine the dspam user and domain and then processes accordingly. Mail destined for other domains (say you pass outbound mail through your mail relay gateway) is passed back to postfix with no processing.

Because this filter handles normal dspam processing as well as user re-training, there's no need to play with postfix aliases or virtual domains as many other dspam HOW-TOs do. It also eliminates unnecessary dspam processing by ONLY dealing with mail destined to your domain.

#!/bin/sh

PATH=/usr/local/bin:/usr/bin:/bin
SENDMAIL="/usr/sbin/sendmail"
DSPAM="/usr/local/bin/dspam"
MYDOMAIN="example.com"

# Get arguments
sender="$1"; shift
recip="$1"; shift

# Parse out the username from the recipient
user=`echo $recip | sed -n 's/^\(.*\)@.*/\1/p'`

# Parse out domain from the recipient
domain=`echo $recip | sed -n 's/.*@\(.*\).*/\1/p'`

if [ -z "$user" ]; then
  echo "Can't determine user"
  exit 75 # EX_TEMPFAIL
fi

if [ "$domain" = "$MYDOMAIN" ]; then
  $DSPAM --deliver=innocent,spam --user "$user" -i -f "$sender" -- "$recip"
elif [ "$domain" = "spam.$MYDOMAIN" ]; then
  $DSPAM --user "$user" --class=spam --source=error
elif [ "$domain" = "ham.$MYDOMAIN" ]; then
  $DSPAM --user "$user" --class=innocent --source=error
else
  $SENDMAIL -i -f "$sender" -- "$recip"
fi

exit $?

last edited 2006-01-05 17:42:57 by mpiat5323