X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=maps%2Fbin%2Fadd2nulllist.cgi;fp=maps%2Fbin%2Fadd2nulllist.cgi;h=d4b7f731c5027fbbf729f388049e999a154b4b0e;hb=88c9cb9f6ed80dd31981b083593b1746695083b9;hp=2e17093a735dfbdedede0a3b5799d61e71b36fc1;hpb=56890e6a4f7bd3681fdc4b6db0cdce1ef0ec5e47;p=clearscm.git diff --git a/maps/bin/add2nulllist.cgi b/maps/bin/add2nulllist.cgi index 2e17093..d4b7f73 100755 --- a/maps/bin/add2nulllist.cgi +++ b/maps/bin/add2nulllist.cgi @@ -16,85 +16,114 @@ use strict; use warnings; use FindBin; -$0 = $FindBin::Script; + +local $0 = $FindBin::Script; use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../lib"; + +use Utils; use MAPS; use MAPSLog; use MAPSWeb; -use MAPSUtil; use CGI qw/:standard *table/; use CGI::Carp 'fatalsToBrowser'; -my $userid; -my $Userid; -my $type = 'null'; +sub Add2List(%) { + my (%rec) = @_; -sub Add2List() { - my $sender = ''; - my $nextseq = GetNextSequenceNo($userid, $type); + CheckParms(['userid', 'type'], \%rec); + + my $nextseq = GetNextSequenceNo(%rec); + + my $Userid = ucfirst $rec{userid}; while () { - my $pattern = param "pattern$nextseq"; - my $domain = param "domain$nextseq"; - my $comment = param "comment$nextseq"; - my $hit_count = param "hit_count$nextseq"; + $rec{pattern} = param "pattern$nextseq"; + $rec{domain} = param "domain$nextseq"; + $rec{comment} = param "comment$nextseq"; + $rec{hit_count} = param "hit_count$nextseq"; + $rec{retention} = param "retention$nextseq"; - last if ((!defined $pattern || $pattern eq '') && - (!defined $domain || $domain eq '')); + last unless $rec{pattern} or $rec{domain}; - $sender = CheckEmail $pattern, $domain; + $rec{sender} = CheckEmail $rec{pattern}, $rec{domain}; - my ($status, $rule) = OnNulllist($sender); + my ($status) = OnNulllist($rec{sender}); - if ($status != 0) { - print br {-class => 'error'}, "The email address $sender is already on ${Userid}'s $type list"; + if ($status) { + print br {-class => 'error'}, + "The email address $rec{sender} is already on ${Userid}'s $rec{type} list"; } else { - $hit_count ||= CountMsg($sender); - - Add2Nulllist($sender, $userid, $comment, $hit_count); + my ($messages, $msg) = Add2Nulllist(%rec); - print br "The email address, $sender, has been added to ${Userid}'s $type list"; + if ($messages < -1) { + print br {-class => 'error'}, "Unable to add $rec{sender} to $rec{type} list"; + return; + } else { + print br "The email address, $rec{sender}, has been added to ${Userid}'s $rec{type} list"; + } # if # Now remove this entry from the other lists (if present) for my $otherlist ('white', 'black') { - my $sth = FindList $otherlist, $sender; - my ($sequence, $count); + FindList( + userid => $rec{userid}, + type => $otherlist, + sender => $rec{sender}, + ); - ($_, $_, $_, $_, $_, $sequence) = GetList($sth); + my $seq = GetList; - if ($sequence) { - $count = DeleteList($otherlist, $sequence); + if ($seq->{sequence}) { + my $err; - print br "Removed $sender from ${Userid}'s " . ucfirst $otherlist . ' list' - if $count > 0; + ($err, $msg) = DeleteList( + userid => $rec{userid}, + type => $otherlist, + sequence => $seq->{sequence}, + ); - ResequenceList($userid, $otherlist); + croak $msg if $err < 0; + + print br "Removed $rec{sender} from ${Userid}'s " . ucfirst $otherlist . ' list' + if $err > 0; + + ResequenceList( + userid => $rec{userid}, + type => $otherlist, + ); } # if } # for } # if $nextseq++; } # while + + return; } # Add2List # Main -$userid = Heading( +my $userid = Heading( 'getcookie', '', 'Add to Null List', 'Add to Null List', ); +$userid ||= $ENV{USER}; + SetContext($userid); NavigationBar($userid); -$Userid = ucfirst $userid; +my $type = 'null'; -Add2List; +Add2List( + userid => $userid, + type => $type, +); print start_form { -method => 'post',