a1b0d5e8532bef32df81f397d0e1bf12b358c9a4
[clearscm.git] / maps / bin / checkaddress.cgi
1 #!/usr/bin/perl
2 ################################################################################
3 #
4 # File:         $RCSfile: checkaddress.cgi,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 local $0 = $FindBin::Script;
20
21 use lib "$FindBin::Bin/../lib";
22 use lib "$FindBin::Bin/../../lib";
23
24 use MAPS;
25
26 use CGI qw(:standard);
27
28 # Get MAPSUser from cookie
29 my $userid;
30
31 if (param "user") {
32   $userid = param 'user';
33 } else {
34   $userid = cookie 'MAPSUser';
35 } # if
36
37 $userid //= $ENV{USER};
38
39 my $sender = param 'sender';
40
41 sub formatRule($$$) {
42   my ($list, $email_on_file, $rec) = @_;
43
44   my $next  = $rec->{sequence} - 1;
45   my $rule  = "Rule: $email_on_file (";
46      $rule .= a {
47        -href   => "/maps/php/list.php?type=$list&next=$next",
48        -target => '_blank',
49      }, "$list:$rec->{sequence}";
50      $rule .= ')' . br;
51
52      if ($rec->{retention}) {
53        $rule .= "Retention: " . $rec->{retention} . br;
54      } # if
55
56      if ($rec->{comment}) {
57        $rule .= "Comment: " . $rec->{comment};
58      } # if
59
60   return $rule;
61 } # formatRule
62
63 sub Heading() {
64   print
65     header     (-title  => "MAPS: Check Address"),
66     start_html (-title  => "MAPS: Check Address",
67                 -author => "Andrew\@DeFaria.com");
68     print h3 {-align => "center",
69               -class => "header"},
70     "MAPS: Checking address $sender";
71
72   return;
73 } # Heading
74
75 sub Body() {
76   my ($onlist, $rec);
77
78   # Algorithm change: We now first check to see if the sender is not found
79   # in the message and skip it if so. Then we handle if we are the sender
80   # and that the from address is formatted properly. Spammers often use 
81   # the senders email address (i.e. andrew@defaria.com) as their from address
82   # so we check "Andrew DeFaria <Andrew@DeFaria.com>", which they have never
83   # forged. This catches a lot of spam actually.
84   #
85   # Next we check to see if the sender is on our whitelist. If so then we let
86   # them in. This allows us to say whitelist josephrosenberg@hotmail.com while
87   # still nulllisting all of the other hotmail.com spammers.
88   #
89   # Next we process blacklisted people as they are also of high priority.
90   #
91   # Then we process nulllist people.
92   #
93   # Finally, we handle return processing
94
95   # Some email addresses have a '+' in them (e.g. 
96   # wipro+autoreply@talent.icims.com). The problem is that CGI.pm replaces the
97   # '+' with a space. Now email addresses cannot contain spaces so we're gonna
98   # assume that a space in the email should be a '+'.
99   $sender =~ s/\s/\+/g;
100
101   ($onlist, $rec) = OnWhitelist($sender, $userid, 0);
102
103   if ($onlist) {
104     print div {-align => "center"},
105       font {-color => "green"},
106         "Messages from", b ($sender), "will be", b ("delivered"), br, hr;
107     print formatRule('white', $sender, $rec);
108   } else {
109     ($onlist, $rec) = OnBlacklist($sender, 0);
110
111     if ($onlist) {
112       print div {-align => "center"},
113            font {-color => "black"},
114             "Messages from", b ($sender), "will be", b ("blacklisted"), br, hr;
115       print formatRule('black', $sender, $rec);
116     } else {
117       ($onlist, $rec) = OnNulllist($sender, 0);
118
119       if ($onlist) {
120         print div {-align => "center"},
121              font {-color => "grey"},
122             "Messages from", b ($sender), "will be", b ("discarded"), br, hr;
123         print formatRule('null', $sender, $rec);
124       } else {
125         print div {-align => "center"},
126              font {-color => "red"},
127             "Messages from", b ($sender), "will be", b ("returned");
128       } # if
129     } # if
130   } # if
131
132   print br div {-align => "center"},
133     submit(-name      => "submit",
134            -value     => "Close",
135            -onClick   => "window.close (self)");
136
137   return;
138 } # Body
139
140 sub Footing() {
141   print end_html;
142
143   return;
144 } # Footing
145
146 # Main
147 SetContext($userid);
148 Heading;
149 Body;
150 Footing;
151
152 exit;
153