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