Download and Build

Download and extract the package, and move into the directory. To configure I'd used something like:

$ ./configure                      \
    --prefix=$HOME/lib/dspam-pg    \
    --enable-daemon                \
    --enable-debug                 \
    --enable-preferences-extension \
    --with-storage-driver=pgsql_drv

Build and install it, with the following standard recipe:

$ make && make install

Configuration

The next stage is to configure DSPAM. You're going to have to edit $HOME/lib/dspam-pg/etc/dspam.conf if you've put it where I did.

You're going to need to check/change the following settings:

StorageDriver /home/sam/lib/dspam-pg/lib/libpgsql_drv.so
# TrustedDeliveryAgent "/usr/bin/procmail"
# UntrustedDeliveryAgent "/usr/bin/procmail -d %u"

Because we're going to be using DSPAM as a procmail filter I'd remove the TrustedDeliveryAgent and UntrustedDeliveryAgent settings so mail can't escape.

Trust sam  

You want to allow yourself to run the stats/other tools programs to see how DSPAM is doing. So change this to make DSPAM trust you.

PgSQLServer             127.0.0.1
PgSQLPort               5432
PgSQLUser               dspam
PgSQLDb                 dspam
PgSQLConnectionCache    3
#PgSQLPass               changeme

Set Postgres up how you want it. Because I'm running it on the same machine and have a firewall, I trust everything to work without a password. Probably not very good, but it's my box at home and I trust it.

ServerQueueSize 32
ServerPID               "/home/sam/lib/dspam-pg/var/run/dspam.pid"
ServerDomainSocketPath  "/home/sam/lib/dspam-pg/tmp/dspam.sock"
ClientHost              "/home/sam/lib/dspam-pg/tmp/dspam.sock"

ServerPass.localhost    "dspam"
ClientIdent             "dspam@localhost"

Set the daemonised DSPAM's client and server options. I think that's about all I changed in my configuration file, but I'll try and remember to put the things I missed in here.

The next stage is to configure Postgres. This consists of Creating the DB, registering the "plpgsql" language, creating the tables, adding the dspam user and allowing it to access the right tables:

$ createdb dspam
$ createlang plpgsql dspam
$ psql dspam < src/tools.pgsql_drv/pgsql_objects.sql
$ createuser --no-adduser --no-createdb dspam
$ psql dspam <<EOF
GRANT SELECT,INSERT,UPDATE,DELETE ON
  dspam_preferences,
  dspam_signature_data,
  dspam_stats,
  dspam_token_data
TO dspam;
EOF

Training

That should be about it for the configuration. The next thing to to is to get the daemon running, I like it in running in "GNU Screen" that way I can see if everything is OK, but running it in the background is popular as well.

$ dspam --debug --daemon

Train with any spam messages

$ formail -s dspam --client --user sam --class=spam \
    --source=corpus --mode=teft < SPAM_MBOX

Train with any ham messages

$ formail -s dspam --client --user sam --class=innocent \
    --source=corpus --mode=teft < HAM_MBOX

Note: corpus training is a bit more convenient if you use the dspam_corpus command.

$ dspam_corpus sam HAM_MBOX
$ dspam_corpus --addspam sam SPAM_MBOX

This displays a progress bar and message throughput. -FrankLuithle


The "formail" program in the above comes with postfix and allows you an mbox file containing several emails into it and it breaks the emails up and passes them one at a time to the dspam program. One the training has finished I would recommend testing DSPAM to make sure everything is OK:

$ dspam --user sam --classify < MAIL

Once you're sure everything is OK you can integrate it with the rest of system.

Procmail Integration

I'm using procmail to filter my mail into nice directories, to bring DSPAM into the mix you need to put something like this near the top of the file:

# Begin spam treatment.
:0fw
| $HOME/lib/dspam-pg/bin/dspam --client --user sam --deliver=stdout

:0:
* ^X-DSPAM-Result: spam
spam
# End spam treatment.

The first rule pipes the mail through DSPAM, this causes several new headers to be added to the mail which we then look at in the next rule. The second rule looks at the extra headers and if DSPAM thought it was a spam message weasles the message off into the spam folder.

That's about it I think. If DSPAM gets something wrong, you would pipe the mail to:

  formail -s ~/lib/dspam-pg/bin/dspam --user sam --source=error \
    --class=spam --mode=teft

The "formail" is there again so you can work with several mail messages at a time (i.e. in mutt you can tag the errors with 't', then pipe them all with ';|' to the program above). The line above takes a message reclassifies it as a spam. If you want to go the other way and classify it as an innocent message you want something like:

  formail -s ~/lib/dspam-pg/bin/dspam --user sam --source=error \
    --class=innocent --mode=teft

Originally written by: SamMason

last edited 2007-06-13 14:56:22 by Lars Tobias Børsting