here is a patch against amavisd-new 2.3.3. It adds :
- a login map to get the username to pass to dspam. It works only for sql
lookups, the field you have to add is 'login'
- disable dspam auto-learn
- remove hardcoded dspam options from source, since dspam can have now its own
config file
P.S: i'm not a perl guru, the hack is maybe dirty :) but it works fine for
me ...
Le Samedi 8 Octobre 2005 19:43, Jakob Curdes a écrit :
> Can anybody comment on the status of dspam integration in SA ? Everybody
> (including Marc) mentions this would be the best approach to use dspam
> in an amavis-centric environment, but I could not find any info on
> integration. Is it really true that nobody has yet done something in
> this direction ?
> (Maybe I will if nobody else has).
>
> Yours,
> Jakob Curdes
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Power Architecture Resource Center: Free content, downloads, discussions,
> and more. http://solutions.newsforge.com/ibmarch.tmpl
> _______________________________________________
> AMaViS-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/amavis-user
> AMaViS-FAQ:http://www.amavis.org/amavis-faq.php3
> AMaViS-HowTos:http://www.amavis.org/howto/
--
___________________________________________
Osmium Work - Ingénierie Open Source
Tél : +212 (0) 22 82 11 05
Fax : +212 (0) 22 82 07 21
--- amavisd.org 2005-10-08 20:37:49.842925241 +0000
+++ amavisd 2005-10-08 20:39:23.945943440 +0000
@@ -236,7 +236,7 @@
@message_size_limit_maps
@addr_extension_virus_maps @addr_extension_spam_maps
@addr_extension_banned_maps @addr_extension_bad_header_maps
- @debug_sender_maps
+ @debug_sender_maps @login_maps
)],
'confvars' => [qw(
$myproduct_name $myversion_id $myversion_id_numeric $myversion_date
@@ -6728,6 +6728,7 @@
unshift(@Amavis::Conf::banned_admin_maps, $nf->('banned_admin', 'S-'));
unshift(@Amavis::Conf::bad_header_admin_maps, $nf->('bad_header_admin', 'S-'));
unshift(@Amavis::Conf::spam_admin_maps, $nf->('spam_admin', 'S-'));
+ unshift(@Amavis::Conf::login_maps , $nf->('login', 'S'));
unshift(@Amavis::Conf::banned_filename_maps, $nf->('banned_rulenames', 'S-'));
section_time('sql-prepare');
}
@@ -13032,6 +13033,26 @@
if (!defined($dspam) || $dspam eq '') {
do_log(5,"spam_scan: DSPAM not available, skipping it");
} else {
+ my %users = ();
+ for my $recip (@{$msginfo->recips}) {
+ my($r,$mk) = lookup(0,$recip, @{ca('login_maps')});
+ $users{$r} = undef if defined $r;
+ }
+ my @users_list = keys(%users);
+ my($dspam_mode,@dspam_users,$all_local);
+ if (@users_list == 0){
+ $dspam_mode = '--mode=notrain';
+ $dspam_users[0] = $daemon_user;
+ $all_local = 0;
+ } elsif (@users_list == 1) {
+ $dspam_mode = '';
+ @dspam_users = @users_list;
+ $all_local = 1;
+ } else {
+ $dspam_mode = '--classify';
+ @dspam_users = @users_list;
+ $all_local = 1;
+ }
# pass the mail to DSPAM, extract its result headers and feed them to SA
$dspam_fname = $msginfo->mail_tempdir . '/dspam.msg';
my($dspam_fh) = IO::File->new; # will receive output from DSPAM
@@ -13040,29 +13061,51 @@
$fh->seek(0,0) or die "Can't rewind mail file: $!";
my($proc_fh,$pid) = run_command('&'.fileno($fh), "&1", $dspam,
qw(--stdout --deliver=spam,innocent
- --mode=tum --feature=chained,noise
- --enable-signature-headers
- --user), $daemon_user,
- ); # --mode=teft
- # qw(--stdout --deliver-spam) # dspam < 3.0
+ --user), @dspam_users, $dspam_mode);
# keep X-DSPAM-*, ignore other changes e.g. Content-Transfer-Encoding
- my($all_local) = !grep { !lookup(0,$_,@{ca('local_domains_maps')}) }
- @{$msginfo->recips};
+ #my($all_local) = !grep { !lookup(0,$_,@{ca('local_domains_maps')}) }
+ # @{$msginfo->recips};
my($first_line); my($ln);
# scan mail header from DSPAM
- for (undef $!; defined($ln=$proc_fh->getline); undef $!) {
- $dspam_fh->print($ln) or die "Can't write to $dspam_fname: $!";
- if (!defined($first_line))
- { $first_line = $ln; do_log(5,"spam_scan: from DSPAM: $first_line") }
- last if $ln eq $eol;
- local($1,$2);
- if ($ln =~ /^(X-DSPAM[^:]*):[ \t]*(.*)$/) { # does not handle folding
- my($hh,$hb) = ($1,$2);
- $dspam_signature = $hb if $ln =~ /^X-DSPAM-Signature:/i;
- $dspam_result = $hb if $ln =~ /^X-DSPAM-Result:/i;
- do_log(3,$ln); push(@lines,$ln); # store header in array passed to SA
- # add DSPAM header fields to passed mail for all recipients
- $hdr_edits->append_header($hh,$hb) if $all_local;
+ if (@users_list > 1){
+ my($best_confidence) = -99;
+ my(@result); my(@tmp);
+ for (undef $!; defined($ln=$proc_fh->getline); undef $!) {
+ $dspam_fh->print($ln) or die "Can't write to $dspam_fname: $!";
+ if (!defined($first_line))
+ { $first_line = $ln; do_log(5,"spam_scan: from DSPAM: $first_line") }
+ local($1,$2);
+ if ($ln =~ /^(X-DSPAM[^:]*):[ \t]*(.*)$/) { # does not handle folding
+ my($hh,$hb) = ($1,$2);
+ do_log(5,"spam_scan: $hh: $hb");
+ @result = split(/; /,$hb);
+ @tmp = split(/=/,$result[3]);
+ if ($tmp[1]>$best_confidence){
+ $best_confidence = $tmp[1];
+ @tmp = split(/"/,$result[1]);
+ $dspam_result = $tmp[1];
+ }
+ }
+ }
+ push(@lines,"X-DSPAM-Result: $dspam_result"); # store header in array passed to SA
+ $hdr_edits->append_header('X-DSPAM-Result',$dspam_result);
+ $hdr_edits->append_header('X-DSPAM-Confidence',$best_confidence);
+ } else {
+ for (undef $!; defined($ln=$proc_fh->getline); undef $!) {
+ $dspam_fh->print($ln) or die "Can't write to $dspam_fname: $!";
+ if (!defined($first_line))
+ { $first_line = $ln; do_log(5,"spam_scan: from DSPAM: $first_line") }
+ last if $ln eq $eol;
+ local($1,$2);
+ if ($ln =~ /^(X-DSPAM[^:]*):[ \t]*(.*)$/) { # does not handle folding
+ my($hh,$hb) = ($1,$2);
+ $dspam_signature = $hb if $ln =~ /^X-DSPAM-Signature:/i;
+ $dspam_result = $hb if $ln =~ /^X-DSPAM-Result:/i;
+ do_log(3,$ln); push(@lines,$ln); # store header in array passed to SA
+ # add DSPAM header fields to passed mail
+ $hdr_edits->append_header($hh,$hb);
+ }
+
}
}
defined $ln || $!==0 || $!==EAGAIN
@@ -13163,29 +13206,29 @@
$sa_tests =~ s/,\s*/,/g; $spam_status = "tests=[" . $sa_tests . "]";
add_entropy($spam_level,$sa_tests);
- if (defined $dspam && $dspam ne '' && defined $spam_level) { # auto-learn
- my($eat,@options);
- @options = (qw(--stdout --mode=tum --user), $daemon_user); # --mode=teft
- if ( $spam_level > 7.0 && $dspam_result eq 'Innocent') {
- $eat = 'SPAM'; push(@options, qw(--class=spam --source=error));
- }
- elsif ($spam_level < 0.5 && $dspam_result eq 'Spam') {
- $eat = 'HAM'; push(@options, qw(--class=innocent --source=error));
- }
- if (defined $eat && $dspam_signature ne '') {
- do_log(2,"DSPAM learn $eat ($spam_level), $dspam_signature");
- my($proc_fh,$pid) = run_command($dspam_fname, "&1", $dspam, @options);
- # consume remaining output to avoid broken pipe
- my($nbytes,$buff);
- while (($nbytes=$proc_fh->read($buff,4096)) > 0) { }
- defined $nbytes or die "Error reading from DSPAM process: $!";
- my($err); $proc_fh->close or $err = $!; my($retval) = $?;
+# if (defined $dspam && $dspam ne '' && defined $spam_level) { # auto-learn
+# my($eat,@options);
+# @options = (qw(--stdout --mode=tum --user), $daemon_user); # --mode=teft
+# if ( $spam_level > 7.0 && $dspam_result eq 'Innocent') {
+# $eat = 'SPAM'; push(@options, qw(--class=spam --source=error));
+# }
+# elsif ($spam_level < 0.5 && $dspam_result eq 'Spam') {
+# $eat = 'HAM'; push(@options, qw(--class=innocent --source=error));
+# }
+# if (defined $eat && $dspam_signature ne '') {
+# do_log(2,"DSPAM learn $eat ($spam_level), $dspam_signature");
+# my($proc_fh,$pid) = run_command($dspam_fname, "&1", $dspam, @options);
+# # consume remaining output to avoid broken pipe
+# my($nbytes,$buff);
+# while (($nbytes=$proc_fh->read($buff,4096)) > 0) { }
+# defined $nbytes or die "Error reading from DSPAM process: $!";
+# my($err); $proc_fh->close or $err = $!; my($retval) = $?;
# do_log(-1,"DSPAM learn $eat response:".$output) if $output ne '';
- $retval==0 && $err==0
- or die ("DSPAM learn $eat FAILED: ".exit_status_str($retval,$err));
- section_time('DSPAM learn');
- }
- }
+# $retval==0 && $err==0
+# or die ("DSPAM learn $eat FAILED: ".exit_status_str($retval,$err));
+# section_time('DSPAM learn');
+# }
+# }
}
if (defined $dspam_fname) {
if (($spam_level > 5.0 ? 1 : 0) != ($dspam_result eq 'Spam' ? 1 : 0))