Renamed checkaddress
[clearscm.git] / maps / bin / checkaddress.pl
1 #!/usr/bin/perl
2 ################################################################################
3 #
4 # File:         $RCSfile: checkaddress,v $
5 # Revision:     $Revision: 1.1 $
6 # Description:  Check an email address
7 # Author:       Andrew@DeFaria.com
8 # Created:      Mon Jan 16 20:25:32 PST 2006
9 # Modified:     $Date: 2013/06/12 14:05:47 $
10 # Language:     perl
11 #
12 # (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
13 #
14 ################################################################################
15 use strict;
16 use warnings;
17
18 use FindBin;
19
20 use lib "$FindBin::Bin/../lib", '/opt/clearscm/lib';
21
22 use MAPS;
23 use Display;
24
25 error("Must specify an email address to check", 1) 
26   if !$ARGV[0] or $ARGV[0] eq "";
27
28 for (@ARGV) {
29   my $sender = lc $_;
30
31   my ($status, $rule);
32
33   my $username = lc $ENV{USER};
34
35   my ($user, $domain) = $sender =~ /(.+)\@(.+)/;
36
37   unless ($user and $domain) {
38     error "Illegal email address $sender";
39
40     next;
41   } # unless
42
43   if ($domain eq "defaria.com" and $user ne $username) {
44     display"Nulllist - $sender is from this domain but is not from $username";
45     next;
46   } # if
47
48   # Algorithm change: We now first check to see if the sender is not found
49   # in the message and skip it if so. Then we handle if we are the sender
50   # and that the from address is formatted properly. Spammers often use 
51   # the senders email address (i.e. andrew@defaria.com) as their from address
52   # so we check "Andrew DeFaria <Andrew@DeFaria.com>", which they have never
53   # forged. This catches a lot of spam actually.
54   #
55   # Next we check to see if the sender is on our whitelist. If so then we let
56   # them in. This allows us to say whitelist josephrosenberg@hotmail.com while
57   # still nulllisting all of the other hotmail.com spammers.
58   #
59   # Next we process blacklisted people as they are also of high priority.
60   #
61   # Then we process nulllist people.
62   #
63   # Finally, we handle return processing
64
65   # Check which list the sender is on. Note that these function calls return a
66   # list of scalars. But if we want to check to see that the first returned
67   # item is in the list we need to use a syntax of () = func(). If instead we
68   # just use if (func()) and func returns a list, then we will not see the first
69   # scalar returned as a boolen. Using () = func() does this for us.
70   if (() = OnWhitelist($sender, $username, 0)) {
71     display "Sender $sender would be whitelisted";
72   } elsif (() = OnBlacklist($sender, 0)) {
73     display "Sender $sender would be be blacklisted";
74   } elsif (() = OnNulllist($sender, 0)) {
75     display "Sender $sender would be nulllisted"
76   } else {
77     display "Sender $sender would be returned"
78   } # if 
79 } # for