Automatic mail processing
Using SpamAssassin
With the xfilter command, Maildrop passes the e-mail message to another command. This can be used to filter spam through SpamAssassin.
SpamAssassin modifies the e-mail message, adding a few X-Spam- headers to the message. With an regular expression, Maildrop can move spam messages to a different folder.
- Filtering Spam: ~/.mailfilter
# Unless an external MDA already filtered the message, # let spamassassin modify the message first. # Also continue if spamassassin fails. # if( ! /^X-Spam-Flag/ ) { exception { xfilter "/usr/bin/spamassassin -x" } } # SpamAssassin leaves a X-Spam-Flag field # in the header, check for it if( /^X-Spam-Flag: YES/ ) { log "---- *SPAM* detected. " exception { # the exception clause causes maildrop to ignore errors to "$MAILBOX/.Spam/" } } # If these other headers are found, also # move the message to the spam folder # if( ( /vdboor-remove_this/ ) \ || ( /X-Mailer: Easy Mass Mailer/ ) \ || ( /top--sites.net/ ) \ || ( /staff@hotmail.com/ ) ) { log "---- *SPAM* manually filtered header" to "$MAILBOX/.Spam/" }
Training
The filter of SpamAssassin can be trained with the sa-learn command. It needs to know which e-mail messages are considered spam, and which are normal messages (ham).
The sa-learn needs to know the folder where the messages are stored. For Courier IMAP, this folder location is a bit obscure. Subfolders start with a dot, read messages are stored in the "cur" folder, new messages are stored in the "new" folder.
- Training the spam filter:
sa-learn --showdots --ham ~/.maildir/.codingdomain.vdboor/cur/ sa-learn --showdots --spam ~/.maildir/.Spam/cur/