Howto Spamassassin User preference with Qmail

By Matthew Francis for In-Tuition Networks Ltd July 2003
Adapted by Sylvestre Ledru [I did not test this installation, so, don't ask me anything about that.]


This howto assumes you're using qmail-1.03 (setup as per LWQ http://www.lifewithqmail.org/lwq.html), vpopmail, SpamAssassin 2.54 (via spamd) and qmail-scanner 1.16 is currently being called from your /etc/tcp.smtp or vpopmail equivalent.

Updating Qmail-Scanner
----------------------

For SA to work with per user preferences AND to have a default policy for domains which don't need user preferences you need to run two copies of spamd. You also need to download the patch below to tell qmail-scanner to only run the default SA with certain domains. If you want to have per user SA prefs ONLY then just configure your spamd as in the 'Creating the second spamd' section below and make sure spamd isn't setup inside qmail-scanner.

Download:
http://no-way.org/uploads/6/22/qmail-scanner-1.16-domainscan.diff to your qmail-scanner source directory. And then type:

cp qmail-scanner-queue.template orig.qmail-scanner-queue.template
patch -p1 < qmail-scanner-1.16-domainscan.diff

This will patch your qmailscanner source to enable you to select AV/Spamscanners on a per domain basis :-)

Run ./configure with your options (ensure spamd is running at this point so that qmail-scanner will detect it). Assuming that goes ok, run it again with --install on the end.

Create /var/spool/qmailscan/virusscan containing

{domain):clamscan_scanner:perlscan_scanner
.:clamscan_scanner:perlscan_scanner:spamassassin

Swap the scanners listed with the ones you have installed. The {domain} should be replace with the domain name required for per user SA preferences (note the lack of spamassassin in the scanners) but without the TLD, eg. for example.com

example:clamscan_scanner:perlscan_scanner
.:clamscan_scanner:perlscan_scanner:spamassassin

Run the following to update your qmail-scan db files:

su qmailq
cd /var/qmail/bin
./qmail-scanner-queue.pl -g


NB. The patch applied above also allows you to filter attachments on a per domain basis vis perlscan_scanner - for example some domains may want .exe file blocked whilst others don't. See http://no-way.org/uploads/6/22/qmail-scanner-1.16-domainscan.diff for details.

Creating the second spamd
-------------------------

This assumes you are already running spamd via daemontools.

Create a second directory for spamd to run from (I've called this vspamd). In this directory create the run file containing:

#!/bin/sh
exec /usr/bin/spamd -c -p 784 -v


This will run a second copy of spamd running on port 784 - by default this will only be accessible from the local machine.

Run this second spamd by:

ln -s ~vspamd /service/vspamd

Verify two spamd's are running:

ps -ax | grep spamd

Ok now all we need to do is tell qmail to run spamc with this second copy of spamd.


Configuring Vpopmail Users
--------------------------

Create .qmail-default in ~vpopmail/domains/{domain}/ containing:

|spamc -p 784 -u "$DEFAULT"@"$HOST" |vdelivermail '' bounce-no-mailbox
Create .qmail-{user} in ~vpopmail/domains/{domain}/{user} containing:
|spamc -p 784 -u "$EXT"@"$HOST" |vdelivermail '' bounce-no-mailbox
and spamd will look up the preferences in the appropriate vpopmail users directory:

~vpopmail/domains/{domain}/{user}/.spamassassin/
Create a user_prefs file in this directory containing the preferences you want set for this user eg:

# How many hits before a mail is considered spam.
required_hits 10

To test, just send this user an email and check the headers for the required number of hits. Assuming this users is set differently to the system default, you know the per user preferences are working :-)

NB. If you're running spamd as a user other than root ensure that the permissions are set so that these files can be read by that user.

BTW the most recent version of spamc defaults the -f option which is why it isn't specified above. See 'man spamc' for details.
From :fabri (puccibox_at_libero.it) posted on 23/11/2003 04:03
Comment :
is it posible to manage user pref via webuserprefs interface?
 
From :Joe Boyce (joe_at_joeboyce.com) posted on 04/12/2003 02:41
Comment :
You can have your users manage this via a web based system, yes. Here's how I do it.

Have SpamAssassin installed to support user preferences via a MySQL database. See http://eu.spamassassin.org/full/2.6x/dist/sql/README
for more information on that.

Download and install http://webuserprefs.pipegrep.net/index.php

For our ISP, our users can go to that page, login which authenticates off of POP3, then manage their own settings.

Works well.
 
From :Russ L (khsweb_at_idaho.tds.net) posted on 05/12/2003 06:56
Comment :
More of a question than a comment, but I have implimented this step by step and it doesn't seem to work. According to the log file, it scans it with the correct prefs file but doesn't tag the file header or subject line. Any ideas?
 
From : () posted on 29/12/2003 18:03
Comment :
 
From :Tom (tom at bitpull.org) posted on 31/12/2003 16:16
Comment :
Russ, you're right. This setup doesnt work. :-(
First you have to use preline to exec code in a .qmail-file. man dot-qmail(!)
Second is that the output of spamc isn't piped correct for further use in vmaildeliver.

Anyway, before breaking your head to solve this issues, use one of these setups to reach your goal:
http://www.dougledbetter.org/tech/spamassassin.html

http://www.beret.net/docs/vpopmail_procmail.php
 
From :Matt () posted on 22/01/2004 13:10
Comment :
Unfortunately this setup only works with the exact versions of the software that I stated at the top of the howto.

Hopefully Sylvestre will update his patch to work with the latest version of qmail-scanner??
 
From :Rick Updegrove (rickupusa hotmail com at at at) posted on 10/05/2005 21:07
Comment :
This setup *does* work without the need for the overhead and complication of procmail. However, I use the full paths and as ton at pitbull mentiond you need the following syntax changes:

.qmail-default

| /var/qmail/bin/preline /usr/local/bin/spamc -u "$DEFAULT"@"$HOST" | /usr/local/vpopmail/bin/vdelivermail ''
bounce-no-mailbox

.qmail-user

| /var/qmail/bin/preline /usr/local/bin/spamc -u "$EXT"@"$HOST" | /usr/local/vpopmail/bin/vdelivermail '' bounce-no-mailbox

 
From :gollum123 (gollum123[at]free.fr) posted on 11/06/2005 19:04
Comment :
.qmail-user doesn't exist by itself. "user" must be changed by the user account.
mathieu.chateau example:
.qmail-mathieu:chateau

.qmail-default works for everyone (no need for qmail-user )

 
From :Blow Job (BlowJob_at_gmail.com) posted on 19/04/2007 19:14
Comment :
This is really fresh idea of the design of the site! I seldom met such in Internet. I will visit your website again. Good Work dude!
 

Comment closed because of the spam