We will allow users to categorize mail as Spam by placing them in user-specific Spam mailboxes. Contrary moving a message flagged as Spam to any other mailbox will relearn it as Ham.
IMAPSieve configuration
Dovecot supports this via its IMAPSieve plugin which we will configure in our custom configuration
# 90-sieve.conf: # ---------------------------------------------------------------------- # Messages can be marked as SPAM or HAM by moving them between mailboxes plugin { sieve_global_dir = /var/vmail/conf.d/%d/sieve sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.execute sieve_plugins = sieve_imapsieve sieve_extprograms # From elsehwhere to Spam folder imapsieve_mailbox1_name = Spam imapsieve_mailbox1_causes = COPY imapsieve_mailbox1_before = file:/var/vmail/conf.d/rspamd/report-spam.sieve # From Spam folder to elsewhere imapsieve_mailbox2_name = * imapsieve_mailbox2_from = Spam imapsieve_mailbox2_causes = COPY imapsieve_mailbox2_before = file:/var/vmail/conf.d/rspamd/report-ham.sieve } # 90-sieve-extprograms.conf: # ---------------------------------------------------------------------- plugin { sieve_pipe_bin_dir = /var/vmail/conf.d/rspamd }
Learning scripts
The following scripts will be stored in
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"]; if environment :matches "imap.mailbox" "*" { set "mailbox" "${1}"; } if string "${mailbox}" "Trash" { stop; } pipe :copy "rspamc-learn-ham.sh";
The actual learn trigger is a simple one-liner
exec /usr/bin/rspamc learn_ham
Classifying Spam is straight-forward based on the triggers defined in Dovecot. If a message is copied to the Spam mailbox it will be learned as Spam.
require ["vnd.dovecot.pipe", "copy"]; pipe :copy "rspamc-learn-spam.sh";
exec /usr/bin/rspamc learn_spam