adding extra addresses to ScamNailer

M A Young m.a.young at durham.ac.uk
Wed Nov 2 17:22:12 GMT 2011


On Mon, 3 Oct 2011, M A Young wrote:

> I would like to be able to add extra entries to the list handled by 
> ScamNailer. The web pages suggest that there should be a local file I can 
> use, but I have looked through the ScamNailer program and can't find it. I 
> am missing something obvious or do I have to modify the code myself to add 
> one.

As I didn't get a reply, I did modify the code myself to use a local file 
to add and remove entries. I am attaching a patch of the changes I made in 
case it is useful to anyone else.

 	Michael Young
-------------- next part --------------
--- ScamNailer-2.09.orig	2011-09-28 14:15:05.000000000 +0100
+++ ScamNailer-2.09	2011-10-27 12:49:00.000000000 +0100
@@ -11,6 +11,7 @@
 # users, then you can use it and change it freely, but please keep my
 # name and email address at the top.
 #
+# Changes added to allow local edits Oct 2011
 
 use strict;
 use File::Temp;
@@ -140,6 +141,8 @@
   my $urlbase = "http://www.mailscanner.tv/emails.";
   my $target= $emailscurrent . 'phishing.emails.list';
   my $query="emails.msupdate.greylist.bastionmail.com";
+  my $localedits = $emailscurrent . 'local.edits';
+  my $localcache = $cache . 'local.temp.file';
 
   my $baseupdated = 0;
   if (! -d $emailscurrent) {
@@ -345,6 +348,76 @@
 
   }
 
+  if ($generate && -s $localedits) {
+    my %localupdates=();
+    open (FILE, "$localedits") or die
+          "Unable to open local edits file ($localedits)\n";
+    while (<FILE>) {
+      chop;
+      my $line=$_;
+      # Is it an addition?
+      if ($line =~ /^\> (.+)$/) {
+        if (defined $localupdates{$1}) {
+          if ($localupdates{$1} eq "<") {
+            delete $localupdates{$1};
+          }
+        } else {
+          $localupdates{$1}=">";
+        }
+      }
+      # Is it an removal?
+      if ($line =~ /^\< (.+)$/) {
+        if (defined $localupdates{$1}) {
+          if ($localupdates{$1} eq ">") {
+            delete $localupdates{$1};
+          }
+        } else {
+          $localupdates{$1}="<";
+        }
+      }
+    }
+    close(FILE);
+
+    # open latest cache file
+    my $file;
+    if ($currentupdate>0) {
+      $file="$cache/$currentbase.$currentupdate";
+    } else {
+      $file="$cache/$currentbase";
+    }
+    open (FILE, "$file") or die
+          "Unable to open file ($file)\n";
+    # Now open the temporary cache file
+    open (FILEOUT, ">$localcache") or die
+         "Unable to write to temporary cache file ($localcache)";
+    # Loop through the base file (or most recent update)
+    while (<FILE>) {
+      chop;
+      my $line=$_;
+
+      if (defined ($localupdates{$line})) {
+        # Does the line need removing?
+        if ($localupdates{$line} eq "<") {
+          next;
+        }
+        # Is it marked as an addition but already present?
+        elsif ($localupdates{$line} eq ">") {
+          delete $localupdates{$line};
+        }
+      }
+      print FILEOUT $line."\n";
+    }
+    close (FILE);
+    my $line;
+    # Are there any additions left
+    foreach $line (keys %localupdates) {
+      if ($localupdates{$line} eq ">") {
+        print FILEOUT $line."\n" ;
+      }
+    }
+    close (FILEOUT);
+  }
+
   # Changes have been made
   if ($generate) {
     print "Updating live file $target\n" unless $quiet;
@@ -357,6 +430,9 @@
     if ($file eq "") {
       die "Unable to work out file!\n";
     }
+    if ( -f $localcache ) {
+      $file="$localcache";
+    }
 
     system ("mv -f $target $target.old");
     system ("cp $file $target");


More information about the MailScanner mailing list