#!/bin/sh

# create temporary holders for HAM and SPAM
touch /tmp/HAM
touch /tmp/SPAM

# make sure they are totally empty
echo "" >/tmp/HAM
echo "" >/tmp/SPAM

# search the users home directories for a HAM folder
for file in `find /home -name "HAM"`
do
  echo "Processing $file"
  head -13 $file >/tmp/tempHAMheader
  cat $file >> /tmp/HAM
  cat /tmp/tempHAMheader > $file
done

# search the users home directories for SPAM folder
for file in `find /home -name "SPAM"`
do
  echo "Processing $file"
  head -13 $file >/tmp/tempSPAMheader
  cat $file >> /tmp/SPAM
  cat /tmp/tempSPAMheader > $file
done

# make sure the temp holders are owned by the user sa-learn will use
chown sweep.sweep /tmp/HAM /tmp/SPAM

echo "Processing collected SPAM"
su - sweep -c "sa-learn --spam --mbox --showdots /tmp/SPAM"
# the following script feeds the known spam to my spamfirewall which is a seperate script
#/usr/local/bin/mboxtospamfirewall.pl /tmp/SPAM

echo "Processing collected HAM"
su - sweep -c "sa-learn --ham --mbox --showdots /tmp/HAM"


