Moving IMAP messages from shell after learning SA spam
I am trying to train the SpamAssassin Bayes filter from the shell, but instead of deleting the spam messages I want to move them to an archive. Is there an easy way to do the move via a shell script? What I have doesn't work, as my mail clients still think the mail is in the original folder, and then the messages duplicate.
Here is what i have so far (based on
# Tag spam in the spam maildir, and notspam in the notspam maildir
# MOVE the tagged mail
#
# The virtual domain where the spam and notspam mailboxes live
MAILHOME=/var/spool/mail/virtual/USERNAME
# The spam and notspam mailboxes
SPAMDIR=.Junk
SPAMARC=.Junk_Archive
HAMDIR=.Message_Archive
# Run sa-learn on all the mail, whether it has been seen by a mail reader or not
sa-learn --spam $MAILHOME/$SPAMDIR/new
sa-learn --spam $MAILHOME/$SPAMDIR/cur
# Move tagged mail, so it isn't used again
mv $MAILHOME/$SPAMDIR/new/* $MAILHOME/$SPAMARC/new/
mv $MAILHOME/$SPAMDIR/cur/* $MAILHOME/$SPAMARC/cur/
#mv $MAILHOME/$SPAMDIR/courierimapkeywords/.*
# $MAILHOME/$SPAMARC/courierimapkeywords/
rm $MAILHOME/$SPAMDIR/courierimapkeywords/.*
Anyway, it does seem to move the messages, but clearly isn't doing so in a way valid under IMAP, as as soon as I view the Junk folder in my client the messages reappear, as I mentioned.
Any suggestions on how to properly do this?
Thanks!
Chris
7 Replies
ServerFault
The script:
Some discussion: