The normal recommended CRM114 spam-training method is to forward mis-classified emails back to yourself, embedding a command sequence that tells the filter to re-classify the message. (See the CRM114 Mailfilter HOWTO.) This is awkward, and hard to explain to non-technical users. (Also, the headers usually get modified by the email client when forwarding. This is not helpful to the retraining process, since the original headers are usually full of spam-related information.)
Instead, I've written a script that scans an IMAP/maildir folder for messages to re-classify. When the user drops a message into this folder, the script determines (without requiring user input) how it was originally classified, and it issues the appropriate re-learn commands. If the new classification is "SPAM", the message is then deleted. If the new classification is "NON-SPAM", then the script calls procmail to re-deliver the message.
This script assumes that you are using procmail as the local delivery agent, and that you are using a Maildir or IMAPdir structure to store the IMAP folders. (If you are using an mbox structure instead of Maildir or IMAPdir, see John Johnston's modified mbox-enabled script instead.)
Your .procmailrc file must include something like:
:0fw: .msgid.lock | /usr/bin/crm -u $HOME/crm114_workingdir mailfilter.crm :0: * ^X-CRM114-Status: SPAM.* INBOX.checkspam/to enable CRM114 filtering to begin with.
In $HOME/crm114_workingdir, you need to set up the standard mailfilter configuration files:
rewrites.mfp whitelist.mfp blacklist.mfp scrub_mailfile_rewrites.mfp priolist.mfp mailfilter.cfas well as the
mailfilter.crmscript. You also need to generate initial spam.css and nonspam.css files using:
cssutil -b -r spam.css cssutil -b -r nonspam.cssThen set up a cron job for the root user, like
*/2 * * * * /opt/procmail-recipes/fix-spam-classification.pl > /dev/nullto run the re-classifying script every 2 minutes. The fix-spam-classification.pl perl source code is available here: