cyrusimap / cyrus-imapd

Cyrus IMAP is an email, contacts and calendar server
http://cyrusimap.org
Other
528 stars 145 forks source link

[Request] Cyrus RSPAMD Spam / Ham learning #3337

Closed thefiredragon closed 3 years ago

thefiredragon commented 3 years ago

Request handling notification events for training rspamd.

Cyrus sieve does not support like dovecot handle move and copy events to a separated mailbox or filesystem folder for training spam / ham.

I had also wrote over the mailing list and someone means it could be handled over notification events.

At this moment there are no samples for notification events availibe and make it hard to undeestand and wrote a script for it.

The goal would be to trigger an copy if an email will be moved to spam to a spam learning place ( folder or a Email Mailbox like spam@domain.com)

(sogo would Support the same for the web Interface only)

Same would be needed for ham, if an Email will be moved from spam to somewhere else and store a copy to a training place like folder or mailbox.

If someone could help here at this point would be really helpful.

Dovecot Support over sieve such handling. Think without help we could not bring up this feature at this time.

Best Regards

dilyanpalauzov commented 3 years ago

I use SpamAssassin with this script:

#!/bin/bash

/usr/local/bin/inotifywait -e create -qm --format %w\ %f /var/spool/imap/user/*/{Not-,}Spam /var/spool/imap/user/*/Spam1{0,5} | while read DIR FILE; do
 if [ ${DIR: -9} = 'Not-Spam/' ]
    then OP=ham
    else OP=spam
 fi
 spamc -L $OP < $DIR$FILE
 stdbuf -o0 echo `date` Learn as $OP $DIR$FILE >> /var/log/sa-learn.log
done

Any time a user moves an email to to Spam folder, it is learnt as spam, and anytime a message is explicitly moved to the Not-Spam folder, the message is learnt as ham.

I see now in the logs, that the files cyrus.index.NEW and cyrus.cache.NEW are also learnt as spam.

thefiredragon commented 3 years ago

Okay thank you, We think about it, and it's good to know there's a way, think it's better to create 2 mailboxes for spam and ham where users can send spam or ham mails to and we want to training our spam from there.

On mailing list we talked about it and it's not useful if everyone in a large environoment use training, too So it's better customer can forward a spam or ham mail to specific mail address from where we can check in or reject requests for learning.

dilyanpalauzov commented 3 years ago

Here a modified version, skipping feeding cyrus.index.NEW and cyrus.cache.NEW to the spam trainer:

#!/bin/bash

/usr/local/bin/inotifywait -e create -qm --format %w\ %f /var/spool/imap/user/*/{Not-,}Spam | while read DIR FILE; do
 if [ ${FILE:0:5} = 'cyrus' ]; then
    stdbuf -o0 echo `date` Skipping $DIR$FILE >> /var/log/sa-learn.log
 elif [ ${DIR: -9} = 'Not-Spam/' ]
    then OP=ham
    else OP=spam
    spamc -L $OP < $DIR$FILE
    stdbuf -o0 echo `date` Learn as $OP $DIR$FILE >> /var/log/sa-learn.log
 fi
done