# 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;
my $value = $mail->get_header($hdr);
if (defined $value) {
chomp $value;
- $value =~ tr/\n/\\n/;
+ # replace newlines with '\n'
+ $value =~ s/\n/\\n/g;
return $value;
}
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;
$out .= " spam $score\n";
$nseen = $score;
} else {
+ my ($before, $received, $after) = $headers =~
+ /(^.*?)(^Received\: \(at .*?\n)(.*$)/ms;
open OUT, "> incoming/I$id" or die "open incoming/I$id: $!";
- my ($received, $from, $other_headers) =
- split(/\n/, $headers, 3);
- if ($recevied =~ /^From /) {
- ($received, $from) = ($from, $received);
- }
- print OUT "$received\n$from\n$other_headers"
+ print OUT $received . $before . $after
or die "print incoming/I$id: $!";
if ($ca_score > 1) {
print OUT "X-CrossAssassin-Score: $ca_score\n"
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) {