SA per-user preferences

From The Network People, Inc.

Jump to: navigation, search

How do I set up per-user SpamAssassin preferences on Mail::Toaster?

To configure SpamAssassin, follow the SQL directions on the SpamAssassin site.

I've added a little bit of support to toaster_setup.pl to help you on your way. Edit toaster-watcher.conf and set the following values:

install_spamassassin_sql = 1 # use AWL, bayes, and per-user prefs from MySQL
install_spamassassin_dbuser = spamassassin
install_spamassassin_dbpass = assSPAMing

Don't forget to create the MySQL user and password for access to the spamassassin database. Here's the command to create a MySQL database, and user/password pair to access it:

mysql -h host -u adminuser-p
Enter password: adminpass
mysql> use mysql;
mysql> insert into user (Host, User, Password) values('localhost','user', password('pass'));
mysql> insert into db (Host, Db, User, Select_priv, Insert_priv, Update_priv, Delete_priv) values('localhost','dbname','user','Y');
mysql> create database spamassassin;
mysql> quit


Contents

What are some common values to stick in userpref?

insert into userpref (username, preference, value) VALUES ('@GLOBAL', 'required_score', '12.0');
insert into userpref (username, preference, value) VALUES ('@GLOBAL', 'whitelist_from', '*@tnpi.biz');
insert into userpref (username, preference, value) VALUES ('bob@example.com', 'required_score', '5.5');
insert into userpref (username, preference, value) VALUES ('bob@example.com', 'whitelist_from', 'alerts@dealnews.com');
insert into userpref (username, preference, value) VALUES ('bob@example.com', 'blacklist_from', '*@spammer.com');


How can users edit their per-user settings?

There are various web interfaces to SpamAssassin, my favorite being the SquirrelMail plugin. There is a page on the SpamAssassin wiki listing the available web interfaces. Instructions for a couple of them follow.

Install the Squirrelmail SpamAssassin plugin (SASQL)

The official plugin page for sasql can be found here

1. Download the current sasql source and save it to /usr/local/src/.

2. Go to the Squirrelmail plugins directory and unpack sasql:

cd /usr/local/www/squirrelmail/plugins
tar zxvf /usr/local/src/sasql-x.x.x.tar.gz

3. Create the sasql configuration file:

cd sasql
cp sasql_conf.php.dist sasql_conf.php

4. Edit the configuration file and set the DSN & proper userpref table:

a. The DSN line should look like:
$SqlDSN = 'mysql://spamassassin:dbpassword@localhost/spamassassin';
b. The table line should look like:
$SqlTable = 'userpref';

5. Run the Squirrelmail config utility:

cd /usr/local/www/squirrelmail
./configure

6. Install the sasql plugin:

a. Select Plugins (#8) from the main configuration menu.
b. Look for and select the sasql plugin (#17).
c. Verify that sasql is listed in the Installed Plugins list.
d. Press S and Enter to save.
e. Press Q and Enter to quit.

7. Test! Browse to http://full.dns.of.toaster/squirrelmail/src/configtest.php and verify that there are no errors.

8. To test if this works, follow the following steps:

a. In qmailadmin, check the user's "Spam Detection?" box.
b. Login to Squirrelmail as the user - this will create the necessary SPAM folders.
c. Logout of Squirrelmail and back in again to verify that the "Learn Ham", "Learn Spam" and "Spam" folders exist.
d. While in Squirrelmail, click on Options and then Spam Filters to be able to modify the user's anti-spam settings.

Install WebUserPrefs

Note: Is this even necessary any more once the Squirrelmail SASQL plugin is installed?

The official project page can be found here. Note that Webuserprefs is version 0.6 and hasn't been updated since at least November 2005.

I did it as follows:

cd /usr/local/www/mail
fetch http://...
tar -xzf webuserprefs-0.5.tar.gz
mv webuserprefs-0.5 webuserprefs
cd webuserprefs
vi config.php

Edit the prefs_source to "db", authorization to "squirrelmail" and set the database info. Point your browser at http://mail.example.com/webuserprefs/ and volia. The catch is that you must be logged in via squirrelmail in order to use it. The alternate solution is to use IMAP or POP3 but then you have to recompile PHP with IMAP support.

Install Pear-DB

Note: Current Mail::Toasters (5.x) seem to have Pear/Pear-DB support properly configured on a default install.

You'll find it in /usr/ports/databases/pear-DB.

This port depends on lang/php4 which should already be installed as part of the Mail::Toaster Apache install. You might have to edit /usr/local/etc/php.ini and set:

include_path = ".:/usr/local/share/pear"

Modify spamd flags.

IMPORTANT: Do not skip this section or spamassassin won't use the database for your preferences.

1. Ensure that toaster-watcher.conf has the following settings:

install_spamassassin               = 1
install_spamassassin_flags         = -v -q -x   # Add -q for per user SQL prefs
filtering_spamassassin_method      = user       # site | user | domain

2. Verify that /etc/rc.conf has the following lines:

spamd_enable="YES"
spamd_flags="-v -q -x"

3. Restart spamd.

How do I alter what prefs SpamAssassin uses?

You can control the order of preferences by re-writing the SQL query that SpamAssassin uses. You can do this by setting the user_scores_sql_custom_query value to a custom query. You can use the following variables in the SQL query:

_USERNAME_
_MAILBOX_
_DOMAIN_

Here are a few example SQL queries:

default query

SELECT preference, value FROM _TABLE_ WHERE username = _USERNAME_ OR username = '@GLOBAL' ORDER BY username ASC

global, then domain level

SELECT preference, value FROM _TABLE_ WHERE username = _USERNAME_ OR username = '@GLOBAL' OR username = '@~'||_DOMAIN_ ORDER BY username ASC

global overrides user prefs

SELECT preference, value FROM _TABLE_ WHERE username = _USERNAME_ OR username = '@GLOBAL' ORDER BY username DESC

from the SA SQL README

user_scores_sql_custom_query SELECT preference, value FROM _TABLE_ WHERE username = _USERNAME_ OR username = '$GLOBAL' OR username = CONCAT('%',_DOMAIN_) ORDER BY username ASC

External Links

Personal tools
Mongers