User Tools

Site Tools


Academic Projects

Wireless Network

Linux Stuff


DSPAM individual bases only for users who retrain DSPAM

This page describes a solution that aims to provide individual bases only for users who are giving feedback to dspam, avoiding waste of storage and processing.

This solutions uses

  • DSPAM (tested with version 3.6.8)
  • MySQL (tested with version 5.0)
    • with an extra table to keep names of users who retrained dspam and have individual bases
  • Postfix (tested with version 2.1.5)
  • courier maildrop (tested with version 1.7.0 from debian sarge)
    • with patches to make queries in mysql and find out if the user has individual base
  • retrain script
    • that inserts first time retrainer in mysql

Courier Maildrop Patch

  • Patch written by Francisco Faleiro Fialho
    • for courier-maildrop package source from debian sarge
    • version: courier-maildrop_0.47-4sarge5_i386

DSPAM Retrain Script

  • this script may be called by postfix when receives an email spam@yourdomain our notspam@yourdomain
    • reads email from stdin and parses username, subject and dspam signature
  • the argument when running this script should be “spam” or “innocent”
    • on postfix this can be configured on
# Script modified by Guilherme Pezzi (04/12/2006)
# Inserts user in MySQL table when first retrains: to activate individual base
# After the first retrain: normal retraining
# logs are kept on /var/dspam/retrain.log

use DBI();

$database = "dspam";
$host = "xxxxxxxxxxxxx";
$usuario = "user";
$senha = "passwrd";

my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host","$usuario", "$senha",{'RaiseError' => 1});

# Get arguments
$class  = $ARGV[0] || die; shift;

open FILE, ">>/var/dspam/retrain.log" or die "unable to open $file $!";
print FILE "===================================================\n$date ";

# Pull out DSPAM signatures and send them to the dspam program
while (<>) {
    if ((! $subj) && (/^Subject: /)) {
        $subj = $_;
    } elsif ((! $sign) && (/(X-DSPAM-Signature: [a-f0-9]+)/)) {
        $sign = $_;
    } elsif ((! $user) && (/(Delivered-To: (\w+)@)/) ) {
        $user = $2;
        $mail = $1;
        $sth = $dbh->prepare("SELECT uid FROM dspam_retrained where uid='$user'");
        if ($numrows==0){
                $myquery =  "INSERT INTO dspam_retrained (uid) VALUES('$user')";

                print FILE "   INSERTED RETRAIN USER !!!!!! \n\n\n   $subj\n   $sign\n   $mail\n   $user\n";
   if ( $subj &&  $user && $sign && $numrows>0 ){
           open(F, "|/usr/local/bin/dspam --source=error --class=$class --user $user --debug");
           print F "$subj\n$sign\n$mail\n";
           print FILE "   RETRAIN OK \n\n\n   $subj\n   $sign\n   $mail\n   $user\n";
print FILE "   RETRAIN ERROR !!!!!! \n\n\n   $subj\n   $sign\n   $mail\n   $user\n";

Downloading, patching and compiling maildrop

  • Downloading debian package source (from debian sarge)
apt-get source courier
  • Patching maildrop source
patch -p0 < patch_dspam_integration
  • compiling and creating debian package
dpkg-buildpackage -uc -b
  • after you can install with “dpkg -i”
    • to check which version it's running
$ maildrop -v
maildrop 1.7.0 Copyright 1998-2003 Double Precision, Inc.
DSPAM Integration enabled.
This program is distributed under the terms of the GNU General Public
License. See COPYING for additional information.
  • you mail also compile manually, just add –enable-dspam to your configure parameters
./configure --enable-dspam

Creating MySQL table to keep users who already retrained DSPAM

  • you may want to change user field size and the table type
use dspam;
create table dspam_retrained (
  user char(8) not null
) type=InnoDB;

Configuring maildrop with dspam

  • /etc/maildropdspam.config
port            3306
database        dspam
dbuser          dspam
dbpw            xxxxxx
dbtable         dspam_retrained
uid_field       uid
timeout         3
  • /etc/maildroprc
if ( $DSPAM_RETRAINED == 1 )
    xfilter "dspam --mode=toe --deliver=innocent,spam --feature=chained,noise --stdout --user $LOGNAME"
    xfilter "dspam --mode=notrain --deliver=innocent,spam --feature=chained,noise --stdout --user global"

Guilherme Peretti Pezzi 07/12/2006 20:12

linux/dspam.txt · Last modified: 2007/08/13 09:56 by pagode