X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=maps%2Fbin%2Fadd2nulllist.pl;h=82a371427487a7bdfc4c2b58564ae5705b0cf9d4;hb=8d6e59ba7728e19d42da1533b9f24d0216867899;hp=b6003c240350eeee3118f7ab85966757eb8bc077;hpb=842a2738bfac772cf226f08a9fa9753377e8a323;p=clearscm.git diff --git a/maps/bin/add2nulllist.pl b/maps/bin/add2nulllist.pl index b6003c2..82a3714 100755 --- a/maps/bin/add2nulllist.pl +++ b/maps/bin/add2nulllist.pl @@ -4,7 +4,8 @@ use warnings; use FindBin; -use lib $FindBin::Bin, '/opt/clearscm/lib'; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../lib"; use MAPS; use MAPSLog; @@ -14,10 +15,12 @@ use Display; # Highly specialized! my $userid = $ENV{USER}; my $Userid; -my $type = "null"; +my $type = 'null'; -sub GetItems { - my $filename = shift; +die "TODO: Test this script"; + +sub GetItems($) { + my ($filename) = @_; my @items; @@ -28,12 +31,13 @@ sub GetItems { 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{hit_count} = $fields[2] ? $fields[2] : 0; + $item{retention} = $fields[3]; push @items, \%item; } # while @@ -43,46 +47,64 @@ sub GetItems { return @items; } # GetItems -sub Add2List { - my @items = @_; +sub Add2List(@) { + my (@items) = @_; - my $sender = ""; - my $nextseq = MAPSDB::GetNextSequenceNo $userid, $type; + my $item; - foreach (@items) { - my %item = %{$_}; + my $item->{sequence} = GetNextSequenceNo( + userid => $userid, + type => $type, + ); - my $pattern = $item{pattern}; - my $domain = $item{domain}; - my $comment = $item{comment}; - my $hit_count = $item{hit_count}; + $item->{userid} = $userid; + $item->{type} = $type; - display_nolf "Adding $pattern\@$domain ($comment) to null list ($nextseq)..."; + for $item (@items) { + display_nolf "Adding $item->{pattern}\@$item->{domain} ($item->{comment}) to null list ($item->{sequence})..."; - last if ((!defined $pattern || $pattern eq '') && - (!defined $domain || $domain eq '')); + last unless $item->{pattern} or $item->{domain}; - $sender = lc ("$pattern\@$domain"); + $item->{sender} = CheckEmail $item->{pattern}, $item->{domain}; - if (OnNulllist $sender) { - display " Already on list"; - } else { - Add2Nulllist $sender, $userid, $comment, $hit_count; - display " done"; + my ($status, $rule) = OnNulllist($item->{sender}, $userid); - # Now remove this entry from the other lists (if present) - foreach my $otherlist ("white", "black") { - my $sth = FindList $otherlist, $sender; - my ($sequence, $count); + if ($status) { + display ' Already on list'; + } else { + my ($message, $msg) = Add2Nulllist(%$item); - ($_, $_, $_, $_, $_, $sequence) = GetList $sth; + display ' done'; - if ($sequence) { - $count = DeleteList $otherlist, $sequence; + # Now remove this entry from the other lists (if present) + for my $otherlist ('white', 'black') { + FindList( + userid => $item->{userid}, + type => $otherlist, + sender => $item->{sender} + ); + + my $seq = GetList; + + if ($seq->{sequence}) { + my $count = DeleteList( + userid => $item->{userid}, + type => $otherlist, + sequence => $seq->{sequence}, + ); + + display "Removed $item->{sender} from ${Userid}'s " . ucfirst $otherlist . ' list' + if $count > 0; + + ResequenceList( + userid => $item->{userid}, + type => $otherlist, + ); } # if - } # foreach + } # for } # if - $nextseq++; + + $item->{sequence}++; } # while return; @@ -91,16 +113,16 @@ sub Add2List { # Main my $filename; -if ($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;