X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=maps%2Fbin%2Fadd2nulllist.pl;h=8ae2c78afd419c4cd401a0f70b3d0430ed500da2;hb=37489534599748bb39434caf2eb59a1211c651fe;hp=21755b38fd42f602a062935277a00b3d17200c4a;hpb=020a4a5ea2be725b155cae3a2cadc9aba3911b9b;p=clearscm.git diff --git a/maps/bin/add2nulllist.pl b/maps/bin/add2nulllist.pl index 21755b3..8ae2c78 100755 --- a/maps/bin/add2nulllist.pl +++ b/maps/bin/add2nulllist.pl @@ -4,7 +4,7 @@ use warnings; use FindBin; -use lib $FindBin::Bin, '/opt/clearscm/lib'; +use lib "$FindBin::Bin/../lib", '/opt/clearscm/lib'; use MAPS; use MAPSLog; @@ -16,81 +16,92 @@ my $userid = $ENV{USER}; my $Userid; my $type = "null"; -sub GetItems { - my $filename = shift; +sub GetItems($) { + my ($filename) = @_; my @items; - open FILE, $filename + open my $file, '<', $filename or error "Unable to open $filename - $!", 1; - while () { + while (<$file>) { my @fields = split; my %item; - my @address = split /\@/, $fields [0]; + my @address = split /\@/, $fields[0]; - $item {pattern} = $address [0]; - $item {domain} = $address [1]; - $item {comment} = $fields [1] ? $fields [1] : ""; + $item{pattern} = $address[0]; + $item{domain} = $address[1]; + $item{comment} = $fields[1] ? $fields[1] : ''; + $item{hit_count} = $fields[2] ? $fields[2] : 0; push @items, \%item; } # while + close $file; + return @items; } # GetItems -sub Add2List { - my @items = @_; +sub Add2List(@) { + my @items = @_; - my $sender = ""; - my $nextseq = MAPSDB::GetNextSequenceNo $userid, $type; + my $sender = ''; + my $nextseq = GetNextSequenceNo($userid, $type); - foreach (@items) { - my %item = %{$_}; + for (@items) { + my %item = %{$_}; - my $pattern = $item {pattern}; - my $domain = $item {domain}; - my $comment = $item {comment}; + my $pattern = $item{pattern}; + my $domain = $item{domain}; + my $comment = $item{comment}; + my $hit_count = $item{hit_count}; display_nolf "Adding $pattern\@$domain ($comment) to null list ($nextseq)..."; - last if ((!defined $pattern || $pattern eq "") && - (!defined $domain || $domain eq "")); - $sender = lc ("$pattern\@$domain"); - if (OnNulllist $sender) { - display " Already on list"; + last if ((!defined $pattern || $pattern eq '') && + (!defined $domain || $domain eq '')); + + $sender = lc ("$pattern\@$domain"); + + if (OnNulllist($sender)) { + display ' Already on list'; } else { - Add2Nulllist $sender, $userid, $comment; - display " done"; - + Add2Nulllist($sender, $userid, $comment, $hit_count); + display ' done'; + # Now remove this entry from the other lists (if present) - foreach my $otherlist ("white", "black") { - my $sth = FindList $otherlist, $sender; - my ($sequence, $count); - ($_, $_, $_, $_, $_, $sequence) = GetList $sth; - if (defined $sequence) { - $count = DeleteList $otherlist, $sequence; - } # if - } # foreach + for my $otherlist ('white', 'black') { + my $sth = FindList($otherlist, $sender); + my ($sequence, $count); + + ($_, $_, $_, $_, $_, $sequence) = GetList($sth); + + if ($sequence) { + $count = DeleteList($otherlist, $sequence); + } # if + } # for } # if + $nextseq++; } # while + + return; } # Add2List # Main my $filename; -if ($ARGV [0]) { - $filename = $ARGV [0]; +if ($ARGV[0]) { + $filename = $ARGV[0]; } else { error "Must specify a filename of addresses to null list", 1; } # if -SetContext $userid; +SetContext($userid); $Userid = ucfirst $userid; -Add2List (GetItems $filename); +Add2List(GetItems ($filename)); exit;