X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=maps%2Flib%2FMAPS.pm;h=92a03218982087b04aa52b77a7d8e1e0100e7bf7;hb=cbfba1c8c330651d563f03ba6e2b04ce48c79896;hp=d316fe7ad8057a77c865dd0f882ea4661f43c681;hpb=78af69cf92b70f02be49fe730a3587b9b182bfe7;p=clearscm.git diff --git a/maps/lib/MAPS.pm b/maps/lib/MAPS.pm index d316fe7..92a0321 100644 --- a/maps/lib/MAPS.pm +++ b/maps/lib/MAPS.pm @@ -34,7 +34,7 @@ use base qw(Exporter); our $db; -our $Version = '2.0'; +our $VERSION = '2.0'; # Globals my $userid = $ENV{MAPS_USERNAME} ? $ENV{MAPS_USERNAME} : $ENV{USER}; @@ -57,6 +57,7 @@ our @EXPORT = qw( CountEmail CountList CountLog + CountLogDistinct Decrypt DeleteEmail DeleteList @@ -154,6 +155,8 @@ sub OpenDB($$) { $db = MyDB->new($username, $password, $dbname, $dbserver); croak "Unable to instantiate MyDB ($username\@$dbserver:$dbname)" unless $db; + + return; } # OpenDB BEGIN { @@ -223,6 +226,7 @@ sub Add2Whitelist(%) { # Add to white list $params{sequence} = 0; + my ($err, $msg) = AddList(%params); return -$err, $msg if $err; @@ -247,7 +251,7 @@ sub Add2Whitelist(%) { while (my $rec = $db->getnext) { last unless $rec->{userid}; - $status = Whitelist($rec->{sender}, $rec->data); + $status = Whitelist($rec->{sender}, $rec->{data}); last if $status; @@ -344,6 +348,7 @@ sub AddUserOptions(%) { } # for return ($err, $msg) if $err; + return; } # AddUserOptions sub Blacklist(%) { @@ -403,6 +408,8 @@ sub CheckEmail(;$$) { if ($username) { if ($username =~ /(.*)\@(.*)/) { return lc "$1\@$2"; + } else { + return lc "$username\@"; } # if } elsif ($domain) { if ($domain =~ /(.*)\@(.*)/) { @@ -627,7 +634,20 @@ sub CountLog(%) { my $condition = "userid='$userid'"; $condition .= " and $additional_condition" if $additional_condition; - return $db->count_distinct('log', 'sender', $condition); + return $db->count('log', $condition); +} # CountLog + +sub CountLogDistinct(%) { + my (%params) = @_; + + CheckParms(['userid', 'column'], \%params); + + my ($additional_condition) = delete $params{additional} || ''; + + my $condition = "userid='$userid'"; + $condition .= " and $additional_condition" if $additional_condition; + + return $db->count_distinct('log', $params{column}, $condition); } # CountLog sub Decrypt ($$) { @@ -780,11 +800,7 @@ sub GetUser() { sub GetUserInfo($) { my ($userid) = @_; - my $userinfo = $db->getone('user', "userid='$userid'", ['name', 'email']); - return %{$db->getone('user', "userid='$userid'", ['name', 'email'])}; - - return %$userinfo; } # GetUserInfo sub GetUserOptions($) { @@ -1171,8 +1187,7 @@ sub ReturnSenders(%) { # Finally slice for the given range my $end_at = $params{start_at} + $params{lines} - 1; - $end_at = (@senders - 1) - if $end_at > @senders; + $end_at = (@senders - 1) if $end_at >= @senders; return (@senders) [$params{start_at} .. $end_at]; } # ReturnSenders @@ -1275,7 +1290,7 @@ sub SetContext($) { if (UserExists($to_user)) { $userid = $to_user; - return GetUserInfo $userid; + return GetUserOptions $userid; } else { return 0; } # if @@ -1310,11 +1325,11 @@ sub UpdateList(%) { my $table = 'list'; my $condition = "userid = '$rec{userid}' and type = '$rec{type}' and sequence = $rec{sequence}"; - if ($rec{pattern} =~ /\@/ and !$rec{domain}) { + if ($rec{pattern} =~ /\@/ && !$rec{domain}) { ($rec{pattern}, $rec{domain}) = split /\@/, $rec{pattern}; - } elsif (!$rec{pattern} and $rec{domain} =~ /\@/) { + } elsif (!$rec{pattern} && $rec{domain} =~ /\@/) { ($rec{pattern}, $rec{domain}) = split /\@/, $rec{domain}; - } elsif (!$rec{pattern} and !$rec{domain}) { + } elsif (!$rec{pattern} && !$rec{domain}) { return "Must specify either Username or Domain"; } # if