From 5636774abde98bcddffdec88b297c7ff322aab43 Mon Sep 17 00:00:00 2001 From: John Denker Date: Mon, 16 Jul 2012 15:09:24 -0700 Subject: utility for updating the blacklist entries in /etc/mail/spamassassin/local.cf --- tools/blacklist-update | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 tools/blacklist-update diff --git a/tools/blacklist-update b/tools/blacklist-update new file mode 100755 index 0000000..99fe4cc --- /dev/null +++ b/tools/blacklist-update @@ -0,0 +1,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 ''; 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"; +} -- cgit v1.2.3