#!/bin/sh
# exit 0 if spam, exit 1 if nonspam.

PATH=$HOME/bin:/l/bin:$PATH; export PATH
umask 077

test -d $HOME/.kspam || mkdir -p $HOME/.kspam
msg=$HOME/.kspam/kmsg.$$
trap "rm -f $msg" 0 1 2 3 15
cat >$msg

# logging (to .procmailrc.log).
printf "%s %s\n" \
       `date +%Y%m%d.%H%M.%Z` \
       "`grep -i '^message-id:' $msg | head -1 | awk '{print $2}'`" >&2

# see if we think it's spam.
kspam <$msg
exit=$?

# whitelist corrections.
if test $exit -eq 0; then
  if sed '/^$/,$d' $msg \
     | egrep '^From:.*(karl|george_planansky)[+@]' >/dev/null; then
    kspam --NONSPAM <$msg
    exit 1
  fi

# blacklist corrections: billo challenge junk.
# got on bondsearch mailing list somehow.
# virus.
elif test $exit -eq 1; then
  if (grep '^From: billo@billo.com' $msg \
      && grep '^Subject: your email' $msg \
      && grep '^Reply-To: challenge-reply@f7.net' $msg) \
     || grep '^From: "Bondsearch" <bondsearch@jbhanauer.com>' \
     || grep '<iframe src=' $msg \
     || grep '^Antigen for Exchange found .* infected' $msg \
  ; then
    kspam --SPAM $msg
    exit 0
  fi
fi

exit $exit
