Moving IMAP messages from shell after learning SA spam

Hi all,

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 http://www.trumphurst.com/weblog/tagspam.html):

# 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

Did I post this in the wrong forum?

Try ServerFault, I guess no one here knows the answer.

I use something similar and it works for me. Well, my setup is based on Dovecot/IMAP.

Thanks, are you able to post what you use?

Sorry, I do not use anything special, just mv like you. The difference is that you (according to your paste above) use Courier as IMAP server, while I use Dovecot as IMAP server. Thus the solution should be 'switch to Dovecot'. It does not sound reasonable to switch just because of that. Still, Dovecot is popular and secure, with many features. I myself had used Courier years ago, and switched to the Dovecot, do not regret it.

OK, thanks I'll have another shot at it.

Have a look at 'cleanup-maildir', a python script.

The script: http://svn.houseofnate.net/unix-tools/t … up-maildir">http://svn.houseofnate.net/unix-tools/trunk/cleanup-maildir

Some discussion: http://www.ducea.com/2006/11/25/cleanup … old-mails/">http://www.ducea.com/2006/11/25/cleanup-maildir-folders-archive-delete-old-mails/

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct