# 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.
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;
[[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],
],
# 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
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;
}
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