More improvements
authorAndrew DeFaria <Andrew@DeFaria.com>
Thu, 12 Aug 2021 19:45:40 +0000 (12:45 -0700)
committerAndrew DeFaria <Andrew@DeFaria.com>
Thu, 12 Aug 2021 19:45:40 +0000 (12:45 -0700)
. Changed checkaddress.cgi to be more informative about other fields
  such as retention and comment.
. Changed maps main script to use full list record so as to allow the
  ability to report individual fields in the list record instead of just
  returning rule
. Changed detail.cgi to use list record instead of just rule
. Changed detail.cgi to handle corner cases where there are 1 less than
  the number of lines to be displayed.
. Added retention to Returned report
. Fixed font size problem with comment
. Made Checkaddress window a little bigger.
. MAPS.pm: Changed the way the ReturnSenders returns senders. A little
  more array manipulation but more accurate. Also made sure email
  addresses are downshifted before adding to log table.

maps/JavaScript/CheckAddress.js
maps/bin/add2blacklist.cgi
maps/bin/add2nulllist.cgi
maps/bin/add2whitelist.cgi
maps/bin/checkaddress.cgi
maps/bin/detail.cgi
maps/bin/maps
maps/css/MAPSStyle.css

index 13ad442..aa6c918 100644 (file)
@@ -18,13 +18,13 @@ function checkaddress (form, user) {
   }
 
   var features = 
-    "height=320"       + "," +
-    "location=no"      + "," +
-    "menubar=no"       + "," +
-    "status=no"                + "," +
-    "toolbar=no"       + "," +
-    "scrollbar=yes"    + "," +
-    "width=600";
+    "height=320"    + "," +
+    "location=no"   + "," +
+    "menubar=no"    + "," +
+    "status=no"     + "," +
+    "toolbar=no"    + "," +
+    "scrollbar=yes" + "," +
+    "width=800";
 
   var url = "/maps/bin/checkaddress.cgi?";
 
index bfa8f4d..cbc395f 100755 (executable)
@@ -50,7 +50,7 @@ sub Add2List(%) {
 
     $rec{sender} = CheckEmail $rec{pattern}, $rec{domain};
 
-    my ($status, $rule) = OnBlacklist($rec{sender});
+    my ($status) = OnBlacklist($rec{sender});
 
     if ($status) {
       print br {-class => 'error'},
index 1007526..d4b7f73 100755 (executable)
@@ -51,7 +51,7 @@ sub Add2List(%) {
 
     $rec{sender} = CheckEmail $rec{pattern}, $rec{domain};
 
-    my ($status, $rule) = OnNulllist($rec{sender});
+    my ($status) = OnNulllist($rec{sender});
 
     if ($status) {
       print br {-class => 'error'},
index e8cd9e2..4aa7379 100755 (executable)
@@ -51,7 +51,7 @@ sub Add2List(%) {
 
     $rec{sender} = CheckEmail $rec{pattern}, $rec{domain};
 
-    my ($status, $rule) = OnWhitelist($rec{sender}, $rec{userid});
+    my ($status) = OnWhitelist($rec{sender}, $rec{userid});
 
     if ($status) {
       print br {-class => 'error'},
index ddec3d5..a1b0d5e 100755 (executable)
@@ -36,7 +36,29 @@ if (param "user") {
 
 $userid //= $ENV{USER};
 
-my $sender = param("sender");
+my $sender = param 'sender';
+
+sub formatRule($$$) {
+  my ($list, $email_on_file, $rec) = @_;
+
+  my $next  = $rec->{sequence} - 1;
+  my $rule  = "Rule: $email_on_file (";
+     $rule .= a {
+       -href   => "/maps/php/list.php?type=$list&next=$next",
+       -target => '_blank',
+     }, "$list:$rec->{sequence}";
+     $rule .= ')' . br;
+
+     if ($rec->{retention}) {
+       $rule .= "Retention: " . $rec->{retention} . br;
+     } # if
+
+     if ($rec->{comment}) {
+       $rule .= "Comment: " . $rec->{comment};
+     } # if
+
+  return $rule;
+} # formatRule
 
 sub Heading() {
   print
@@ -51,7 +73,7 @@ sub Heading() {
 } # Heading
 
 sub Body() {
-  my ($onlist, $rule);
+  my ($onlist, $rec);
 
   # Algorithm change: We now first check to see if the sender is not found
   # in the message and skip it if so. Then we handle if we are the sender
@@ -69,29 +91,36 @@ sub Body() {
   # Then we process nulllist people.
   #
   # Finally, we handle return processing
-  ($onlist, $rule) = OnWhitelist($sender, $userid, 0);
+
+  # Some email addresses have a '+' in them (e.g. 
+  # wipro+autoreply@talent.icims.com). The problem is that CGI.pm replaces the
+  # '+' with a space. Now email addresses cannot contain spaces so we're gonna
+  # assume that a space in the email should be a '+'.
+  $sender =~ s/\s/\+/g;
+
+  ($onlist, $rec) = OnWhitelist($sender, $userid, 0);
 
   if ($onlist) {
     print div {-align => "center"},
       font {-color => "green"},
         "Messages from", b ($sender), "will be", b ("delivered"), br, hr;
-    print $rule;
+    print formatRule('white', $sender, $rec);
   } else {
-    ($onlist, $rule) = OnBlacklist($sender, 0);
+    ($onlist, $rec) = OnBlacklist($sender, 0);
 
     if ($onlist) {
       print div {-align => "center"},
            font {-color => "black"},
             "Messages from", b ($sender), "will be", b ("blacklisted"), br, hr;
-      print $rule;
+      print formatRule('black', $sender, $rec);
     } else {
-      ($onlist, $rule) = OnNulllist($sender, 0);
+      ($onlist, $rec) = OnNulllist($sender, 0);
 
       if ($onlist) {
         print div {-align => "center"},
              font {-color => "grey"},
             "Messages from", b ($sender), "will be", b ("discarded"), br, hr;
-        print $rule;
+        print formatRule('null', $sender, $rec);
       } else {
         print div {-align => "center"},
              font {-color => "red"},
index ef67882..06e8bd9 100755 (executable)
@@ -32,10 +32,11 @@ use MAPSLog;
 use MAPSWeb;
 use DateUtils;
 
-my $type   = param 'type';
-my $next   = param 'next';
-my $lines  = param 'lines';
-my $date   = param 'date';
+my $type  = param 'type';
+my $list  = substr $type, 0, -4 if $type =~ /list$/; 
+my $next  = param 'next';
+my $lines = param 'lines';
+my $date  = param 'date';
 
 $date ||= '';
 
@@ -74,6 +75,17 @@ my %types = (
   ]
 );
 
+sub formatRule($) {
+  my ($rec) = @_;
+
+  return '' unless $rec->{pattern} or $rec->{domain};
+
+  $rec->{pattern} //= '';
+  $rec->{domain}  //= '';
+
+  return "$rec->{pattern}\@$rec->{domain}";
+} # formatRule
+
 sub MakeButtons($) {
   my ($type) = @_;
 
@@ -150,6 +162,8 @@ sub Body($) {
 
   my $current = $next + 1;
 
+  my ($onlist, $rec);
+
   print div {-align => 'center'}, b (
     '(' . $current . '-' . $last . ' of ' . $total . ')');
   print start_form {
@@ -171,12 +185,13 @@ sub Body($) {
 
   print
     Tr [
-      th {-class  => 'tablebordertopleft'},  '',
-      th {-class  => 'tableborder'},         'Sender',
-      th {-class  => 'tableborder'},         'List',
-      th {-class  => 'tableborder'},         'Hit Count',
-      th {-class  => 'tableborder'},         'Rule',
-      th {-class  => 'tablebordertopright'}, 'Comment',
+      th {-class => 'tablebordertopleft'},  '',
+      th {-class => 'tableborder'},         'Sender',
+      th {-class => 'tableborder'},         'List',
+      th {-class => 'tableborder'},         'Hit Count',
+      th {-class => 'tableborder'},         'Rule',
+      th {-class => 'tableborder'},         'Retention',
+      th {-class => 'tablebordertopright'}, 'Comment/Date',
     ];
 
   my @senders = ReturnSenders(
@@ -227,45 +242,16 @@ sub Body($) {
       $heading = $msgs->[0]{subject} if $msgs->[0]{subject};
     } # if
 
-    my ($onlist, $seq);
-
-    my $rule      = 'none';
-    my $hit_count = 0;
-
-    ($onlist, $rule, $seq, $hit_count) = OnWhitelist($sender, $userid, 0);
+    ($onlist, $rec) = OnWhitelist($sender, $userid, 0);
 
     unless ($onlist) {
-      ($onlist, $rule, $seq, $hit_count) = OnBlacklist($sender, 0);
+      ($onlist, $rec) = OnBlacklist($sender, 0);
 
       unless ($onlist) {
-        ($onlist, $rule, $seq, $hit_count) = OnNulllist($sender, 0);
+        ($onlist, $rec) = OnNulllist($sender, 0);
       } # unless
     } # unless
 
-    $hit_count //= '';
-
-    my $list     = '';
-    my $sequence = 0;
-    my $comment  = '';
-
-    # Parse rule
-    if ($rule) {
-      if ($rule =~ /\((\w+):(\d+)\)\s+"(\S*)"/) {
-        $list     = $1;
-        $sequence = $2;
-        $rule     = $3;
-        $comment  = '';
-      } elsif ($rule =~ /\((\w+):(\d+)\)\s+"(\S*) - (.*)"/) {
-        $list     = $1;
-        $sequence = $2;
-        $rule     = $3;
-        $comment  = $4;
-      } # if
-
-      $rule =~ s/\\@/\@/;
-    } # if
-
-    $sequence //= 0;
     $next++;
 
     # Start Sender line
@@ -298,24 +284,40 @@ sub Body($) {
       -href  => "mailto:$sender$heading",
     }, "&nbsp;$sender";
 
-    my $listlink = ($list and $sequence) ? "$list:$sequence" : '&nbsp;';
+    if ($rec) {
+      my $listlink = ($rec->{type} and $rec->{sequence}) ? "$rec->{type}:$rec->{sequence}" : '';
+
+      $rec->{comment} //= '';
+
+      print td {
+        -class => $dataclass,
+        -align => 'right',
+      }, a {
+        href  => "/maps/php/list.php?type=$rec->{type}&next=" . ($rec->{sequence} - 1),
+      }, $listlink,
+      td {
+        -class => $dataclass,
+        -align => 'right',
+      }, "$rec->{hit_count}&nbsp;",
+      td {
+        -class => $dataclass,
+      }, formatRule($rec),
+      td {
+        -class => $dataclass,
+        -align => 'right',
+      }, "$rec->{retention}&nbsp;",
+      td {
+        -class => $rightclass,
+      }, $rec->{comment};
+    } else {
+      # $rec will be undefined if this message will be returned
+      print td {-class => $dataclass},
+            td {-class => $dataclass},
+            td {-class => $dataclass},
+            td {-class => $dataclass},
+            td {-class => $rightclass};
+    } # if
 
-    print td {
-      -class => $dataclass,
-      -align => 'right',
-    }, a {
-      href  => "/maps/php/list.php?type=$list&next=" . ($sequence - 1),
-    }, $listlink,
-    td {
-      -class => $dataclass,
-      -align => 'right',
-    }, "$hit_count&nbsp;",
-    td {
-      -class => $dataclass,
-    }, $rule,
-    td {
-      -class => $rightclass,
-    }, $comment;
     print end_Tr;
 
     my $msgnbr = 0;
@@ -347,7 +349,7 @@ sub Body($) {
         Tr [
           td {
             -class   => $subjectclass,
-            -colspan => 4,
+            -colspan => 5,
           }, a {
             -href    => "display.cgi?sender=$sender;msg_date=$rec->{timestamp}",
            }, '&nbsp;&nbsp;&nbsp;&nbsp;' . $rec->{subject},
index 6050269..8ff35a7 100755 (executable)
@@ -122,6 +122,12 @@ sub ValidDomainUser($) {
   return defined $uid ? 1 : 0;
 } # ValidDomainUser
 
+sub formatRule($) {
+  my ($rec) = @_;
+
+  return "Rule: $rec->{pattern}\@$rec->{domain}:$rec->{sequence}/$rec->{hit_count}";
+} # formatRule
+
 sub ProcessMsgs ($$$) {
   my ($msgfile, $username, $user_email) = @_;
 
@@ -130,7 +136,7 @@ sub ProcessMsgs ($$$) {
   while (!eof $msgfile) {
     my ($sender, $sender_long, $reply_to, $subject, $data) = ReadMsg ($msgfile);
 
-    my ($onlist, $rule, $sequence, $hit_count);
+    my ($onlist, $rec, $sequence, $hit_count);
 
     # Algorithm change: We now first check to see if the sender is not found
     # in the message and skip it if so. Then we handle if we are the sender
@@ -163,13 +169,13 @@ sub ProcessMsgs ($$$) {
     } # if
 
     # Check whitelist:
-    ($onlist, $rule, $sequence, $hit_count) = OnWhitelist $sender;
+    ($onlist, $rec) = OnWhitelist $sender;
 
     if ($onlist) {
       if (ValidDomainUser $sender) {
-        $log->msg("Whitelisting $sender - Rule: $rule:$sequence/$hit_count");
+        $log->msg("Whitelisting $sender - Rule: " . formatRule($rec));
 
-        Whitelist $sender, $data, $sequence, $hit_count;
+        Whitelist $sender, $data, $rec->{sequence}, $rec->{hit_count};
       } else {
         $log->msg("Sender ($sender) from this domain but user not found");
 
@@ -180,16 +186,16 @@ sub ProcessMsgs ($$$) {
     } # if
 
     # Check blacklist:
-    ($onlist, $rule, $sequence, $hit_count) = OnBlacklist $sender;
+    ($onlist, $rec) = OnBlacklist $sender;
 
     if ($onlist) {
-      $log->msg("Blacklisting $sender - Rule: $rule:$sequence/$hit_count");
+      $log->msg("Blacklisting $sender - Rule: " . formatRule($rec));
 
       Blacklist(
         userid    => $userid,
         sender    => $sender,
-        sequence  => $sequence,
-        hit_count => $hit_count,
+        sequence  => $rec->{sequence},
+        hit_count => $rec->{hit_count},
         data      => $data,
       );
 
@@ -197,11 +203,12 @@ sub ProcessMsgs ($$$) {
     } # if 
 
     # Check nulllist:
-    ($onlist, $rule, $sequence, $hit_count) = OnNulllist $sender;
+    ($onlist, $rec) = OnNulllist $sender;
 
     if ($onlist) {
-      $log->msg("Nulllisting $sender - Rule: $rule:$sequence/$hit_count");
-      Nulllist $sender, $sequence, $hit_count;
+      #$log->msg("Nulllisting $sender - Rule: $rule:$sequence/$hit_count");
+      $log->msg("Nulllisting $sender - Rule: " . formatRule($rec));
+      Nulllist $sender, $rec->{sequence}, $rec->{hit_count};
       next;
     } # if
 
index 5849c91..93bf030 100644 (file)
@@ -497,7 +497,7 @@ img {
   border-right:  solid 3px SteelBlue;
   border-left:   1px dotted #ccc;
   border-bottom: 1px dotted #ccc;
-  font-size:     12px;
+  font-size:     14px;
 }
 .tablebottomleft {
   background:                    White;