5 =head1 NAME $RCSfile: importlist.cgi,v $
7 Imports a white, black or null list into MAPS
15 Andrew DeFaria <Andrew@DeFaria.com>
23 Mon Jan 16 20:25:32 PST 2006
27 $Date: 2019/04/04 13:40:10 $
33 Usage; importlist.cgi [-usa|ge] [-h|elp] [-v|erbose] [-de|bug]
34 [-type <white|black|null>] [-file <filename>]
37 -usa|ge Print this usage
39 -v|erbose Verbose mode (Default: Not verbose)
40 -de|bug Turn on debugging (Default: Off)
42 -t|ype Type of list - white, black or null
47 This script will import list entries from a list file for white, black or null
48 lists. Normally this script is run from the Import List button.
56 local $0 = $FindBin::Script;
58 use lib "$FindBin::Bin/../lib";
67 use CGI qw/:standard *table/;
68 use CGI::Carp "fatalsToBrowser";
70 my ($userid, $Userid);
73 usage => sub { pod2usage },
74 help => sub { pod2usage(-verbose => 2)},
75 verbose => sub { set_verbose },
76 debug => sub { set_debug },
79 $opts{type} = param 'type';
80 $opts{file} = param 'filename';
82 die "File not specified" unless $opts{file};
85 my ($list, $type) = @_;
97 my ($sender, $comment, $hit_count, $last_hit, $retention) = split /,/;
101 # The code for checking if a sender is on a list does not expect the $sender
103 my $cleansedSender = $sender;
105 $cleansedSender =~ s/(\^|\+)//g;
107 # TODO: While this works well for real email addresses it does not handle
108 # our regexes. True it can weed out some duplicates where a more specific
109 # email address is already covered by a more general regex. For example,
110 # I may have say andrew@someplace.ru in a null list but also have say
111 # ".*\.ru$" which covers andrew@someplace.ru. Using On<List>list functions
112 # will always see ".*\.ru$" as nonexistant and readd it.
113 if ($type eq 'white') {
114 ($alreadyExists) = OnWhitelist($cleansedSender, $userid);
115 } elsif ($type eq 'black') {
116 ($alreadyExists) = OnBlacklist($cleansedSender, $userid);
117 } elsif ($type eq 'null') {
118 ($alreadyExists) = OnNulllist($cleansedSender, $userid);
121 unless ($alreadyExists) {
122 # Some senders lack '@' as they are username only senders. But AddList
123 # complains if there is no '@'. For such senders tack on a '@'n
124 if ($sender !~ /\@/) {
134 hit_count => $hit_count,
135 last_hit => $last_hit,
136 retention => $retention,
139 print "Added $sender to ${Userid}'s ${type}list<br>";
140 push @output, "Added $sender to ${Userid}'s ${type}list<br>";
144 push @output, "$sender is already on your " . ucfirst($type) . 'list<br>';
148 print $_ for @output;
164 pod2usage 'Type not specified' unless $opts{type};
165 pod2usage 'File not specified' unless $opts{file};
167 # Now let's see if we can get that file
168 my $list = upload('filename');
170 #pod2usage "Unable to read $opts{file}" unless -r $opts{file};
179 $userid //= $ENV{USER};
180 $Userid = ucfirst $userid;
184 NavigationBar($userid);
186 my $count = importList($list, $opts{type});
189 print br "$count list entry imported";
190 } elsif ($count == 0) {
191 print br 'No entries imported';
193 print br "$count list entries imported";