#!/bin/sh
# Once a night, report on the filtered spam and save it away,
# and reclassify the day's spam that got through the filter.

PATH=$HOME/bin:$PATH; export PATH
umask 002

cd $HOME/misc || exit 1

#grep '^From ' caughtspam | egrep -v MAILER-DAEMON | nl -w2 -s:
#grep '^From ' caughtspam | nl -w2 -s:
checkspam caughtspam

dir=old/caughtspam
test -d $dir || mkdir $dir

date=`date +%Y%m%d`
target=$dir/$date
mv caughtspam $target
bzip2 $target
chmod 444 $target.bz2

touch caughtspam
chmod 644 caughtspam

cd $HOME/mail || exit 1
if test -s spam; then
  kspam --SPAM <spam
  mv spam $HOME/misc/$target.x
  bzip2 $HOME/misc/$target.x
  chmod 444 $HOME/misc/$target.x.bz2
fi

if test -s nonspam; then
  nonspam=$HOME/misc/old/nonspam
  test -d $nonspam || mkdir -p $nonspam
  mv nonspam $nonspam/$date
  bzip2 $nonspam/$date
  chmod 444 $nonspam/$date.bz2
fi
