Added use lib for clearscm
[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";
21 use lib "$FindBin::Bin/../../lib";
22
23 use MAPS;
24 use Display;
25
26 error("Must specify an email address to check", 1) 
27   if !$ARGV[0] or $ARGV[0] eq "";
28
29 for (@ARGV) {
30   my $sender = lc $_;
31
32   my ($status, $rule);
33
34   my $username = lc $ENV{USER};
35
36   my ($user, $domain) = $sender =~ /(.+)\@(.+)/;
37
38   unless ($user and $domain) {
39     error "Illegal email address $sender";
40
41     next;
42   } # unless
43
44   if ($domain eq "defaria.com" and $user ne $username) {
45     display"Nulllist - $sender is from this domain but is not from $username";
46     next;
47   } # if
48
49   # Algorithm change: We now first check to see if the sender is not found
50   # in the message and skip it if so. Then we handle if we are the sender
51   # and that the from address is formatted properly. Spammers often use 
52   # the senders email address (i.e. andrew@defaria.com) as their from address
53   # so we check "Andrew DeFaria <Andrew@DeFaria.com>", which they have never
54   # forged. This catches a lot of spam actually.
55   #
56   # Next we check to see if the sender is on our whitelist. If so then we let
57   # them in. This allows us to say whitelist josephrosenberg@hotmail.com while
58   # still nulllisting all of the other hotmail.com spammers.
59   #
60   # Next we process blacklisted people as they are also of high priority.
61   #
62   # Then we process nulllist people.
63   #
64   # Finally, we handle return processing
65
66   # Check which list the sender is on. Note that these function calls return a
67   # list of scalars. But if we want to check to see that the first returned
68   # item is in the list we need to use a syntax of () = func(). If instead we
69   # just use if (func()) and func returns a list, then we will not see the first
70   # scalar returned as a boolen. Using () = func() does this for us.
71   if (() = OnWhitelist($sender, $username, 0)) {
72     display "Sender $sender would be whitelisted";
73   } elsif (() = OnBlacklist($sender, 0)) {
74     display "Sender $sender would be be blacklisted";
75   } elsif (() = OnNulllist($sender, 0)) {
76     display "Sender $sender would be nulllisted"
77   } else {
78     display "Sender $sender would be returned"
79   } # if 
80 } # for