Merge branch 'master' of git+ssh://github.com/adefaria/clearscm
[clearscm.git] / maps / bin / add2whitelist.cgi
index cb0eb26..6b80947 100755 (executable)
@@ -2,8 +2,8 @@
 ################################################################################
 #
 # File:         $RCSfile: add2whitelist.cgi,v $
-# Revision:    $Revision: 1.1 $
-# Description: Add an email address to the blacklist
+# Revision:     $Revision: 1.1 $
+# Description:  Add an email address to the blacklist
 # Author:       Andrew@DeFaria.com
 # Created:      Mon Jan 16 20:25:32 PST 2006
 # Modified:     $Date: 2013/06/12 14:05:47 $
@@ -18,11 +18,12 @@ use warnings;
 use FindBin;
 $0 = $FindBin::Script;
 
-use lib $FindBin::Bin;
+use lib "$FindBin::Bin/../lib";
 
 use MAPS;
 use MAPSLog;
 use MAPSWeb;
+use MAPSUtil;
 
 use CGI qw/:standard *table/;
 use CGI::Carp 'fatalsToBrowser';
@@ -31,55 +32,55 @@ my $userid;
 my $Userid;
 my $type = 'white';
 
-sub Add2List {
-  my $sender   = '';
-  my $nextseq  = MAPSDB::GetNextSequenceNo $userid, $type;
+sub Add2List() {
+  my $sender  = '';
+  my $nextseq = GetNextSequenceNo($userid, $type);
 
   while () {
-    my $pattern        = param "pattern$nextseq";
-    my $domain = param "domain$nextseq";
-    my $comment        = param "comment$nextseq";
+    my $pattern = param "pattern$nextseq";
+    my $domain  = param "domain$nextseq";
+    my $comment = param "comment$nextseq";
 
     last if ((!defined $pattern || $pattern eq '') &&
-            (!defined $domain  || $domain  eq ''));
+             (!defined $domain  || $domain  eq ''));
 
-    $sender = lc "$pattern\@$domain";
+    $sender = CheckEmail $pattern, $domain;
 
-    my ($status, $rule) = OnWhitelist $sender, $userid;
+    my ($status, $rule) = OnWhitelist($sender, $userid);
 
     if ($status != 0) {
       print br {-class => 'error'}, "The email address $sender is already on ${Userid}'s $type list";
     } else {
-      my $messages = Add2Whitelist $sender, $userid, $comment;
+      my $messages = Add2Whitelist($sender, $userid, $comment);
 
       print br "The email address, $sender, has been added to ${Userid}'s $type list";
       if ($messages > 0) {
-       if ($messages == 1) {
-         print br 'Your previous message has been delivered';
-       } else {
-         print br "Your previous $messages messages have been delivered";
-       } # if
+        if ($messages == 1) {
+          print br 'Your previous message has been delivered';
+        } else {
+          print br "Your previous $messages messages have been delivered";
+        } # if
       } elsif ($messages == -1) {
-       print br {-class => 'error'}, 'Unable to deliver message';
+        print br {-class => 'error'}, 'Unable to deliver message';
       } else {
-       print br 'Unable to find any old messages but future messages will now be delivered.';
+        print br 'Unable to find any old messages but future messages will now be delivered.';
       } # if
 
       # Now remove this entry from the other lists (if present)
-      foreach my $otherlist ('black', 'null') {
-       my $sth = FindList $otherlist, $sender;
-       my ($sequence, $count);
+      for my $otherlist ('black', 'null') {
+        my $sth = FindList($otherlist, $sender);
+        my ($sequence, $count);
 
-       ($_, $_, $_, $_, $_, $sequence) = GetList $sth;
+        ($_, $_, $_, $_, $_, $sequence) = GetList($sth);
 
-       if ($sequence) {
-         $count = DeleteList $otherlist, $sequence;
-         print br "Removed $sender from ${Userid}'s " . ucfirst $otherlist . ' list'
-           if $count > 0;
+        if ($sequence) {
+          $count = DeleteList($otherlist, $sequence);
+          print br "Removed $sender from ${Userid}'s " . ucfirst $otherlist . ' list'
+            if $count > 0;
 
-         ResequenceList $userid, $otherlist;
-       } # if
-      } # foreach
+          ResequenceList($userid, $otherlist);
+        } # if
+      } # for
     } # if
 
     $nextseq++;
@@ -87,7 +88,7 @@ sub Add2List {
 } # Add2List
 
 # Main
-$userid = Heading (
+$userid = Heading(
   'getcookie',
   '',
   'Add to White List',
@@ -98,23 +99,23 @@ $userid ||= $ENV{USER};
 
 $Userid = ucfirst $userid;
 
-SetContext $userid;
+SetContext($userid);
 
-NavigationBar $userid;
+NavigationBar($userid);
 
 Add2List;
 
 print start_form {
-  -method      => 'post',
-  -action      => 'processaction.cgi',
-  -name                => 'list'
+  -method => 'post',
+  -action => 'processaction.cgi',
+  -name   => 'list'
 };
 
 print '<p></p><center>',
-  hidden ({-name       => 'type',
-          -default     => $type}),
-  submit ({-name       => 'action',
-          -value       => 'Add New Entry'}),
+  hidden ({-name    => 'type',
+           -default => $type}),
+  submit ({-name    => 'action',
+           -value   => 'Add'}),
   '</center>';
 
 Footing;