blob: 99fe4cc88840f44d621cdcbad1ea57861fc7e060 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#! /usr/bin/perl -w
use strict;
use Symbol;
main: {
my $file = '/etc/mail/spamassassin/local.cf';
my $inch = Symbol::gensym;
my $mainpart = '';
my %blacklist = ();
my $verb = 'blacklist_from';
open($inch, '<', $file)
|| die "Could not open input file '$file'\n";
while (my $line = <$inch>) {
chomp $line;
my @stuff = split(' ', $line, 2);
if (0+@stuff == 2 && $stuff[0] eq $verb) {
$blacklist{$stuff[1]} ++;
} else {
$mainpart .= $line . "\n";
}
}
close $inch;
my $unchanged = 0;
my $new = 0;
while (my $line=<>){
chomp $line;
if ($line =~ m'<.*@(.*)>$') {
my $key = "*@" . $1;
if (exists $blacklist{$key}) {
$unchanged++;
} else {
$new++;
}
$blacklist{$key} ++;
} else {
print STDERR "no '<user\@domain>'; ignoring line ...\n";
print STDERR "... '$line'\n";
}
}
my $ouch = Symbol::gensym;
open($ouch, '>', $file)
|| die "Could not open output file '$file'\n";
print $ouch $mainpart;
for my $baddy (sort keys %blacklist){
print $ouch "$verb $baddy\n";
}
close $ouch;
my $updated = $unchanged + $new;
my $total = 0+(keys %blacklist);
print "$new new + $unchanged unchanged = $updated updated; $total new total\n";
}
|