qw(@gDefaultArchitectures),
qw($gTemplateDir),
qw($gDefaultPackage),
+ qw($gSpamMaxThreads $gSpamSpamsPerThread $gSpamKeepRunning $gSpamScan $gSpamCrossassassinDb)
],
text => [qw($gBadEmailPrefix $gHTMLTail $gHTMLExpireNote),
],
set_default(\%config,'spam_scan',0);
+=item spam_crossassassin_db
+
+Location of the crosassassin database, defaults to
+spool_dir/../CrossAssassinDb
+
+=cut
+
+set_default(\%config,'spam_crossassassin_db',$config{spool_dir}.'/../CrossAssassinDb');
+
+=item spam_max_cross
+
+Maximum number of cross-posted messages
+
+=cut
+
+set_default(\%config,'spam_max_cross',6);
+
+
+=item spam_spams_per_thread
+
+Number of spams for each thread (on average). Defaults to 200
+
+=cut
+
+set_default(\%config,'spam_spams_per_thread',200);
+
+=item spam_max_threads
+
+Maximum number of threads to start. Defaults to 20
+
+=cut
+
+set_default(\%config,'spam_max_threads',20);
+
+=item spam_keep_running
+
+Maximum number of seconds to run without restarting. Defaults to 3600.
+
+=cut
+
+set_default(\%config,'spam_keep_running',3600);
+
+=item spam_mailbox
+
+Location to store spam messages; is run through strftime to allow for
+%d,%m,%Y, et al. Defaults to 'spool_dir/../mail/spam/assassinated.%Y-%m-%d'
+
+=cut
+
+set_default(\%config,'spam_mailbox',$config{spool_dir}.'/../mail/spam/assassinated.%Y-%m-%d');
+
+=item spam_crossassassin_mailbox
+
+Location to store crossassassinated messages; is run through strftime
+to allow for %d,%m,%Y, et al. Defaults to
+'spool_dir/../mail/spam/crossassassinated.%Y-%m-%d'
+
+=cut
+
+set_default(\%config,'spam_crossassassin_mailbox',$config{spool_dir}.'/../mail/spam/crossassassinated.%Y-%m-%d');
+
+=item spam_local_tests_only
+
+Whether only local tests are run, defaults to 0
+
+=cut
+
+set_default(\%config,'spam_local_tests_only',0);
+
+=item spam_user_prefs
+
+User preferences for spamassassin, defaults to $ENV{HOME}/.spamassassin/user_prefs
+
+=cut
+
+set_default(\%config,'spam_user_prefs',"$ENV{HOME}/.spamassassin/user_prefs");
+
+=item spam_rules_dir
+
+Site rules directory for spamassassin, defaults to
+'/usr/share/spamassassin'
+
+=cut
+
+set_default(\%config,'spam_rules_dir','/usr/share/spamassassin');
+
=back
# unfortunatly we can't use strict;
-use lib qw(/usr/lib/debbugs);
+use warnings;
+use strict;
use Mail::CrossAssassin;
use Mail::SpamAssassin;
-my $config_path = '/etc/debbugs';
-require "$config_path/config";
+use Debbugs::Config qw(:config);
# New versions of debbugs will not allow use in /etc/debbugs/config
use POSIX qw(strftime);
-$gSpamMailbox = strftime($gSpamMailbox,gmtime);
-$gCrossMailbox = strftime($gCrossMailbox,gmtime);
+my $spam_mailbox = strftime($config{spam_mailbox},gmtime);
+my $cross_mailbox = strftime($config{spam_crossassassin_mailbox},gmtime);
umask 002;
$| = 1;
return '';
}
-my $user_prefs = "$ENV{HOME}/.spamassassin/user_prefs";
-
my $spam = Mail::SpamAssassin->new({
dont_copy_prefs => 1,
- site_rules_filename => $gSpamRulesDir,
- userprefs_filename => $user_prefs,
- local_tests_only => ($gSpamLocalTestsOnly || 0),
+ site_rules_filename => $config{spam_rules_dir},
+ userprefs_filename => $config{spam_user_prefs},
+ local_tests_only => ($config{spam_local_tests_only} || 0),
debug => ($ENV{DEBBUGS_SPAM_DEBUG} || 0),
});
$spam->compile_now(1); # use all user preferences
while (my $id = <STDIN>) {
chomp $id;
- my $nf = <STDIN> or die "Could not read nf: $!";
+ my $nf = <STDIN>;
+ if (not defined $nf) {
+ die "Could not read nf: $!";
+ }
chomp $nf;
unless (rename "incoming/S$id", "incoming/R$id") {
die "Could not rename incoming/S$id: $!";
my $keys = ca_keys($mail->get_body);
print "$keys\n$messageid\n"
or die "Could not send keys: $!";
- my $ca_score = <STDIN> or die "Could not read ca_score: $!";
+ my $ca_score = <STDIN>;
+ die "Could not read ca_score: $!" if not defined $ca_score;
chomp $ca_score;
my $todo = 0;
my ($headers, $body);
- my $seen = <STDIN> or die "Child could not read seen: $!";
+ my $seen = <STDIN>;
+ die "Child could not read seen: $!" if not defined $seen;
chomp $seen;
my $status;
my $nseen = $seen;
$ca_score;
$out .= " spam $score\n";
$nseen = $score;
- } elsif ($status->get_score() > 0 && $ca_score >= $gMaxCross) {
+ } elsif ($status->get_score() > 0 && $ca_score >= $config{spam_max_cross}) {
$todo = 2;
my $score = sprintf "%.1f/%.1f %d",
$status->get_score(), $status->get_required_score(), $ca_score;
open OUT, "> incoming/I$id" or die "open incoming/I$id: $!";
my ($received, $from, $other_headers) =
split(/\n/, $headers, 3);
- if ($recevied =~ /^From /) {
+ if ($received =~ /^From /) {
($received, $from) = ($from, $received);
}
print OUT "$received\n$from\n$other_headers"
print "$todo\n";
<STDIN>;
if ($todo) {
- open OUT, '>>', ($todo == 1) ? $gSpamMailbox : $gCrossMailbox
+ open OUT, '>>', ($todo == 1) ? $spam_mailbox : $cross_mailbox
or die "Could not open assassinated: $!";
print OUT $headers or die "print assassinated: $!";
if ($ca_score > 1) {
# Creates: incoming/I.nn
# Stop: spamscan-stop
-# unfortunatly we can't use strict;
-use lib qw(/usr/lib/debbugs);
+use warnings;
+use strict;
+
use threads;
use threads::shared;
-my $config_path = '/etc/debbugs';
-my $lib_path = '/usr/lib/debbugs';
-#use lib $lib_path;
-#use lib "/usr/lib/debbugs";
+use Debbugs::Config qw(:config);
+
+use Debbugs::Common qw(:lock);
+
use Mail::CrossAssassin;
use Socket;
use IO::Handle;
use IPC::Open2;
-require "$config_path/config";
-require "$lib_path/errorlib";
-$ENV{PATH} = $lib_path . ':' . $ENV{PATH};
-exit unless $gSpamScan;
+exit unless $config{spam_scan};
-chdir $gSpoolDir or die "chdir spool: $!\n";
+chdir $config{spool_dir} or die "chdir spool: $!\n";
umask 002;
eval {
- &filelock('incoming-spamscan');
+ filelock('incoming-spamscan');
};
exit if $@;
my $crossassassinated_lock : shared;
my $threadsrunning : shared = 0;
+# flush output immediately
$| = 1;
sub lprint ($) {
# This thread handles the updating and querying of the crossassassin db
sub cross {
- ca_init('\b\d{3,8}(?:-(?:close|done|forwarded|maintonly|submitter|quiet|subscribe))?\@bugs\.debian\.org', '/org/bugs.debian.org/CrossAssassinDb');
+ ca_init('\b\d{3,8}(?:-(?:close|done|forwarded|maintonly|submitter|quiet|subscribe))?\@'.$config{email_domain}, $config{spam_crossassassin_db});
my $mytid = threads->self->tid();
crosscheck:
while ($spamscan_stop <= 1) {
print $sain "$id\n$nf\n";
lprint "{$mytid} $id is $nf\n";
my $keys;
- unless ($keys = <$saout>) {
+ unless (defined($keys = <$saout>)) {
lprint "{$mytid} Could not get keys: $!\n";
last pp;
}
chomp $keys;
my $messageid;
- unless ($messageid = <$saout>) {
+ unless (defined($messageid = <$saout>)) {
lprint "{$mytid} Could not read messageid: $!\n";
last pp;
}
last pp;
}
my $todo;
- unless ($todo = <$saout>) {
+ unless (defined($todo = <$saout>)) {
lprint "{$mytid} Could not read todo: $!\n";
last pp;
}
}
unless($nseen) {
lprint "{$mytid} Could not read seen: $!\n";
- start_sa if (scalar(@ids) > ($threadsrunning * $gSpamsPerThread)
- && $threadsrunning < $gMaxThreads);
+ start_sa() if (scalar(@ids) > ($threadsrunning * $config{spam_spams_per_thread})
+ && $threadsrunning < $config{spam_max_threads});
last pp;
}
chomp $nseen;
$spamseen{$messageid} = $nseen if ($nseen);
my $out;
- unless($out = <$saout>) {
+ unless(defined($out = <$saout>)) {
lprint "{$mytid} Could not read out: $!\n";
last pp;
}
}
my @sa_threads;
-sub start_sa() {
+sub start_sa {
my $s = threads->create(\&sa)
or die "Could not start sa threads: $!";
$s->detach;
push @sa_threads, $s;
}
-$gKeepRunning = 3600 unless $gKeepRunning > 0;
-$gSpamsPerThread = 200 unless defined($gSpamsPerThread);
-$gMaxThreads = 20 unless defined($gMaxThreads);
-
my $cross_thread = threads->create(\&cross)
or die "Could not start cross thread: $!";
$cross_thread->detach;
start_sa;
# start_sa;
-my $stopafter = time() + $gKeepRunning;
+my $stopafter = time() + $config{spam_keep_running};
for (;;) {
alarm 180;
push @ids, @i;
cond_broadcast @ids;
}
- start_sa if (scalar(@ids) > (($threadsrunning - 1) * $gSpamsPerThread)
- && $threadsrunning < $gMaxThreads);
+ start_sa if (scalar(@ids) > (($threadsrunning - 1) * $config{spam_spams_per_thread})
+ && $threadsrunning < $config{spam_max_threads});
sleep 30;
}