SpamAssassin performance home : internet : mail : toaster : filtering : content filtering : SpamAssassin : per-user preferences SpamAssassin testing

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

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)

Install it as you would any other squirrelmail plugin. Edit sasql_conf.php and set the DSN. Make sure to update the table name to be "userpref" as the SpamAssassin docs and SA sql scripts expect.

Install WebUserPrefs

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

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's flags.

The best way is to modify /etc/rc.conf and add -q to spamd_flags such as in the following lines:

  • spamd_enable="YES"
  • spamd_flags="-d -v -q -x -r /var/run/spamd.pid"

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

Last modified on 5/17/05.