#!/bin/sh
#
# spamc.sh
#
# Simple filter to plug SpamAssassin
# into the Postfix MTA, using the spamc / spamd
# daemon version of SpamAssassin.
#

# File locations:
INSPECT_DIR=/var/spool/filter
SENDMAIL="/usr/sbin/sendmail -i"
SPAMC=/usr/local/spamassassin/bin/spamc

# Exit codes from <sysexits.h>
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 in.$$ out.$$" 0 1 2 3 15

# Write raw input to a temp file before sending to spamc:
# (spamc doesn't seem to like taking input from a pipe)
cat > in.$$
$SPAMC < in.$$ 2>/dev/null > out.$$
$SENDMAIL "$@" < out.$$

exit $?

