Forums

Resolved
0 votes
I occasionally get spam emails which are not recognised as such, and ham emails which are being filed as spam.

I want to set up a system for the users to tell spamassassin about unrecognised spam, and incorrectly spammed ham. To that end I set up additional folders in each user's mailboxes for Junk and NotSpam. The users move any spam they find in their inbox to Junk, and and normal mail they find in their spam to NotSpam.

I now want to write or find a script which will look in the Junk folder, send the contents to sa-learn --spam, then move the messages to the regular spam folder. It should also look in the NotSpam folder, send the contents to sa-learn --ham, and move them into the inbox.

I have tried to write shell scripts for this, and I have also downloaded and tried to follow sa-learn-cyrus, plus looked at the script I found at wiki.apache.org/spamassassin/RemoteImapFolder.

My script finds the email files OK, and sends them to sa-learn (although I worry that the Spam score and subject alteration should really be reversed before doing this, and I don't know how). I'm stuck on moving the messages to the correct folder, as I suspect a plain Linux mv command will just confuse cyrus, as it has cache, header, index and squat files in the folder, which presumably need to be updated.

sa-learn-cyrus seems to be able to find emails ok, but (as far as I can tell from running it in simulate mode) it does not attempt to move the mails to the right folder, just purges them.

The other script runs OK (after suitable modifications for my setup), but the Junk emails keep reappearing in the inbox.

Specific questions I need to answer are:

1) Why does mail with [SPAM] in the Subject still appear in the INBOX?

2) Is there an existing script which does what I want?

3) What is the proper method to move an email from one mailbox folder to another in Cyrus? Ideally callable from a shell script.
Tuesday, January 30 2018, 03:58 PM
Share this post:
Responses (2)
  • Accepted Answer

    Tuesday, January 30 2018, 08:56 PM - #Permalink
    Resolved
    0 votes
    Guessing here, but from this link, you can probably just do:
    sa-learn --showdots --mbox --spam /var/spool/imap/{user_initial}/user/{username}/Junk/
    I can't find a way of scripting file movement for the moment. The only way I know of scripting a move is to use imapsync, but it is a non-starter as you need to know everyone's passwords.
    The reply is currently minimized Show
  • Accepted Answer

    Friday, February 02 2018, 08:35 PM - #Permalink
    Resolved
    0 votes
    I have approached the idea from a different, and I think better, angle. All mail which SpamAssassin things is spam has an X-Spam-Flag: YES header, and mail which it thinks is ham has a X-Spam-Flag: NO header. So, if I just tell users to move any misfiled mail into the right folder, I can then look through it for headers which don't match the folder.

    To that end, I have written a bash script to do that very job, and placed it on GitHub at cyrus-mark-ham-spam.
    The reply is currently minimized Show
Your Reply