From dd26c7cbfb7818e740d8acadbd43e6f066acd098 Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Wed, 16 Nov 2022 21:11:16 -0600 Subject: [PATCH] Revise mail to remove use of quasi-global %info hash --- gatekeeper.pl | 57 +++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/gatekeeper.pl b/gatekeeper.pl index 9f804e9..fa71747 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -1398,27 +1398,30 @@ sub sendmail { # Used for both success and failure. # + +=item mail $message, [ to => \@addresses ], [ subject => $subject ] + +Send MESSAGE to ADDRESSES or the internal reporting inbox if ADDRESSES is +not given. + +=cut + sub mail { my $msg = shift; - my $send_to_user = shift; - my $subject = shift; - $subject ||= ''; + my %args = @_; + + $args{subject} = 'generic failure' unless $args{subject}; our $Internal_Report_Inbox; my @email_list = ($Internal_Report_Inbox); # Some messages should be sent to the user, some should not - push (@email_list, @{$info{email}}) - if (defined $info{email} && $send_to_user); - - # If this is an e-mail to the uploader, don't send it to the script - # maintainer. - shift(@email_list) if ($send_to_user); + @email_list = @{$args{to}} if defined $args{to}; # At minimum, an Internet email address must contain an @ character. @email_list = grep m/@/, @email_list; - if ($#email_list == -1) { + unless (@email_list) { # Something went wrong, but we can't figure out which package this # upload belongs to. Mention that in the logs, and then mail this to # the script maintainer anyway. @@ -1429,20 +1432,11 @@ sub mail { my $sender = 'ftp-upload-script@gnu.org'; $sender = 'ftp-upload@gnu.org' - if ($send_to_user); # We really want replies to go to the ftp-upload queue + if defined $args{to}; # We really want replies to go to the ftp-upload queue @email_list = exclude_mail_blacklist($email_blacklist, @email_list); - #print STDERR "final emails: @email_list\n"; - # return @_; - - if ($subject ne '') { - $subject = "[$zone_tag gnu-ftp-upload] $subject"; - } elsif (defined $info{package}) { - $subject = "[$zone_tag gnu-ftp-upload] $info{package}"; - } else { - $subject = "[$zone_tag gnu-ftp-upload] generic failure"; - } + $args{subject} = "[$zone_tag gnu-ftp-upload] $args{subject}"; # Wrap message at 78 characters, this is e-mail... local $Text::Wrap::columns = 78; @@ -1452,7 +1446,7 @@ sub mail { [[To => join ', ', @email_list], [From => $sender], [Date => strftime("%a, %e %b %Y %H:%M:%S %z", localtime)], - [Subject => $subject], + [Subject => $args{subject}], ['Reply-To' => 'ftp-upload@gnu.org'], ['Message-ID'=> Email::MessageID->new->in_brackets], ], @@ -2771,13 +2765,15 @@ foreach my $packet (@packets) { # each list element is an array reference # report success if ($directive_only) { - mail("processing of $directive_file complete",1); + mail "processing of $directive_file complete", + to => \@email_addresses, subject => $op_header->{package}; } else { my @messages = ("upload of $upload_file and $sig_file complete"); unshift @messages, @{$op_header->{notices}}, '' if $op_header->{notices}; # The "notices" key in the oplist header is a kludge, but seems to be # the best immediate step to only send mail during the report phase. - mail(join("\n", @messages),1); + mail join("\n", @messages), + to => \@email_addresses, subject => $op_header->{package}; } # unlink the directive file @@ -2791,7 +2787,7 @@ foreach my $packet (@packets) { # each list element is an array reference unless ($oplist) { # The directive text is emailed immediately after $oplist is set, # so if $oplist is not set, then we still need to send it. Do so now. - mail($directive_text,0,'debug: directive file contents') + mail $directive_text, subject => 'debug: directive file contents' if $directive_text && DEBUG; } @@ -2804,15 +2800,18 @@ foreach my $packet (@packets) { # each list element is an array reference push @email_addresses, directory_email_addresses($E->directory) if $E->directory; @{$info{email}} = @email_addresses; - mail(join("\n",$E->summary,'',$E->trace_msg),1); + mail join("\n",$E->summary,'',$E->trace_msg), + to => \@email_addresses, subject => $op_header->{package}; } elsif ($E->type_p('package_configuration')) { - mail($E->summary,0); + mail $E->summary; } elsif ($E->type_p('signature_error') || $E->type_p('processing_error')) { - mail($E->summary,1); + mail $E->summary, + to => \@email_addresses, subject => $op_header->{package}; } elsif (UNIVERSAL::can($E, 'message')) { # catch-all for exceptions carrying long-form messages - mail($E->message,1); + mail $E->message, + to => \@email_addresses, subject => $op_header->{package}; } } else { # Exceptions thrown by perl itself come out as strings, as do simple -- 2.25.1