]> git.donarmstrong.com Git - debbugs.git/commitdiff
* Add configuration variables for spamscan to Debbugs::Config
authorDon Armstrong <don@donarmstrong.com>
Sun, 30 Mar 2008 01:43:10 +0000 (18:43 -0700)
committerDon Armstrong <don@donarmstrong.com>
Sun, 30 Mar 2008 01:43:10 +0000 (18:43 -0700)
 * Fix spamscan to use warnings; use strict
 * Use Debbugs::Config in spamscan instead of directly sourcing /etc/debbugs/config

Debbugs/Config.pm
scripts/spamscan-sa
scripts/spamscan.in

index 8d650e07f26a19110bc2b7c70cedf9e5cc940812..5f2936a58891db5f278a5fb77bc21386a9017346 100644 (file)
@@ -67,6 +67,7 @@ BEGIN {
                                 qw(@gDefaultArchitectures),
                                 qw($gTemplateDir),
                                 qw($gDefaultPackage),
+                                qw($gSpamMaxThreads $gSpamSpamsPerThread $gSpamKeepRunning $gSpamScan $gSpamCrossassassinDb)
                                ],
                     text     => [qw($gBadEmailPrefix $gHTMLTail $gHTMLExpireNote),
                                 ],
@@ -642,6 +643,92 @@ Whether or not spamscan is being used; defaults to 0 (not being used
 
 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
 
index 3dd5f19efd1f5cd3eb238e084abefff3e08a2a03..190cca58de9798c70486d90a780ce2d8989eaeca 100755 (executable)
@@ -4,16 +4,16 @@
 
 # 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;
@@ -30,20 +30,21 @@ sub header_or_empty ($$) {
     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: $!";
@@ -68,11 +69,13 @@ while (my $id = <STDIN>) {
     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;
@@ -94,7 +97,7 @@ while (my $id = <STDIN>) {
                    $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;
@@ -104,7 +107,7 @@ while (my $id = <STDIN>) {
            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"
@@ -125,7 +128,7 @@ while (my $id = <STDIN>) {
     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) {
index 7e25a7bf4438183f27201e90f87e67d4f7036bde..d1acbe1d76ae420ac4b6ee9b337942fb4e92a2a1 100755 (executable)
 # 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 $@;
 
@@ -52,6 +50,7 @@ my $assassinated_lock : shared;
 my $crossassassinated_lock : shared;
 my $threadsrunning : shared = 0;
 
+# flush output immediately
 $| = 1;
 
 sub lprint ($) {
@@ -69,7 +68,7 @@ if (-e $user_prefs) {
 
 # 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) {
@@ -136,13 +135,13 @@ getid:        for (;;) {
            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;
            }
@@ -182,7 +181,7 @@ crossret:   for (;;) {
                last pp;
            }
            my $todo;
-           unless ($todo = <$saout>) {
+           unless (defined($todo = <$saout>)) {
                lprint "{$mytid} Could not read todo: $!\n";
                last pp;
            }
@@ -202,14 +201,14 @@ crossret:   for (;;) {
            }
            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;
            }
@@ -227,24 +226,20 @@ crossret:   for (;;) {
 }
 
 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;
@@ -279,8 +274,8 @@ for (;;) {
        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;
 }