#!/bin/bash

#DEBUG=$1

if [ `ls -A /home/bill/Mail/Maildir/.Trash/cur | wc -l` -eq 0 ]
  then
    echo -e "************** no trash!! **************\n"
  else
    echo -e "************** dumping trash **************\n"
    for myfile in /home/bill/Mail/Maildir/.Trash/cur/*
    do
      grep -s -q "X-Spam-Status: Yes" "$myfile"
      if [ $? -eq 0 ]
      then
        echo -e "************** report spam **************\n"
        razor-report -home=/home/vpopmail/.razor "$myfile" 2>&1
        pyzor --homedir /etc/mail/spamassassin report < "$myfile" 2>&1
      fi
      rm "$myfile"
      sleep 10
    done
fi

if [ `ls -A /home/bill/Mail/Maildir/.Junk/cur | wc -l` -eq 0 ]
  then
    echo -e "************** no spam to learn!! **************\n"
  else
    echo -e "**************  learning spam ... **************\n"
/usr/local/bin/sa-learn --username=vpopmail --dbpath home/bill/Mail/.spamassassin --prefs-file=/home/bill/Mail/.spamassassin/user_prefs --spam /home/bill/Mail/Maildir/.Junk/cur 2>&1
    for myfile in /home/bill/Mail/Maildir/.Junk/cur/*
    do
      grep -s -q "autolearn=ham" "$myfile"
      if [ $? -eq 0 ]
      then
        echo -e "************** un-learning ham for spam **************\n"
        sa-learn --forget "$myfile" 2>&1
      fi
      razor-report -home=/home/vpopmail/.razor "$myfile" 2>&1
      pyzor --homedir /etc/mail/spamassassin report < "$myfile" 2>&1
      sleep 10
      rm "$myfile"
    done
fi

find /home/bill/Mail/Maildir -regex '.*/cur/.*$' -ctime -1 -exec grep -l autolearn=no {} \;|grep -v "\.users\|\.sare-users\|\.Junk" > /tmp/ham

if [ -f "/tmp/ham" ]
  then
    echo -e "************** learning ham **************\n"
/usr/local/bin/sa-learn --username=vpopmail --dbpath /home/bill/Mail/.spamassassin --prefs-file=/home/bill/Mail/.spamassassin/user_prefs --ham -f /tmp/ham 2>&1
    rm /tmp/ham
  else
    echo -e "************** hmm ... no ham file in tmp **************\n"
fi

chown vpopmail.vchkpw /home/vpopmail/domains/mccormick.ath.cx/bill/.spamassassin/bayes_toks

Reply via email to