Revise exclude_mail_blacklist
authorJacob Bachmeyer <jcb@gnu.org>
Fri, 28 Oct 2022 23:37:48 +0000 (18:37 -0500)
committerJacob Bachmeyer <jcb@gnu.org>
Fri, 28 Oct 2022 23:37:48 +0000 (18:37 -0500)
gatekeeper.pl

index 3011c77ba7b11d897844545cf290331534a7b31e..2999438c0f62fab89997bbd04a4ac91b9f8fcd2f 100755 (executable)
@@ -985,23 +985,30 @@ END
 # - Email
 #
 
+=item @filtered = exclude_mail_blacklist ( $blacklist_file, @addresses )
+
+Filter ADDRESSES to remove addresses mentioned in BLACKLIST_FILE.
+
+=cut
+
 sub exclude_mail_blacklist {
-    my @emaillist = @_;
-    my @blacklist = ();
-    my @tomail = @emaillist;
-    if (-f $email_blacklist) {
-       open(BLACKLIST, "<$email_blacklist");
-       @blacklist = <BLACKLIST>;
-       close(BLACKLIST);
-       chomp(@blacklist);
-
-       my %blacklist = map{$_ => 1 } @blacklist;
-       my %emaillist = map{$_ => 1 } @emaillist;
-
-       @tomail = grep(!defined $blacklist{$_}, @emaillist);
-    }
+  my $blacklist_file = shift;
+  my @emaillist = @_;
+
+  local *_;
+  my %blacklist;
+
+  my @filtered = @emaillist;
+  if (-f $blacklist_file) {
+    open BLACKLIST, '<', $blacklist_file
+      or ftp_abort("open($blacklist_file) failed: $!");
+    while (<BLACKLIST>) { chomp; $blacklist{$_}++ }
+    close BLACKLIST or ftp_abort("close($blacklist_file) failed: $!");
+
+    @filtered = grep !$blacklist{$_}, @emaillist;
+  }
 
-    return @tomail;
+  return @filtered;
 }
 
 # Used for both success and failure.
@@ -1043,7 +1050,7 @@ sub mail {
   $sender = 'ftp-upload@gnu.org'
     if ($send_to_user); # We really want replies to go to the ftp-upload queue
 
-  @email_list = exclude_mail_blacklist(@email_list);
+  @email_list = exclude_mail_blacklist($email_blacklist, @email_list);
 
   #print STDERR "final emails: @email_list\n";
   # return @_;