File: README

package info (click to toggle)
spamassassin 3.1.7-2
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 5,376 kB
  • ctags: 2,123
  • sloc: perl: 39,706; ansic: 3,133; sh: 1,344; sql: 170; makefile: 168
file content (232 lines) | stat: -rw-r--r-- 8,747 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232

Loading SpamAssassin User Preferences From An SQL Database
----------------------------------------------------------

SpamAssassin can now load users' score files from an SQL database.  The concept
here is to have a web application (PHP/perl/ASP/etc.) that will allow users to
be able to update their local preferences on how SpamAssassin will filter their
e-mail.  The most common use for a system like this would be for users to be
able to update the white list of addresses (whitelist_from) without the need
for them to update their $HOME/.spamassassin/user_prefs file.  It is also quite
common for users listed in /etc/passwd to not have a home directory, therefore,
the only way to have their own local settings would be through an RDBMS system.

Note that this will NOT look for test rules, only local scores,
whitelist_from(s), and required_score.

In addition, any config options marked as Admin Only will NOT be parsed from
SQL preferences.

SpamAssassin will check the global configuration file (ie. any file matching
/etc/mail/spamassassin/*.cf) for the following settings:

  user_scores_dsn		DBI:driver:connection
  user_scores_sql_username	dbusername
  user_scores_sql_password	dbpassword

The first option, user_scores_dsn, describes the data source name that will be
used to create the connection to your SQL server.  It MUST be in the format
as listed above.  <driver> should be the DBD driver that you have installed
to access your database. <connection> can differ depending on which
database you are using.

For MySQL, connection should take the format

  database:hostname[:port]

<database> must be the name of the database that you created to store the user
preference table. <hostname> is the name of the host that contains the SQL
database server. <port> is the optional port number where your database server
is listening.

  user_scores_dsn		DBI:mysql:spamassassin:localhost

Would tell SpamAssassin to connect to the database named spamassassin using
MySQL on the local server, and since <port> is omitted, the driver will use the
default port number.

For PostgreSQL, connection should take the following format:

  dbname=database;[host=hostname;[port=port;]
  
  user_scores_dsn               DBI:Pg:dbname=spamassassin;host=localhost

would do the same as the previous example.

For additional information, please refer to the DBD::* documentation
for your particular driver.

The spamd server will not pay attention to SQL preferences by default,
even with user_scores_dsn set in the config files.  You must startup
spamd with the proper options (ie -q or -Q, see perldoc spamd for more
information).  If the user_scores_dsn option does not exist,
SpamAssassin will not attempt to use SQL for retrieving users'
preferences.

While scanning a message if spamd is unable to connect to the server
specified in user_scores_dsn or an error occurs when querying the SQL
server then spam checking will not be performed on that message.

The user_scores_sql_username and user_scores_sql_password options are
required if your database server requires a username and password to
be sent on connect.

If you have a table layout that differs from the default, please
review the documentation for user_scores_sql_custom_query for
information on how deal with a custom layout.

Requirements
------------

In order for SpamAssassin to work with your SQL database, you must have
the perl DBI module installed, AS WELL AS the DBD driver/module for your
specific database.  For example, if using MySQL as your RDBMS, you must have
the Msql-Mysql module installed.  Check CPAN for the latest versions of DBI 
and your database driver/module. 

We are currently using:

  DBI-1.20
  Msql-Mysql-modules-1.2219
  perl v5.6.1

But older and newer versions should work fine as the SQL code in SpamAssassin
is as simple as could be.


Database Schema
---------------

The database must contain a table, default name "userpref", with at
least three fields:

  username varchar(100)	  # this is the username whose e-mail is being filtered
  preference varchar(30)  # the preference (whitelist_from, required_score, etc.)
  value varchar(100)	  # the value of the named preference

You can add as many other fields you wish as long as the above three fields are
contained in the table.

Note that you can either use just the mail recipient's username for the
"username" field, in which case a varchar(8) should suffice.  Alternatively,
you can use the entire recipient's email address, e.g. "user@example.com", and
use the full varchar(100).

Included is a default table that can be safely used in your own setup.  To use
the default table, you must first create a database, and a username/password
that can access that database.

If you wish to use a table that differs from the included default you
should review the user_scores_sql_custom_query config option for
information on making it work correctly.

To create a database, if one does not already exist, see "Creating A Database"
below.

To install the table to a mysql database, use the following command:

mysql -h <hostname> -u <adminusername> -p <databasename> < userpref_mysql.sql
Enter password: <adminpassword>

This will create the following table:

CREATE TABLE userpref (
  username varchar(100) default NOT NULL,
  preference varchar(30) default NOT NULL,
  value varchar(100) default NOT NULL,
  prefid int(11) NOT NULL auto_increment,
  PRIMARY KEY (prefid),
  INDEX (username)
) TYPE=MyISAM;

For PostgreSQL, use the following command:

psql -U <username> -f userpref_pg.sql <databasename>

This will create a table similar to above.

Once you have created the database and added the table, just add the required
lines to your global configuration file (local.cf).  Note that you must be
running spamc/spamd in order for this to work, and the current username must
be passed to spamd.  This can be done from spamc using the following
.procmailrc recipe:

  :0fw
  | /usr/local/bin/spamc -f

(watch out; spamc could be installed as /usr/bin/spamc instead.)
If you are using this from /etc/procmailrc, you must include DROPPRIVS=yes 
before spamc.  An example /etc/procmailrc:

  DROPPRIVS=yes

  :0fw
  | /usr/local/bin/spamc -f

Also note that spamd may need the "-q" switch so it knows to look up users in
the SQL table instead of /etc/passwd.  See "man spamd".


Creating A Database 
-------------------

Here's the command to create a MySQL database, and user/password pair to access
it:

mysql -h <hostname> -u <adminusername> -p
Enter password: <adminpassword>
mysql> use mysql;
mysql> insert into user (Host, User, Password) values('localhost','<username>', password('<password>'));
mysql> insert into db (Host, Db, User, Select_priv) values('localhost','<databasename>','<username>','Y');
mysql> create database <databasename>;
mysql> quit

NOTE: If you intend to use this database for Bayes and/or AWL data you
may need to grant additional privs (ie Insert_priv, Update_priv and
Delete_priv).  Please refer to the MySQL documentation for the proper
method of adding these privs.

To create the database for PostgreSQL, with a username/password:

psql -U <adminuser> template1
template1=# CREATE USER <username> PASSWORD '<password>';
template1=# CREATE DATABASE <databasename> OWNER = <username>;


Testing SpamAssassin/SQL
------------------------

To test your SQL setup, and debug any possible problems, you should start
spamd with the -D option, which will keep spamd in the foreground, and will
output debug message to the terminal. You should then test spamd with a
message by calling spamc.  You can use the sample-spam.txt file with the
following command:

  cat sample-spam.txt | spamc

Watch the debug output from spamd and look for the following debug line:

  retrieving prefs for <username> from SQL server

If you do not see the above text, then the SQL query was not successful, and
you should see any error messages reported. <username> should be the user
that was passed to spamd and is usually the user executing spamc.

Note that under the default configuration any prefs stored under the
username '@GLOBAL' are used as defaults for all users.

This code has only been tested using MySQL as the RDMS, but it has been written
with the utmost simplicity using DBI, and any database driver that conforms to
the DBI interface should work without problems.

******
NB:  This should be considered BETA, and the interface, schema, or overall
operation of SQL support may change at any time with future releases of SA.
******

Web Interfaces
--------------

Several web interfaces have been created for per user configurations.
You can find more information about these on the SpamAssassin wiki:
http://wiki.apache.org/spamassassin/WebUserInterfaces