Finally allowed "username@domain.com" to be specified
[clearscm.git] / maps / bin / add2nulllist.cgi
1 #!/usr/bin/perl
2 ################################################################################
3 #
4 # File:         $RCSfile: add2nulllist.cgi,v $
5 # Revision:     $Revision: 1.1 $
6 # Description:  Add an email address to the nulllist
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 $0 = $FindBin::Script;
20
21 use lib "$FindBin::Bin/../lib";
22
23 use MAPS;
24 use MAPSLog;
25 use MAPSWeb;
26 use MAPSUtil;
27
28 use CGI qw/:standard *table/;
29 use CGI::Carp 'fatalsToBrowser';
30
31 my $userid;
32 my $Userid;
33 my $type = 'null';
34
35 sub Add2List() {
36   my $sender   = '';
37   my $nextseq  = GetNextSequenceNo($userid, $type);
38
39   while () {
40     my $pattern   = param "pattern$nextseq";
41     my $domain    = param "domain$nextseq";
42     my $comment   = param "comment$nextseq";
43     my $hit_count = param "hit_count$nextseq";
44
45     last if ((!defined $pattern || $pattern eq '') &&
46               (!defined $domain || $domain  eq ''));
47
48     $sender = CheckEmail $pattern, $domain;
49
50     my ($status, $rule) = OnNulllist($sender);
51
52     if ($status != 0) {
53       print br {-class => 'error'}, "The email address $sender is already on ${Userid}'s $type list";
54     } else {
55       $hit_count ||= CountMsg($sender);
56
57       Add2Nulllist($sender, $userid, $comment, $hit_count);
58
59       print br "The email address, $sender, has been added to ${Userid}'s $type list";
60
61       # Now remove this entry from the other lists (if present)
62       for my $otherlist ('white', 'black') {
63         my $sth = FindList $otherlist, $sender;
64         my ($sequence, $count);
65
66         ($_, $_, $_, $_, $_, $sequence) = GetList($sth);
67
68         if ($sequence) {
69           $count = DeleteList($otherlist, $sequence);
70
71           print br "Removed $sender from ${Userid}'s " . ucfirst $otherlist . ' list'
72             if $count > 0;
73
74           ResequenceList($userid, $otherlist);
75         } # if
76       } # for
77     } # if
78
79     $nextseq++;
80   } # while
81 } # Add2List
82
83 # Main
84 $userid = Heading(
85   'getcookie',
86   '',
87   'Add to Null List',
88   'Add to Null List',
89 );
90
91 SetContext($userid);
92
93 NavigationBar($userid);
94
95 $Userid = ucfirst $userid;
96
97 Add2List;
98
99 print start_form {
100   -method => 'post',
101   -action => 'processaction.cgi',
102   -name   => 'list'
103 };
104
105 print '<p></p><center>',
106   hidden ({-name    => 'type',
107            -default => $type}),
108   submit ({-name    => 'action',
109            -value   => 'Add'}),
110   '</center>';
111
112 Footing;
113
114 exit;