Finally allowed "username@domain.com" to be specified
authorAndrew DeFaria <Andrew@DeFaria.com>
Wed, 27 Nov 2019 21:19:48 +0000 (14:19 -0700)
committerAndrew DeFaria <Andrew@DeFaria.com>
Wed, 27 Nov 2019 21:19:48 +0000 (14:19 -0700)
maps/bin/add2blacklist.cgi
maps/bin/add2nulllist.cgi
maps/bin/add2whitelist.cgi
maps/lib/MAPS.pm
maps/lib/MAPSUtil.pm

index 194932d..06c8125 100755 (executable)
@@ -23,6 +23,7 @@ use lib "$FindBin::Bin/../lib";
 use MAPS;
 use MAPSLog;
 use MAPSWeb;
+use MAPSUtil;
 
 use CGI qw/:standard *table/;
 use CGI::Carp 'fatalsToBrowser';
@@ -43,7 +44,7 @@ sub Add2List() {
     last if ((!defined $pattern || $pattern eq '') &&
              (!defined $domain  || $domain  eq ''));
 
-    $sender = lc "$pattern\@$domain";
+    $sender = CheckEmail $pattern, $domain;
 
     my ($status, $rule) = OnBlacklist($sender);
 
index da698dd..2e17093 100755 (executable)
@@ -23,6 +23,7 @@ use lib "$FindBin::Bin/../lib";
 use MAPS;
 use MAPSLog;
 use MAPSWeb;
+use MAPSUtil;
 
 use CGI qw/:standard *table/;
 use CGI::Carp 'fatalsToBrowser';
@@ -44,7 +45,7 @@ sub Add2List() {
     last if ((!defined $pattern || $pattern eq '') &&
               (!defined $domain || $domain  eq ''));
 
-    $sender = lc "$pattern\@$domain";
+    $sender = CheckEmail $pattern, $domain;
 
     my ($status, $rule) = OnNulllist($sender);
 
index dd7068b..6b80947 100755 (executable)
@@ -23,6 +23,7 @@ use lib "$FindBin::Bin/../lib";
 use MAPS;
 use MAPSLog;
 use MAPSWeb;
+use MAPSUtil;
 
 use CGI qw/:standard *table/;
 use CGI::Carp 'fatalsToBrowser';
@@ -43,7 +44,7 @@ sub Add2List() {
     last if ((!defined $pattern || $pattern eq '') &&
              (!defined $domain  || $domain  eq ''));
 
-    $sender = lc "$pattern\@$domain";
+    $sender = CheckEmail $pattern, $domain;
 
     my ($status, $rule) = OnWhitelist($sender, $userid);
 
index f1871ff..ae6efcc 100644 (file)
@@ -376,7 +376,7 @@ sub CheckOnList ($$;$) {
                    : !defined $domain
                    ? "$email_on_file\@"
                    : $email_on_file;
-    if ($sender =~ /$search_for/i) {
+    if ($sender and $sender =~ /$search_for/i) {
       $rule   = "Matching rule: ($listtype:$sequence) \"$email_on_file\"";
       $rule  .= " - $comment" if $comment and $comment ne '';
       $status = 1;
index 4a2a97d..43e86b3 100644 (file)
@@ -19,13 +19,16 @@ use warnings;
 
 use vars qw (@ISA @EXPORT);
 
-BEGIN {
-  $ENV{TZ}='America/Los_Angeles';
-} # BEGIN
+# Not sure why I was setting TZ to LA but I'm in Phoenix now. This is best
+# handled by configuring the OS correctly anyway.
+#BEGIN {
+#  $ENV{TZ}='America/Los_Angeles';
+#} # BEGIN
 
 @ISA = qw (Exporter);
 
-@EXPORT = qw (
+@EXPORT = qw(
+  CheckEmail
   FormatDate
   FormatTime
   SQLDatetime2UnixDatetime
@@ -36,7 +39,7 @@ BEGIN {
 
 sub Today2SQLDatetime;
 
-sub FormatDate {
+sub FormatDate($) {
   my ($date) = @_;
 
   return substr ($date, 5, 2)  . '/' .
@@ -44,7 +47,7 @@ sub FormatDate {
          substr ($date, 0, 4);
 } # FormatDate
 
-sub FormatTime {
+sub FormatTime($) {
   my ($time) = @_;
 
   my $hours   = substr $time, 0, 2;
@@ -60,7 +63,7 @@ sub FormatTime {
   return "$hours:$minutes:$seconds $AmPm";
 } # FormatTime
 
-sub SQLDatetime2UnixDatetime {
+sub SQLDatetime2UnixDatetime($) {
   my ($sqldatetime) = @_;
 
   my %months = (
@@ -86,7 +89,7 @@ sub SQLDatetime2UnixDatetime {
   return $months {$month} . " $day, $year \@ $time";
 } # SQLDatetime2UnixDatetime
 
-sub SubtractDays {
+sub SubtractDays($$) {
   my ($timestamp,$nbr_of_days) = @_;
 
   my @months = (
@@ -259,8 +262,27 @@ sub UnixDatetime2SQLDatetime($) {
   return "$year-$month-$day $time";
 } # UnixDatetime2SQLDatetime
 
-sub Today2SQLDatetime {
+sub Today2SQLDatetime() {
   return UnixDatetime2SQLDatetime(scalar localtime);
 } # Today2SQLDatetime
 
+sub CheckEmail($$) {
+  my ($username, $domain) = @_;
+
+  # Check to see if a full email address in either $username or $domain
+  if ($username eq '') {
+    return '' if $domain eq '';
+
+    if ($domain =~ /(.*)\@(.*)/) {
+      ($username, $domain) = split '@', $domain;
+    } # if
+  } elsif ($domain eq '') {
+    if ($username =~ /(.*)\@(.*)/) {
+      ($username, $domain) = split '@', $username;
+    } # if
+  } # if
+
+   return lc "$username\@$domain";
+} # CheckEmail
+
 1;