| 1 |
What: |
| 2 |
|
| 3 |
This document describes how to use bogofilter to filter mail that passes |
| 4 |
through a qmail mail server. |
| 5 |
|
| 6 |
Theory: |
| 7 |
|
| 8 |
The idea is to setup bogofilter on the mail server and have it filter all |
| 9 |
incoming mail. |
| 10 |
|
| 11 |
There are several advantages to doing so: |
| 12 |
|
| 13 |
1. Mail users on non-unix platforms will benefit from bogofilter spam filtering |
| 14 |
|
| 15 |
2. bogofilter learns better since it has access to a larger corpus. |
| 16 |
|
| 17 |
There is also a mechanism for users to register new spam/nonspam messages, as |
| 18 |
well as correcting misclassifications. |
| 19 |
|
| 20 |
Assumptions: |
| 21 |
|
| 22 |
- Most of the steps described here require root privileges. |
| 23 |
- qmail is installed in /var/qmail. If you installed qmail from rpm, it is |
| 24 |
probably installed in /usr/qmail. |
| 25 |
- You have installed Bruce Guenter's qmail-qfilter program which is available |
| 26 |
from: |
| 27 |
|
| 28 |
http://untroubled.org/qmail-qfilter |
| 29 |
|
| 30 |
- bogofilter is installed in /usr/bin/bogofilter on the mail server. |
| 31 |
|
| 32 |
Installation: |
| 33 |
|
| 34 |
- Create a /home/bogofilter directory if you don't already have one. |
| 35 |
Note that you may change the name and location, if you wish. |
| 36 |
Just remember that you did so! |
| 37 |
|
| 38 |
# mkdir /home/bogofilter |
| 39 |
|
| 40 |
- Change the ownership of /home/bogofilter to the qmail alias user, usually |
| 41 |
called 'alias' |
| 42 |
|
| 43 |
# chown -R alias:alias /home/bogofilter |
| 44 |
|
| 45 |
|
| 46 |
- Build the initial spam and nonspam databases by feeding your corpus of mail. |
| 47 |
Assuming that the files are in mbox format in /home/bogofilter, you say: |
| 48 |
|
| 49 |
# bogofilter -d /home/bogofilter -s < spam.mbx |
| 50 |
# bogofilter -d /home/bogofilter -n < nonspam.mbx |
| 51 |
|
| 52 |
Filtering: |
| 53 |
|
| 54 |
- Create a script to invoke bogofilter, say /home/bogofilter/bogofilter-run, |
| 55 |
modeled on the following: |
| 56 |
|
| 57 |
#!/bin/sh |
| 58 |
exec /usr/bin/qmail-qfilter /usr/bin/bogofilter -d /home/bogofilter -p -u -e |
| 59 |
|
| 60 |
Make sure the script is executable! |
| 61 |
|
| 62 |
Given a good initial corpus, it is better to have bogofilter update its |
| 63 |
lists based on the message classification, since it is quite likely to get |
| 64 |
it right. |
| 65 |
NOTE: Misclassifications MUST be corrected later, else the corpus will |
| 66 |
degrade and misclassifications can get worse over time. |
| 67 |
|
| 68 |
- Setup an /etc/tcpcontrol/qmail.rules entry to trigger the filtering. |
| 69 |
Ideally, you want to filter incoming mail, but not outgoing. |
| 70 |
|
| 71 |
in /etc/tcpcontrol/qmail.rules or its equivalent, enter the default rule: |
| 72 |
|
| 73 |
:allow,QMAILQUEUE="/home/bogofilter/bogofilter-run" |
| 74 |
|
| 75 |
- Now, every incoming message will have the header line |
| 76 |
|
| 77 |
X-Bogosity: ... |
| 78 |
|
| 79 |
added to the headers. |
| 80 |
A bogofilter classified spam messages will have the entry: |
| 81 |
|
| 82 |
X-Bogosity: Spam ... |
| 83 |
|
| 84 |
Note that the actual header name is configurable at compile time and may |
| 85 |
have been changed. |
| 86 |
|
| 87 |
- Educate your users on how to filter their spam based on the value of the |
| 88 |
X-Bogosity header. |
| 89 |
Spam messages should be diverted to a spam mailbox, rather than deleted. |
| 90 |
|
| 91 |
|
| 92 |
Registration and Correction: |
| 93 |
|
| 94 |
Setup an email alias, for users to register new spam or nonspam messages |
| 95 |
as well as to correct misclassification. |
| 96 |
|
| 97 |
- copy contrib/dot-qmail-bogofilter-default to |
| 98 |
/var/qmail/alias/.qmail-bogofilter-default |
| 99 |
|
| 100 |
If you are not using the alias 'bogofilter', you'll need to rename the file |
| 101 |
to your alias and edit the contents |
| 102 |
|
| 103 |
If you are not using /home/bogofilter, you'll need to edit the contents |
| 104 |
|
| 105 |
- copy contrib/bogofilter-qfe script to /home/bogofilter. |
| 106 |
|
| 107 |
Change the domain variable in the script to your domain. Let's assume |
| 108 |
example.com. The script will have to be edited if: |
| 109 |
1. You have multiple domains |
| 110 |
2. Your users use Mail User Agents I don't know about. |
| 111 |
|
| 112 |
Please send me your improvements! |
| 113 |
|
| 114 |
If you wish to save copies of the incoming messages, run the command |
| 115 |
|
| 116 |
# /var/qmail/bin/maildirmake /home/bogofilter/Maildir |
| 117 |
|
| 118 |
and to /var/qmail/alias/.qmail-bogofilter-default, append the line: |
| 119 |
|
| 120 |
/home/bogofilter/Maildir/ |
| 121 |
|
| 122 |
The trailing slash is important. Thanks to John Crawford for reminding me. |
| 123 |
|
| 124 |
- Make sure the script is executable |
| 125 |
|
| 126 |
# chmod +x /home/bogofilter/bogofilter-qfe |
| 127 |
|
| 128 |
- Educate your users to bounce their messages to: |
| 129 |
|
| 130 |
To register: |
| 131 |
spam, send to [email protected] |
| 132 |
nonspam, send to [email protected] |
| 133 |
|
| 134 |
To correct misclassified: |
| 135 |
|
| 136 |
spam, send to [email protected] |
| 137 |
nonspam, send to [email protected] |
| 138 |
|
| 139 |
It is important that users bounce or redirect the messages rather than |
| 140 |
forward them since forwarding loses important header information. |
| 141 |
|
| 142 |
- Done! |
| 143 |
|
| 144 |
NOTE: |
| 145 |
|
| 146 |
If bogofilter generates "out of memory" error messages, check the ulimits |
| 147 |
setting. |
| 148 |
|
| 149 |
TODO: |
| 150 |
|
| 151 |
A message that is delivered to a group alias will be filtered once, but may |
| 152 |
be corrected multiple times. Ideally, the script should only accept the first |
| 153 |
correction and ignore the rest. |
| 154 |
|
| 155 |
Author: |
| 156 |
Gyepi Sam <[email protected]> |
| 157 |
|