summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-16 15:16:43 -0700
committerJohn Denker <jsd@av8n.com>2012-07-16 16:04:51 -0700
commit14b7add3c77a79fd46ad55a43a4051a10ebfc0b4 (patch)
tree201ac3911ae85a19975926b5df48c2a4cdb35d69 /tools
parent5636774abde98bcddffdec88b297c7ff322aab43 (diff)
minor upgrades
Diffstat (limited to 'tools')
-rwxr-xr-xtools/blacklist-update52
-rw-r--r--tools/mail-scan.c8
2 files changed, 51 insertions, 9 deletions
diff --git a/tools/blacklist-update b/tools/blacklist-update
index 99fe4cc..4621ef2 100755
--- a/tools/blacklist-update
+++ b/tools/blacklist-update
@@ -1,9 +1,33 @@
#! /usr/bin/perl -w
+#########################
+# BEWARE:
+#
+# The most dangerous criminals routinely forge email from-addresses.
+# Therefore blacklisting addresses only works for senders
+# who have bad manners but are otherwise quasi-legitimate.
+#
+# Overuse of blacklisting will punish innocent parties
+# whose domain-names look nice to forgers.
+
+## hint: mail-scan +from * | iconv -c \...
+## | sed 's/.*@//;s/>$//' | sort | uniq -c | sort -nr > some-junk.from-count
+
use strict;
use Symbol;
main: {
+ my $baremode = 0;
+ my @argv = @ARGV;
+ @ARGV = ();
+ while (@argv){
+ my $arg = shift @argv;
+ if ($arg eq '-bare') {
+ $baremode++;
+ } else {
+ die "Unrecognized verbiage '$arg'\n";
+ }
+ }
my $file = '/etc/mail/spamassassin/local.cf';
my $inch = Symbol::gensym;
my $mainpart = '';
@@ -15,6 +39,7 @@ main: {
chomp $line;
my @stuff = split(' ', $line, 2);
if (0+@stuff == 2 && $stuff[0] eq $verb) {
+ my $key = lc($stuff[1]);
$blacklist{$stuff[1]} ++;
} else {
$mainpart .= $line . "\n";
@@ -23,23 +48,34 @@ main: {
close $inch;
my $unchanged = 0;
my $new = 0;
- while (my $line=<>){
+ liner: while (my $line=<>){
chomp $line;
- if ($line =~ m'<.*@(.*)>$') {
- my $key = "*@" . $1;
+ my $domain = '';
+ if ($baremode) {
+ my @stuff = split(' ', $line);
+ $domain = $stuff[$#stuff];
+ } else {
+ if ($line =~ m'<.*@(.*)>$') {
+ $domain = $1;
+ } else {
+ print STDERR "no '<user\@domain>'; ignoring line ...\n";
+ print STDERR "... '$line'\n";
+ next liner;
+ }
+ }
+ if ($domain ne '') {
+ my $key = "*@" . lc($domain);
if (exists $blacklist{$key}) {
$unchanged++;
} else {
$new++;
}
- $blacklist{$key} ++;
- } else {
- print STDERR "no '<user\@domain>'; ignoring line ...\n";
- print STDERR "... '$line'\n";
+ $blacklist{$key} ++;
}
+
}
- my $ouch = Symbol::gensym;
+ my $ouch = Symbol::gensym;
open($ouch, '>', $file)
|| die "Could not open output file '$file'\n";
print $ouch $mainpart;
diff --git a/tools/mail-scan.c b/tools/mail-scan.c
index 5ec2b25..56b3806 100644
--- a/tools/mail-scan.c
+++ b/tools/mail-scan.c
@@ -4,8 +4,14 @@
// scrutinize email
//
-// hint: mail-scan +from * \...
+// Hint:
+// mail-scan +from * | iconv -c \...
// | sed 's/.*@//;s/>$//' | sort | uniq -c | sort -nr > some-junk.from-count
+//
+// Also:
+// grep score=[34] /home/user/Maildir/new/* -l | xargs mail-scan +From | blacklist-update
+// Then:
+// grep score=[34] /home/user/Maildir/new/* -l | xargs mv-to -i /home/user/Maildir/spam/
#include <iostream>
#include <stdlib.h> /* for exit() */