summaryrefslogtreecommitdiff
path: root/tools/blacklist-update
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-16 15:09:24 -0700
committerJohn Denker <jsd@av8n.com>2012-07-16 15:09:24 -0700
commit5636774abde98bcddffdec88b297c7ff322aab43 (patch)
tree8d5e0c98886f95d8e4fe131dff7a245db5807802 /tools/blacklist-update
parenta73009734a8f795d3c1fabe3a4cfc43501010464 (diff)
utility for updating the blacklist entries in /etc/mail/spamassassin/local.cf
Diffstat (limited to 'tools/blacklist-update')
-rwxr-xr-xtools/blacklist-update53
1 files changed, 53 insertions, 0 deletions
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 '<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";
+}