Mercurial > hg > Blog
changeset 102:94bbe517a174
Automated merge with ssh://xanthippe//home/dirk/Projekte/Blog
author | Dirk Olmes <dirk.olmes@codedo.de> |
---|---|
date | Sat, 28 Mar 2020 02:43:15 +0100 |
parents | ec4fc0b8cc08 (diff) 0e63edd28f55 (current diff) |
children | 6aa2fa328a94 |
files | |
diffstat | 1 files changed, 44 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/content/Linux/bogofilter.md Sat Mar 28 02:43:15 2020 +0100 @@ -0,0 +1,44 @@ +Title: Filtering spam mails with bogofilter +Date: 2020-03-22 +Lang: en + +I'm running a [Postfix](http://www.postfix.org/) server here at home to process incoming mail. To integrate spam filtering I'm delivering mails via [procmail](https://en.wikipedia.org/wiki/Procmail) - it's as simple as setting `mailbox_command = /usr/bin/procmail` in postfix' `main.cf`. + +Spam filtering works by invoking the filter ([bogofilter](https://bogofilter.sourceforge.io/) in my case) from procmail like this: + + :::shell + :0 fw + | /usr/bin/bogofilter -uep + +This command will pipe the mail content through bogofilter which will add a `X-Bogosity` header denoting the spam status of the mail. + +A second procmail rule moves all spam to a designated spam folder on my IMAP server: + + :::shell + :0 + * ^X-Bogosity: Spam.* + $HOME/.maildir/.INBOX.Spam/ + +For training I use two designated folders on my IMAP server: *LearnSpam* and *LearnGood*. I'm simply moving mails that I want to train as spam to the *LearnSpam* folder. Once per hour I train spam/good mails using this script: + + :::shell + #!/bin/bash + SPAM_FOLDER=$HOME/.maildir/.INBOX.Spam.LearnSpam + if [[ -d $SPAM_FOLDER ]]; then + SPAM_CUR=$SPAM_FOLDER/cur + # only invoke bogofilter if there are mails in the folder + if [[ "$(ls -A $SPAM_CUR)" ]]; then + /usr/bin/bogofilter -s -B $SPAM_FOLDER && rm $SPAM_CUR/* + fi + fi + HAM_FOLDER=$HOME/.maildir/.INBOX.Spam.LearnGood + if [[ -d $HAM_FOLDER ]]; then + HAM_CUR=$HAM_FOLDER/cur + # only invoke bogofilter if there are mails in the folder + if [[ "$(ls -A $HAM_CUR)" ]]; then + /usr/bin/bogofilter -n -B $HAM_FOLDER && rm $HAM_CUR/* + fi + fi + +The script is invoked via cron. +