• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

READMEH A D20-Mar-20218.4 KiB228161

README.awlH A D20-Mar-20216.9 KiB177132

README.bayesH A D20-Mar-20219 KiB214162

README.txrepH A D20-Mar-20213.8 KiB10270

awl_mysql.sqlH A D20-Mar-2021416 1110

awl_pg.sqlH A D20-Mar-2021729 2722

bayes_mysql.sqlH A D20-Mar-20211.4 KiB4740

bayes_pg.sqlH A D20-Mar-20213.7 KiB120105

txrep_mysql.sqlH A D20-Mar-2021443 1211

txrep_pg.sqlH A D20-Mar-2021746 2822

txrep_sqlite.sqlH A D20-Mar-2021689 2320

userpref_mysql.sqlH A D20-Mar-2021265 98

userpref_pg.sqlH A D20-Mar-2021232 87

README

1
2Loading SpamAssassin User Preferences From An SQL Database
3----------------------------------------------------------
4
5SpamAssassin can now load users' score files from an SQL database.  The concept
6here is to have a web application (PHP/perl/ASP/etc.) that will allow users to
7be able to update their local preferences on how SpamAssassin will filter their
8e-mail.  The most common use for a system like this would be for users to be
9able to update the white list of addresses (whitelist_from) without the need
10for them to update their $HOME/.spamassassin/user_prefs file.  It is also quite
11common for users listed in /etc/passwd to not have a home directory, therefore,
12the only way to have their own local settings would be through an RDBMS system.
13
14Note that this will NOT look for test rules, only local scores,
15whitelist_from(s), and required_score.
16
17In addition, any config options marked as Admin Only will NOT be parsed from
18SQL preferences.
19
20SpamAssassin will check the global configuration file (ie. any file matching
21/etc/mail/spamassassin/*.cf) for the following settings:
22
23  user_scores_dsn		DBI:driver:connection
24  user_scores_sql_username	dbusername
25  user_scores_sql_password	dbpassword
26
27The first option, user_scores_dsn, describes the data source name that will be
28used to create the connection to your SQL server.  It MUST be in the format
29as listed above.  <driver> should be the DBD driver that you have installed
30to access your database. <connection> can differ depending on which
31database you are using.
32
33For MySQL, connection should take the format
34
35  database:hostname[:port]
36
37<database> must be the name of the database that you created to store the user
38preference table. <hostname> is the name of the host that contains the SQL
39database server. <port> is the optional port number where your database server
40is listening.
41
42  user_scores_dsn		DBI:mysql:spamassassin:localhost
43
44Would tell SpamAssassin to connect to the database named spamassassin using
45MySQL on the local server, and since <port> is omitted, the driver will use the
46default port number.
47
48For PostgreSQL, connection should take the following format:
49
50  dbname=database;[host=hostname;[port=port;]
51
52  user_scores_dsn               DBI:Pg:dbname=spamassassin;host=localhost
53
54would do the same as the previous example.
55
56For additional information, please refer to the DBD::* documentation
57for your particular driver.
58
59The spamd server will not pay attention to SQL preferences by default,
60even with user_scores_dsn set in the config files.  You must startup
61spamd with the proper options (ie -q or -Q, see perldoc spamd for more
62information).  If the user_scores_dsn option does not exist,
63SpamAssassin will not attempt to use SQL for retrieving users'
64preferences.
65
66While scanning a message if spamd is unable to connect to the server
67specified in user_scores_dsn or an error occurs when querying the SQL
68server then spam checking will not be performed on that message.
69
70The user_scores_sql_username and user_scores_sql_password options are
71required if your database server requires a username and password to
72be sent on connect.
73
74If you have a table layout that differs from the default, please
75review the documentation for user_scores_sql_custom_query for
76information on how deal with a custom layout.
77
78Requirements
79------------
80
81In order for SpamAssassin to work with your SQL database, you must have
82the perl DBI module installed, AS WELL AS the DBD driver/module for your
83specific database.  For example, if using MySQL as your RDBMS, you must have
84the Msql-Mysql module installed.  Check CPAN for the latest versions of DBI
85and your database driver/module.
86
87We are currently using:
88
89  DBI-1.20
90  Msql-Mysql-modules-1.2219
91  perl v5.6.1
92
93But older and newer versions should work fine as the SQL code in SpamAssassin
94is as simple as could be.
95
96
97Database Schema
98---------------
99
100The database must contain a table, default name "userpref", with at
101least three fields:
102
103  username varchar(100)	  # this is the username whose e-mail is being filtered
104  preference varchar(50)  # the preference (whitelist_from, required_score, etc.)
105  value varchar(100)	  # the value of the named preference
106
107You can add as many other fields you wish as long as the above three fields are
108contained in the table.
109
110Note that you can either use just the mail recipient's username for the
111"username" field, in which case a varchar(8) should suffice.  Alternatively,
112you can use the entire recipient's email address, e.g. "user@example.com", and
113use the full varchar(100).
114
115Included is a default table that can be safely used in your own setup.  To use
116the default table, you must first create a database, and a username/password
117that can access that database.
118
119If you wish to use a table that differs from the included default you
120should review the user_scores_sql_custom_query config option for
121information on making it work correctly.
122
123To create a database, if one does not already exist, see "Creating A Database"
124below.
125
126To install the table to a mysql database, use the following command:
127
128mysql -h <hostname> -u <adminusername> -p <databasename> < userpref_mysql.sql
129Enter password: <adminpassword>
130
131This will create the following table:
132
133CREATE TABLE userpref (
134  username varchar(100) default NOT NULL,
135  preference varchar(50) default NOT NULL,
136  value varchar(100) default NOT NULL,
137  prefid int(11) NOT NULL auto_increment,
138  PRIMARY KEY (prefid),
139  INDEX (username)
140) TYPE=MyISAM;
141
142For PostgreSQL, use the following command:
143
144psql -U <username> -f userpref_pg.sql <databasename>
145
146This will create a table similar to above.
147
148Once you have created the database and added the table, just add the required
149lines to your global configuration file (local.cf).  Note that you must be
150running spamc/spamd in order for this to work, and the current username must
151be passed to spamd.  This can be done from spamc using the following
152.procmailrc recipe:
153
154  :0fw
155  | /usr/local/bin/spamc -f
156
157(watch out; spamc could be installed as /usr/bin/spamc instead.)
158If you are using this from /etc/procmailrc, you must include DROPPRIVS=yes
159before spamc.  An example /etc/procmailrc:
160
161  DROPPRIVS=yes
162
163  :0fw
164  | /usr/local/bin/spamc -f
165
166Also note that spamd may need the "-q" switch so it knows to look up users in
167the SQL table instead of /etc/passwd.  See "man spamd".
168
169
170Creating A Database
171-------------------
172
173Here's the command to create a MySQL database, and user/password pair to access
174it:
175
176mysql -h <hostname> -u <adminusername> -p
177Enter password: <adminpassword>
178mysql> use mysql;
179mysql> insert into user (Host, User, Password) values('localhost','<username>', password('<password>'));
180mysql> insert into db (Host, Db, User, Select_priv) values('localhost','<databasename>','<username>','Y');
181mysql> create database <databasename>;
182mysql> quit
183
184NOTE: If you intend to use this database for Bayes and/or AWL data you
185may need to grant additional privs (ie Insert_priv, Update_priv and
186Delete_priv).  Please refer to the MySQL documentation for the proper
187method of adding these privs.
188
189To create the database for PostgreSQL, with a username/password:
190
191psql -U <adminuser> template1
192template1=# CREATE USER <username> PASSWORD '<password>';
193template1=# CREATE DATABASE <databasename> OWNER = <username>;
194
195
196Testing SpamAssassin/SQL
197------------------------
198
199To test your SQL setup, and debug any possible problems, you should start
200spamd with the -D option, which will keep spamd in the foreground, and will
201output debug message to the terminal. You should then test spamd with a
202message by calling spamc.  You can use the sample-spam.txt file with the
203following command:
204
205  cat sample-spam.txt | spamc
206
207Watch the debug output from spamd and look for the following debug line:
208
209  retrieving prefs for <username> from SQL server
210
211If you do not see the above text, then the SQL query was not successful, and
212you should see any error messages reported. <username> should be the user
213that was passed to spamd and is usually the user executing spamc.
214
215Note that under the default configuration any prefs stored under the
216username '@GLOBAL' are used as defaults for all users.
217
218This code has only been tested using MySQL as the RDMS, but it has been written
219with the utmost simplicity using DBI, and any database driver that conforms to
220the DBI interface should work without problems.
221
222Web Interfaces
223--------------
224
225Several web interfaces have been created for per user configurations.
226You can find more information about these on the SpamAssassin wiki:
227http://wiki.apache.org/spamassassin/WebUserInterfaces
228

README.awl

1
2Using SpamAssassin Auto-Whitelists With An SQL Database
3-------------------------------------------------------
4
5SpamAssassin can now load users' auto-whitelists from a SQL database.
6The most common use for a system like this would be for users to be
7able to have per user auto-whitelists on systems where users may not
8have a home directory to store the whitelist DB files.
9
10In order to activate the SQL based auto-whitelist you have to
11configure spamassassin and spamd to use a different whitelist factory.
12This is done with the auto_whitelist_factory config variable, like
13so:
14
15auto_whitelist_factory Mail::SpamAssassin::SQLBasedAddrList
16
17SpamAssassin will check the global configuration file (ie. any file
18matching /etc/mail/spamassassin/*.cf) for the following settings:
19
20user_awl_dsn                 DBI:driver:database:hostname[:port]
21user_awl_sql_username        dbusername
22user_awl_sql_password        dbpassword
23
24The first option, user_awl_dsn, describes the data source name that
25will be used to create the connection to your SQL server.  It MUST be
26in the format as listed above.  <driver> should be the DBD driver that
27you have installed to access your database (initially tested with
28MySQL (driver is 'mysql'), PostgreSQL ('Pg') and SQLite ('SQLite')).
29<database> must be the name of the database that you created to store
30the auto-whitelist table. <hostname> is the name of the host that contains
31the SQL database server.  <port> is the optional port number where your
32database server is listening.
33
34user_awl_dsn                DBI:mysql:spamassassin:localhost
35
36Would tell SpamAssassin to connect to the database named spamassassin using
37MySQL on the local server, and since <port> is omitted, the driver will use the
38default port number.  The other two required options tells SpamAssassin to use
39the defined username and password to establish the connection.
40
41If the user_awl_dsn option does not exist, SpamAssassin will not attempt
42to use SQL for the auto-whitelist.
43
44One additional configuration option exists that allows you to set the
45table name for the auto-whitelist table.
46
47user_awl_sql_table           awl
48
49For an example of connecting to a PostgreSQL database, see the README file.
50
51Requirements
52------------
53
54In order for SpamAssassin to work with your SQL database, you must have
55the perl DBI module installed, AS WELL AS the DBD driver/module for your
56specific database.  For example, if using MySQL as your RDBMS, you must have
57the Msql-Mysql (DBD::mysql) module installed.  Check CPAN for the latest
58versions of DBI and your database driver/module.
59
60We are currently using:
61
62DBI-1.60.9
63DBD-mysql-4.012
64perl v5.10.1
65
66But older versions should work fine.
67
68
69Database Schema
70---------------
71
72The database must contain a table named by 'user_awl_sql_table' (default
73setting: "awl") with at least these fields:
74
75  username varchar(100)	  # this is the username whose e-mail is being filtered
76  email varchar(200)      # this is the address key
77  ip    varchar(40)       # this is the ip key (fits IPv4 or IPv6)
78  msgcount int(11)        # this is the message counter
79  totscore float          # this is the total calculated score
80  signedby varchar(255)   # a DKIM or DomainKeys signing domain(s)
81
82You can add as many other fields you wish as long as the above fields are
83contained in the table.
84
85The 'signedby' field was introduced in version 3.3.0 and is only needed
86if auto_whitelist_distinguish_signed is true, e.g. (in local.cf):
87  auto_whitelist_distinguish_signed 1
88and is only useful if a plugin DKIM is enabled. If the setting is off
89the field is not used, but it does no harm to have it in a table.
90The new field makes AWL keep separate records for author addresses with
91valid DKIM or DomainKeys signatures, and separate records for unsigned mail,
92which does a good job for popular domains such as gmail.com and yahoo.com
93where most of the spam claiming to be from such domain does not come from
94a freemail provider and therefore can not carry a valid signature.
95
96Included is a default table that can be safely used in your own setup.
97To use the default table, you must first create a database, and a
98username/password that can access that database.  (See "Creating A Database",
99in "sql/README", if you don't have a suitable database ready.)
100
101To install the table, use the following command:
102
103mysql -h <hostname> -u <adminusername> -p <databasename> < awl_mysql.sql
104Enter password: <adminpassword>
105
106This will create the following table:
107
108CREATE TABLE awl (
109  username varchar(100) NOT NULL default '',
110  email varchar(255) NOT NULL default '',
111  ip varchar(40) NOT NULL default '',
112  msgcount int(11) NOT NULL default '0',
113  totscore float NOT NULL default '0',
114  signedby varchar(255) NOT NULL default '',
115  PRIMARY KEY (username,email,signedby,ip)
116) TYPE=MyISAM;
117
118
119For PostgreSQL, use the following:
120
121psql -U <username> -f awl_pg.sql <databasename>
122
123
124To add a field 'signedby' to an existing table and to modify a primary key:
125under MySQL:
126  ALTER TABLE awl
127    DROP PRIMARY KEY,
128    ADD signedby varchar(255) NOT NULL DEFAULT '',
129    ADD PRIMARY KEY (username,email,signedby,ip);
130under PostgreSQL:
131  DROP INDEX awl_pkey;
132  ALTER TABLE awl
133    ADD signedby varchar(255) NOT NULL DEFAULT '',
134    ADD PRIMARY KEY (username,email,signedby,ip);
135then add the following to local.cf to let SpamAssassin start using the
136newly added field 'signedby' :
137  auto_whitelist_distinguish_signed 1
138
139To extend a field awl.ip on an existing table to be able to fit
140an IPv6 addresses (39 characters would suffice) or an IPv4 address:
141under MySQL:
142  ALTER TABLE awl MODIFY ip varchar(40);
143under PostgreSQL:
144  ALTER TABLE awl ALTER ip TYPE varchar(40);
145
146
147Once you have created the database and added the table, just add the
148required lines to your global configuration file (local.cf).  Note that
149you must specify the proper whitelist factory in the config file in order
150for this to work and the current username must be passed to spamd.
151
152Testing SpamAssassin/SQL
153------------------------
154
155To test your SQL setup, and debug any possible problems, you should start
156spamd with the -D option, which will keep spamd in the foreground, and will
157output debug message to the terminal. You should then test spamd with a
158message by calling spamc.  You can use the sample-spam.txt file with the
159following command:
160
161cat sample-spam.txt | spamc
162
163Watch the debug output from spamd and look for the following debug line:
164
165SQL Based AWL: Connected to <your dsn>
166
167If you do not see the above text, then the SQL query was not successful,
168and you should consult any error messages reported.
169
170This code has been tested using MySQL as the RDBMS, with basic tests
171against PostgreSQL and SQLite.  It has been written with the utmost
172simplicity using DBI, and any database driver that conforms to the DBI
173interface and allows you to refer to a column on the right hand side
174of an expression (ie update foo set bar = bar + 1) should work with
175little or no problems.  If you find a driver that has issues, please
176report them to the SADev list.
177

README.bayes

1
2Using A SQL Database for Bayesian Storage Module
3-------------------------------------------------------
4
5SpamAssassin can now store users' bayesian filter data in a SQL
6database.  The most common use for a system like this would be for
7users to be able to have per user bayesian filter data on systems
8where users may not have a home directory to store the data.
9
10In order to activate the SQL based bayesian storage you have to
11configure spamassassin and spamd to use a different bayes storage
12module.  This can be done via a setting in the global configuration
13file.
14
15The directives required to turn on the SQL based bayesian storage are:
16
17bayes_store_module		   Mail::SpamAssassin::BayesStore::SQL
18
19This directive is used by the Bayes module to determine which storage
20module should be used. If not set it will default to:
21Mail::SpamAssassin::BayesStore::DBM
22
23The storage module Mail::SpamAssassin::BayesStore::SQL is an older generic
24SQL module which can be also be used with versions of MySQL which did not
25have support for an InnoDB engine and transactions. If choosing this module
26consider replacing the InnoDB engine with MyISAM (explicitly or defaulted)
27in the schema (files bayes_mysql.sql and awl_mysql.sql). Note that old
28versions of MySQL expect syntax TYPE=MyISAM instead of ENGINE=MyISAM,
29while newer versions throw a syntax error on TYPE and only allow ENGINE.
30In short: replace ENGINE=InnoDB with TYPE=MyISAM (or just leave it out)
31in the bayes_mysql.sql and awl_mysql.sql schemas if ENGINE=InnoDB is not
32accepted.
33
34There is also a MySQL specific storage driver available to provides a
35small boost in performance.  It requires version 4.1 or above of the
36MySQL database software to work properly.  In addition, it provides
37rollback on error functionality if you create your bayes database table
38using the InnoDB storage engine. WARNING: Using this module with a version
39of MySQL < 4.1 could have unexpected results.  To use the MySQL 4.1+
40specific module set your bayes_store_module directive accordingly:
41  bayes_store_module               Mail::SpamAssassin::BayesStore::MySQL
42
43PostgreSQL users will want to use the PostgreSQL specific storage
44module:
45  bayes_store_module               Mail::SpamAssassin::BayesStore::PgSQL
46This module provides a slightly different interface to makes better
47use of the resources that PostgreSQL offers.  In addition, please make
48sure that you follow the instructions below for loading the proper
49procedural language and installing the tables and stored procedure.
50
51Additional configuration directives provided by BayesSQL:
52
53bayes_sql_dsn			   DBI:driver:database:hostname[:port]
54bayes_sql_username		   dbusername
55bayes_sql_password		   dbpassword
56
57The bayes_sql_dsn directive describes the data source name that will
58be used to create the connection to your SQL server.  It MUST be in
59the format as listed above.  <driver> should be the DBD driver that
60you have installed to access your database (initially tested with
61MySQL, PostgreSQL, and SQLite).  <database> must be the name of the
62database that you created to store the bayes data tables. <hostname>
63is the name of the host that contains the SQL database server.
64<port> is the optional port number where your database server is
65listening.
66
67For an example of connection to PostgreSQL, see the main README file.
68
69In addition to the global configuration directives there is a user
70preference:
71
72bayes_sql_override_username	   someusername
73
74This directive, if used, will override the username used for storing
75data in the database.  This could be used to group users together to
76share bayesian filter data.  You can also use this config option to
77trick sa-learn to learn data as a specific user.
78
79
80Requirements
81------------
82
83In order for SpamAssassin to work with your SQL database, you must
84have the perl DBI module installed, AS WELL AS the DBD driver/module
85for your specific database.  For example, if using MySQL as your
86RDBMS, you must have the DBD::mysql module installed, a PostgreSQL
87database requires DBD::Pg.  Check CPAN for latest versions of DBI
88and your database driver/module.
89
90The BayesStore::SQL module was tested with:
91
92DBI-1.38
93DBD-mysql-2.9002
94perl v5.8.0
95
96But older (and newer) versions should work fine as the SQL code in
97SpamAssassin is as simple as could be.
98
99NOTE: Some users have reported problems using DBD::Pg v1.22. There appears
100to be a bug in how parameters are quoted in that version, we recommend you
101upgrade to at least v1.31.
102
103In addition, there appears to be a quote bug in some versions of PostgreSQL.
104It's unclear when the bug was fixed.  7.4.2 seems to work just fine, however
105some have reported problems with 7.3.6.  Your mileage may vary with versions
106less than 7.4.2.  If you happen to know when the specific bug was fixed please
107feel free to notify the dev team so they can update this documentation.
108
109Database Schema
110---------------
111
112The database schema for storage of the bayesian filter data contains
113several different tables.  Several sample SQL schemas have been
114included in to help in setting up your database.  The schemas contain
115the minimum tables and columns necessary to work with the code as
116written.  You are free to add other columns as needed for your local
117implementation.  Presently there is no way to override the table and
118column names used by the BayesStore::SQL code, this feature may be added
119in the future.
120
121Example setup of bayes tables for MySQL:
122
123This assumes that you have already created a database for use with
124spamassassin and setup a username/password that can access that database.
125(See "Creating A Database", in "sql/README", if you don't have a suitable
126database ready.)
127
128To install the tables using the included example, use the following command:
129
130mysql -h <hostname> -u <adminusername> -p databasename < bayes_mysql.sql
131Enter password: <adminpassword>
132
133To install the tables for PostgreSQL, use:
134
135You need to install the plpgsql procedural language (assuming it
136hasn't already been installed in template1). You can do this by
137running the following command:
138
139createlang plpgsql <databasename>
140
141and then:
142
143psql -U <username> -f bayes_pg.sql <databasename>
144
145From a security viewpoint, it is wise to grant the minimum privileges
146needed to the user on the bayes tables.  These grants largely depend
147on your system policies but here are some example grants to get you
148started, please review carefully before putting into production:
149
150GRANT SELECT, UPDATE, DELETE, INSERT ON TABLE bayes_token TO <username>;
151GRANT SELECT, UPDATE, DELETE, INSERT ON TABLE bayes_vars TO <username>;
152GRANT SELECT, UPDATE, DELETE, INSERT ON TABLE bayes_seen TO <username>;
153GRANT SELECT, DELETE, INSERT ON TABLE bayes_expire TO <username>;
154GRANT SELECT ON TABLE bayes_global_vars TO <username>;
155GRANT USAGE, SELECT, UPDATE ON SEQUENCE bayes_vars_id_seq TO <username>;
156
157Once you have created the database and added the tables, just add the
158required lines to your global configuration file (local.cf).
159
160Testing SpamAssassin/SQL
161------------------------
162
163To test your SQL setup, and debug any possible problems, you should
164start spamd with the -D option, which will keep spamd in the
165foreground, and will output debug message to the terminal. You should
166then test spamd with a message by calling spamc.  You can use the
167sample-spam.txt file with the following command:
168
169spamc < sample-spam.txt
170
171Watch the debug output from spamd and look for the following debug
172line:
173
174debug: bayes: Database connection established
175debug: bayes: Using username: <username>
176
177If you do not see the above text, then the SQL query was not
178successful, and you should see any error messages reported.
179
180This code has been tested using MySQL as the RDMS, with basic tests
181against PostgreSQL and SQLite.  It does require a database that allows
182you to refer to a column on the right hand side of an expression (ie
183update foo set bar = bar + 1).  Any database driver that allows for
184that usage should work with the BayesStore::SQL code.  NOTE: You may
185find that some implementations do not provide a significant advantage
186over using the default DBM implementation.  If you find a driver that
187should work and has issues, please report them to the SADev list.
188
189Converting Bayes Data From a DBM Database
190-----------------------------------------
191
192Converting your bayes database data from Berkeley (DBM) based storage
193to SQL based storage is as simple as a backup and then restore.
194
195If you are upgrading from a previous version of SpamAssassin you
196should first follow any recommended upgrade instructions for that
197release, in most cases this will be as simple as running an
198sa-learn --sync
199
200Once you have performed this upgrade, for each bayes database follow
201this procedure:
202
203o Run 'sa-learn --backup > backup.txt' which will backup your bayes
204  data into a text file.
205o Optionally you can run 'sa-learn --clear' to remove the DBM based
206  bayes files.
207o Modify your local.cf file according to the directions above.
208o Run 'sa-learn --restore backup.txt' to restore your bayes data to
209  the SQL database.
210
211NOTE: sa-learn must be run as the user who's data you are loading, or
212      you must make use of the bayes_sql_override_username config
213      option.
214

README.txrep

1
2Using SpamAssassin Automatic Reputation With An SQL Database
3-------------------------------------------------------
4
5The TxRep plugin improves on the earlier Auto-Whitelist plugin.
6The most common use for a system like this would be for tracking
7the expected spam score (or reputation) of frequent senders. A
8domain that sends frequent spam will lose reputation (or gain
9spam score) over time.
10
11In order to activate the SQL based reputation system you have to
12configure spamassassin and spamd to use the appropriate storage
13backend. This is done with the txrep_factory config variable,
14like so:
15
16txrep_factory Mail::SpamAssassin::SQLBasedAddrList
17
18SpamAssassin will check the global configuration file (ie. any file
19matching /etc/mail/spamassassin/*.cf) for the following settings:
20
21user_awl_dsn                 DBI:driver:database:hostname[:port]
22user_awl_sql_username        dbusername
23user_awl_sql_password        dbpassword
24
25These settings are identical to those for the AWL plugin, so you
26do not need to change these if you are upgrading.
27
28The first option, user_awl_dsn, describes the data source name that
29will be used to create the connection to your SQL server.  It MUST be
30in the format as listed above.  <driver> should be the DBD driver that
31you have installed to access your database (the most common being
32MySQL (driver is 'mysql'), PostgreSQL ('Pg') and SQLite ('SQLite')).
33<database> must be the name of the database that you created to store
34the txrep table. <hostname> is the name of the host that contains
35the SQL database server.  <port> is the optional port number where your
36database server is listening.
37
38user_awl_dsn                DBI:mysql:spamassassin:localhost
39
40Would tell SpamAssassin to connect to the database named spamassassin using
41MySQL on the local server, and since <port> is omitted, the driver will use
42the default port number.  The other two required options tells SpamAssassin
43to use the defined username and password to establish the connection.
44
45If the user_awl_dsn option does not exist, SpamAssassin will not attempt
46to use SQL for tracking reputations.
47
48One additional configuration option exists that allows you to set the
49table name for the txrep table.
50
51user_awl_sql_table           txrep
52
53For an example of connecting to a PostgreSQL database, see the README file.
54
55Requirements
56------------
57
58In order for SpamAssassin to work with your SQL database, you must have
59the perl DBI module installed, AS WELL AS the DBD driver/module for your
60specific database.  For example, if using MySQL as your RDBMS, you must have
61the Msql-Mysql (DBD::mysql) module installed.  Check CPAN for the latest
62versions of DBI and your database driver/module.
63
64Database Schema
65---------------
66
67The database must contain a table named by 'user_awl_sql_table' (default
68setting: "txrep") with at least the fields specified in the accompanying
69SQL files.
70
71You can add as many other fields you wish as long as the required fields
72are contained in the table.
73
74To install the table, use the following command:
75
76mysql -h <hostname> -u <adminusername> -p <databasename> < txrep_mysql.sql
77Enter password: <adminpassword>
78
79For PostgreSQL, use the following:
80
81psql -U <username> -f txrep_pg.sql <databasename>
82
83Once you have created the database and added the table, just add the
84required lines to your global configuration file (local.cf).  Note that
85you must specify the proper storage backend in the config file in order
86for this to work and the current username must be passed to spamd.
87
88Maintenance
89---------------
90
91It is recommended to keep user_awl_sql_table clear of stale data, for
92performance reasons. A sample query that can be run on a regular
93schedule is below:
94
95DELETE FROM txrep WHERE last_hit <= (now() - INTERVAL 120 day);
96
97For PostgreSQL, use the following:
98
99DELETE FROM txrep WHERE last_hit <= (now() - INTERVAL '120 day');
100
101
102