X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=maps%2Fbin%2Fmaps;h=854316bce4da4f619b2fe9c640ed07551c415c21;hb=24352d115ade3e1f4916df9c0102b1edb804f0c6;hp=4f960c4424054c5efafced4039a13f3f94a52c8a;hpb=16babf81ce331af378de565ba73e927ff5491f65;p=clearscm.git diff --git a/maps/bin/maps b/maps/bin/maps index 4f960c4..854316b 100755 --- a/maps/bin/maps +++ b/maps/bin/maps @@ -48,7 +48,7 @@ $Date: 2013/06/12 14:05:47 $ -[no]e|xecute: Set execute mode. -# (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved. +# (c) Copyright 2000-2021, Andrew@DeFaria.com, all rights reserved. =cut @@ -56,11 +56,13 @@ use strict; use warnings; use Getopt::Long; +use Email::Valid; use FindBin; use File::Temp qw (tempfile); use Net::Domain qw (hostdomain); -use lib "$FindBin::Bin/../lib", '/opt/clearscm/lib'; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../lib"; use MAPS; use MAPSLog; @@ -68,18 +70,14 @@ use MAPSLog; use Display; use Utils; -my $verbose = 0; -my $execute = 1; -my $userid = $ENV{USER}; - -my $logpath = "$FindBin::Bin/../log"; -my $logfile = "$logpath/debug.log"; -my $forwardto = $ENV{MAPS_FORWARDTO} || 'adefaria@gmail.com'; +my $verbose = 0; +my $execute = 1; +my $userid = $ENV{USER}; # For some reason I'm not parsing messages correctly but it only seems to # happen when the message is piped in from the MTA. This routine will # temporarily save the messages in a file. -sub SaveStdin () { +sub SaveStdin() { # Generate tempfile my $msgfile = tempfile (); @@ -95,7 +93,7 @@ sub SaveStdin () { return $msgfile; } # SaveStdin -sub ValidDomainUser ($) { +sub ValidDomainUser($) { my ($sender) = @_; my ($username, $domainname); @@ -120,23 +118,11 @@ sub ValidDomainUser ($) { sub ProcessMsgs ($$$) { my ($msgfile, $username, $user_email) = @_; - return - unless $execute; + return unless $execute; while (!eof *$msgfile) { my ($sender, $sender_long, $reply_to, $subject, $data) = ReadMsg (*$msgfile); - #if ($forwardto) { - # Forward a copy - #open my $mail, '|', "/usr/lib/sendmail $forwardto" - #or die "Unable to open pipe to sendmail - $!"; - - #print $mail "$data\n"; - - #close $mail - #or die "Unable to forward email to $forwardto - $!"; - #} # if - my ($onlist, $rule, $sequence, $hit_count); # Algorithm change: We now first check to see if the sender is not found @@ -156,11 +142,8 @@ sub ProcessMsgs ($$$) { # # Finally, we handle return processing - # Special sender handling: - if ($sender !~ /.+\@.+/) { - verbose "Sender not found in message or invalid"; - next; - } # if + # Discard any email with an invalid email address + next unless Email::Valid->address($sender); if ($sender eq $user_email and (lc ($sender_long) !~ lc ("\"$username\" <$user_email>") and @@ -190,9 +173,15 @@ sub ProcessMsgs ($$$) { if ($onlist) { verbose "Blacklisting $sender"; - my @msg = split /\n/, $data; - Blacklist $sender, $sequence, $hit_count, @msg; + Blacklist( + userid => $userid, + sender => $sender, + sequence => $sequence, + hit_count => $hit_count, + data => $data, + ); + next; } # if @@ -207,25 +196,30 @@ sub ProcessMsgs ($$$) { # Return processing: verbose "Returning message from $sender"; - ReturnMsg $sender, $reply_to, $subject, $data; + ReturnMsg( + userid => $userid, + sender => $sender, + reply_to => $reply_to, + subject => $subject, + data => $data, + ); } # while } # ProcessMsgs # Main -GetOptions ( +GetOptions( 'user=s' => \$userid, 'verbose' => sub { set_verbose }, 'debug' => sub { set_debug }, 'execute!' => \$execute, - 'forwardto=s' => \$forwardto ) || Usage; my $msgfile; if ($ARGV[0] and $ARGV[0] ne "") { - open $msgfile, $ARGV[0]; + open $msgfile, '<', $ARGV[0]; - if (!$msgfile) { + unless ($msgfile) { Error "Unable to open file ($ARGV[0]): $!\n"; exit 1; } # if @@ -235,9 +229,9 @@ if ($ARGV[0] and $ARGV[0] ne "") { verbose "Starting MAPS...."; -my ($username, $user_email) = SetContext $userid +my %userOptions = SetContext $userid or die "$userid is not a registered MAPS user\n"; -ProcessMsgs $msgfile, $username, $user_email; +ProcessMsgs $msgfile, $userOptions{name}, $userOptions{email}; exit 0;