#! /bin/bash

# This a sample script how to use the <spamcheck/> feature of smtp-t
#
# I'm using this script to call SpamAssassin (http://spamassassin.org/)
# from smtp-t.

# spamc - client location
SPAMC=/usr/bin/spamc

#################################################################
# nothing beyond here should require adjustment
#################################################################

# skip 'From ' 1st line that gets added by spamd/spamc
output="`$SPAMC | tail +2`"
exitcode=$?

flagvalue=`echo "$output" | 822field X-Spam-Flag | sed 's/^ //'`
# X-Spam-Flag might contain "YES"

if [ "$flagvalue" = "YES" ]; then
  # match - likely spam
  # signal spam with exitcode 1
  exit 1
else
  exit 0
fi
