Patch for dovecot-antispam-plugin to support IMAP Flags indicating Junk status

Jonas Wielicki jonas at
Fri Nov 25 10:43:41 UTC 2016

Hash: SHA512

Dear list,

I made a patch which extends dovecot-antispam-plugin with support to take the 
addition and removal of a specific set of flags as trigger for learning.

This allows for very tight integration with Thunderbird and KMail, which both 
set flags for Junk messages (Thunderbird sets "Junk", KMail sets "JUNK"). With 
this patch and according configuration, dovecot-antispam-plugin can trigger on 
the addition (learn as spam) and removal (learn as ham) of these flags.

Combined with a sieve script which sets these flags for incoming mail which 
has been classified as spam, this allows for a tight and intuitive feedback 
loop between users and the server-side spam classification system.

I tested that patch with dovecot 2.2 from Debian stretch and so far it works 
pretty well.

I realise that dovecot-antispam-plugin has not been updated since 2013. It 
also has not been migrated to Github yet. If it is to be migrated there, I 
would be happy to submit a pull request there for discussion and merging. 
Otherwise, someone would have to indicate how to go forward with applying this 
patch to the official version, if that is desired.

The patch is based on current tip and feedback is appreciated. I took some 
inspiration from dovecot-core/src/plugins/notify/notify-storage.c -- this 
requires the use of struct mail_private to be able to override the vfunc for 
mail_update_keywords, which I actually do not like. However, when I tried to 
make this patch base on the use of the notify plugin (via notify_register), I 
ran into the issue that the transaction is partially freed before the 
transaction_commit event from notify is emitted, which is unfortunate and 
breaks at least the mailtrain backend (which I use). This is in theory 
fixable, but I wanted to keep the patch as small as possible, as I have no 
idea whether this will eventually end up upstream or whether I’ll have to 
maintain that for myself.

If upstream is not interested in this patch, please let me know! In that case, 
I would consider making an own plugin, which fewer backends (possibly only a 
mailtrain-like one) out of this, but frankly, I would consider that a waste of 

In the hope that this is useful for others and hoping for feedback,
Jonas Wielicki

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Trigger-learning-on-change-of-configurable-IMAP-Flag.patch
Type: text/x-patch
Size: 7147 bytes
Desc: not available
URL: <>

More information about the dovecot mailing list