I needed to get this working this week and found the RemoteImapFolder wiki page. I decided to use that method here are the steps I did to make this work for me. I use qmail instead of cyrus so needed to change the redelivery method also. I don't have a username on the wiki and thought I see if anyone here had any improvements before I add it to the wiki.

Create a .fetchmailrc file in the users home that the cron script will run from or maybe in /etc
---
poll mail.domain.com
    user 'user1' there with password 'password' is user1 here
    user 'user2' there with password 'password' is user2 here
---

Replace the mail server name on the first line and the 2 usernames and the password on each of the users lines, Duplicate for each user you want to learn from. What this does is make the script below not stop and ask for a password when it is run.

It is run like this
./learnfromexchange user FOLDERNAME mail.bccks.com (spam|ham|forget)

For the server I run we use sitewide bayes - so I talked to 4 of the users and got permission to learn from their spam and a non-personal good email folder that they will drag email to.

Then I run the script from cron
02 4 * * * root /root/learnfromexchange user1 SPAM mail.domain.com spam
12 4 * * * root /root/learnfromexchange user1 CLEAN mail.domain.com ham
22 4 * * * root /root/learnfromexchange user2 SPAM mail.domain.com spam
32 4 * * * root /root/learnfromexchange user2 CLEAN mail.domain.com ham


So here is the script it has check for the correct ammount or arguments - but not yet for valid values on the arguments - since I only needed to run it from cron

#/bin/bash
ARGS=4         # Script requires 4 arguments.
E_BADARGS=65  # Exit value if incorrect number of args passed.

test $# -ne $ARGS \
 && echo "---------------------------------------------------------" \
 && echo "Usage: `basename $0` username emailfolder type" \
 && echo "Like: learnfromexchange.sh jim SPAM mail.domain.com spam" \
 && echo "---------------------------------------------------------" \
 && exit $E_BADARGS

username=$1
spamfolder=$2
imapserver=$3
foldertype=$4
/usr/bin/fetchmail -a -k -s -n -u $username -p IMAP \
 --folder $spamfolder -m 'bash -c "/usr/bin/tee \
>(/usr/bin/sa-learn --spam --single /dev/null)|/usr/bin/spamc|/usr/bin/rsmtp"'\
 $imapserver



Reply via email to