From: Don Armstrong Date: Wed, 3 Sep 2025 21:41:29 +0000 (-0700) Subject: Enable $gCcAllmailsToAddr and switch to add_recipients in process X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=8ee85a33b580c4ce874c1d9ba8fff5b67f16efcd;p=debbugs.git Enable $gCcAllmailsToAddr and switch to add_recipients in process --- diff --git a/lib/Debbugs/Config.pm b/lib/Debbugs/Config.pm index bfddacc4..2a7cf842 100644 --- a/lib/Debbugs/Config.pm +++ b/lib/Debbugs/Config.pm @@ -80,6 +80,7 @@ BEGIN { qw($gTemplateDir), qw($gDefaultPackage), qw($gSpamMaxThreads $gSpamSpamsPerThread $gSpamKeepRunning $gSpamScan $gSpamCrossassassinDb), + qw($gCcAllMailsToAddr), qw($gDatabase), ], text => [qw($gBadEmailPrefix $gHTMLTail $gHTMLExpireNote), diff --git a/lib/Debbugs/Recipients.pm b/lib/Debbugs/Recipients.pm index 29b92f72..dc39a3a4 100644 --- a/lib/Debbugs/Recipients.pm +++ b/lib/Debbugs/Recipients.pm @@ -97,6 +97,9 @@ sub add_recipients { unknown_packages => {type => HASHREF, default => {}, }, + received_at_quiet => {type => SCALAR, + default => 0, + }, }, ); @@ -106,7 +109,7 @@ sub add_recipients { for my $data (@{$param{data}}) { add_recipients(data => $data, map {exists $param{$_}?($_,$param{$_}):()} - qw(recipients debug transcript actions_taken unknown_packages) + qw(recipients debug transcript actions_taken unknown_packages received_at_quiet) ); } return; @@ -136,7 +139,7 @@ sub add_recipients { ); } } - if (defined $param{data}{severity} and defined $config{strong_list} and + if (not $param{received_at_quiet} and defined $param{data}{severity} and defined $config{strong_list} and isstrongseverity($param{data}{severity})) { _add_address(recipients => $param{recipients}, address => "$config{strong_list}\@".$config{list_domain}, @@ -186,8 +189,8 @@ sub add_recipients { length $config{cc_all_mails_to_addr} ) { _add_address(recipients => $param{recipients}, - address => $config{cc_all_mails_to}, - reason => "cc_all_mails_to", + address => $config{cc_all_mails_to_addr}, + reason => "cc_all_mails_to_addr", bug_num => $param{data}{bug_num}, type => 'bcc', ); diff --git a/scripts/process b/scripts/process index e1364c5c..0a1d4ab2 100755 --- a/scripts/process +++ b/scripts/process @@ -32,7 +32,7 @@ use Debbugs::Config qw(:globals :config); use Debbugs::Control qw(append_action_to_log valid_usertag); use Debbugs::Control::Service qw(valid_control control_line); -use Debbugs::Recipients qw(determine_recipients); +use Debbugs::Recipients qw(add_recipients determine_recipients); use Encode qw(encode_utf8 decode); use List::AllUtils qw(first uniqnum); @@ -142,6 +142,7 @@ my @msg; close($log); } +my $veryquiet= $codeletter eq 'Q'; my $tdate = strftime "%a, %d %h %Y %T +0000", gmtime; my $fwd= "Received: via spool by $baddress\@$gEmailDomain id=$nn\n". @@ -152,14 +153,10 @@ my (@headerlines, @bodylines); # whether maintainer addresses have been checked our $maintainerschecked = 0; -#maintainer address for this message -our @maintaddrs; -# other src addresses -our @addsrcaddrs; -our @resentccs; -our @bccs; - +my @resentccs; my $resentccexplain=''; +# recipients for this message +my %recipients; # whether there's a new reference with this email our $newref = 0; @@ -374,7 +371,6 @@ if ($codeletter eq 'D' || $codeletter eq 'F') my $receivedat; my $markaswhat; my $set_forwarded; - my $generalcc; my $set_done; if ($codeletter eq 'F') { # Forwarded (appendlog($ref,$msg),finish()) if defined $data->{forwarded} and length($data->{forwarded}); @@ -387,10 +383,7 @@ if ($codeletter eq 'D' || $codeletter eq 'F') } if ( length( $gListDomain ) > 0 && length( $gForwardList ) > 0 ) { push @generalcc, "$gForwardList\@$gListDomain"; - $generalcc= "$gForwardList\@$gListDomain"; - } else { - $generalcc=''; - } + } } else { # Done if (defined $data->{done} and length($data->{done}) and not defined $pheader{'source-version'} and @@ -402,16 +395,9 @@ if ($codeletter eq 'D' || $codeletter eq 'F') $markaswhat= 'done'; $set_done= $pheader{'done'} // $header{'from'}; if ( length( $gListDomain ) > 0 && length( $gDoneList ) > 0 ) { - $generalcc= "$gDoneList\@$gListDomain"; push @generalcc, "$gDoneList\@$gListDomain"; - } else { - $generalcc=''; } } - if (defined $gStrongList and isstrongseverity($data->{severity})) { - $generalcc = join ', ', $generalcc, "$gStrongList\@$gListDomain"; - push @generalcc,"$gStrongList\@$gListDomain"; - } if ($ref<0) { &sendmessage(create_mime_message( [From => qq("$gProject $gBug Tracking System" <$gMaintainerEmail>), @@ -435,12 +421,12 @@ if ($codeletter eq 'D' || $codeletter eq 'F') finish(); } - &checkmaintainers; + add_recipients( + data => $data, + recipients => \%recipients, + received_at_quiet => $veryquiet, + ); - my @noticecc = grep($_ ne $replyto,@maintaddrs); - my $noticeccval.= join(', ', grep($_ ne $replyto,@maintaddrs)); - $noticeccval =~ s/\s+\n\s+/ /g; - $noticeccval =~ s/^\s+/ /; $noticeccval =~ s/\s+$//; my @process= ($ref,split(/ /,$data->{mergedwith})); my $orgref= $ref; @@ -481,18 +467,6 @@ if ($codeletter eq 'D' || $codeletter eq 'F') # Add bug mailing list to $generalbcc as appropriate # This array is used to specify bcc in the cases where we're using create_mime_message. - my @generalbcc = @generalcc; - if (defined $config{subscription_domain} and length $config{subscription_domain}) { - @generalbcc = (@generalbcc, @addsrcaddrs); - } - if (defined $config{bug_subscription_domain} and length $config{bug_subscription_domain}) { - @generalbcc = (@generalbcc, "bugs=$ref\@$config{bug_subscription_domain}"); - } - my $generalbcc = join(', ', @generalbcc); - $generalbcc =~ s/\s+\n\s+/ /g; - $generalbcc =~ s/^\s+/ /; $generalbcc =~ s/\s+$//; - if (length $generalbcc) {$generalbcc = "Bcc: $generalbcc\n"}; - writebug($ref, $data); my $hash = get_hashname($ref); @@ -526,7 +500,7 @@ if ($codeletter eq 'D' || $codeletter eq 'F') data => $data, }, ), - [join("\n",@msg)]),'',[$replyto,@generalbcc,@noticecc],1); + [join("\n",@msg)]),'',[$replyto,@generalcc,make_list(values %{{determine_recipients(recipients => \%recipients,address_only => 1)}})],1); } else { &htmllog("Reply","sent",$replyto,"You have taken responsibility."); &sendmessage(create_mime_message( @@ -552,7 +526,7 @@ if ($codeletter eq 'D' || $codeletter eq 'F') data => $data, }, ), - [$orig_report,join("\n",@msg)]),'',[$replyto,@generalbcc,@noticecc],1); + [$orig_report,join("\n",@msg)]),'',[$replyto,@generalcc, make_list(values %{{determine_recipients(recipients => \%recipients,address_only => 1)}})],1); &htmllog("Notification","sent",$data->{originator}, "$gBug acknowledged by developer."); &sendmessage(create_mime_message( @@ -649,9 +623,9 @@ if ($ref<0) { # new bug report } if (defined $config{default_package}) { - &checkmaintainers; # if there are no maintainers for this package, assign it to the default package - if (not @maintaddrs) { + my @maintainers = package_maintainers(package => $data->{package}); + if (not @maintainers) { $data->{package} = $config{default_package}; $brokenness.= fill_template('mail/process_default_package_selected', {old_package => $pheader{source} || $pheader{package} || 'No package', @@ -659,8 +633,12 @@ if ($ref<0) { # new bug report } ); # force the maintainers to be rechecked - $maintainerschecked = 0; - &checkmaintainers; + add_recipients( + data => $data, + recipients => \%recipients, + received_at_quiet => $veryquiet, + ); + } } @@ -705,6 +683,7 @@ if ($ref<0) { # new bug report $data->{subject} = $subject; $data->{msgid} = $header{'message-id'}; writebug($ref, $data); + $data->{bug_num} = $ref; # Deal with usertags my $current_user; unshift @usertag_bits, ['user', $replyto]; @@ -743,7 +722,19 @@ if ($ref<0) { # new bug report map {"$_\n"} @msg); } -&checkmaintainers; +add_recipients( + data => $data, + recipients => \%recipients, + received_at_quiet => $veryquiet, +); + +my @maintaddrs; +for my $p (splitpackages($data->{package})) { + for my $maint (package_maintainer(binary=>$p)) { + push @maintaddrs, get_addresses($maint); + } +} + print {$debugfh} "maintainers >".join(' ',@maintaddrs)."<\n"; @@ -766,16 +757,6 @@ if (@maintaddrs && ($codeletter eq 'B' || $codeletter eq 'M')) { ); } -@bccs = @addsrcaddrs; -if (defined $gStrongList and isstrongseverity($data->{severity})) { - push @bccs, "$gStrongList\@$gListDomain"; -} - -# Send mail to the per bug list subscription too -if (defined $config{bug_subscription_domain} and length $config{bug_subscription_domain}) { - push @bccs, "bugs=$ref\@$config{bug_subscription_domain}"; -} - if (defined $pheader{source}) { # Prefix source versions with the name of the source package. They # appear that way in version trees so that we can deal with binary @@ -815,7 +796,6 @@ if (defined $pheader{source}) { writebug($ref, $data); } -my $veryquiet= $codeletter eq 'Q'; if ($codeletter eq 'M' && !@maintaddrs) { $veryquiet= 1; $brokenness.= fill_template('mail/invalid_maintainer', @@ -859,11 +839,11 @@ ${references}${source_pr_header} END chomp $enc_msg; $enc_msg = encode_utf8($enc_msg).$fwd."\n"; - &sendmessage($enc_msg,[$data->{originator},@resentccs],[@bccs]); + &sendmessage($enc_msg,[$data->{originator},make_list(values %{{determine_recipients(recipients => \%recipients,address_only => 1)}})]); } elsif ($codeletter eq 'B') { # Sent to submit my $report_followup = $newref ? 'report' : 'followup'; &htmllog($newref ? "Report" : "Information", "forwarded", - join(', ',"$gSubmitList\@$gListDomain",@resentccs), + join(', ',"$gSubmitList\@$gListDomain",determine_recipients(recipients=>\%recipients,cc=>1)), "$gBug#$ref". (length($data->{package})? "; Package ".html_escape($data->{package})."" : ''). "."); @@ -882,8 +862,8 @@ ${references}${source_pr_header} END chomp $enc_msg; $enc_msg = encode_utf8($enc_msg).$fwd."\n"; - &sendmessage($enc_msg,["$gSubmitList\@$gListDomain",@resentccs],[@bccs]); -} elsif (@resentccs or @bccs) { # Quiet or Maintainer + &sendmessage($enc_msg,["$gSubmitList\@$gListDomain",make_list(values %{{determine_recipients(recipients => \%recipients,address_only => 1)}})]); +} else { # Quiet or Maintainer # D and F done far earlier; B just done - so this must be M or Q # We preserve whichever it was in the Reply-To (possibly adding # the $gBug#). @@ -916,7 +896,7 @@ ${references}${source_pr_header} END chomp $enc_msg; $enc_msg = encode_utf8($enc_msg).$fwd."\n"; - &sendmessage($enc_msg,[@resentccs],[@bccs]); + &sendmessage($enc_msg,[make_list(values %{{determine_recipients(recipients => \%recipients,address_only => 1)}})]); } my $htmlbreak= length($brokenness) ? "

\n".html_escape($brokenness)."\n

\n" : ''; @@ -1303,54 +1283,6 @@ sub fill_template{ } -# this shole routine is *bad*; will be changed to use -# Debbugs::Recipients and stuff therin in short order. -sub checkmaintainers { - return if $maintainerschecked++; - return if !length($data->{package}); - - my $anymaintfound=0; my $anymaintnotfound=0; - for my $p (splitpackages($data->{package})) { - $p =~ y/A-Z/a-z/; - $p =~ /((?:src:)?[a-z0-9.+-]+)/; - $p = $1; - next unless defined $p; - if (defined $config{subscription_domain} and length $config{subscription_domain}) { - my @source = binary_to_source(binary => $p, - source_only => 1, - ); - if (@source) { - push @addsrcaddrs, - map {"$_\@$config{subscription_domain}"} @source; - } else { - push @addsrcaddrs, "$p\@$config{subscription_domain}"; - } - } - # this is utter hackery until we switch to Debbugs::Recipients - my @maints = package_maintainer(binary => $p); - if (@maints) { - print {$debugfh} "maintainer add >$p|".join(',',@maints)."<\n"; - my %temp; - @temp{@maintaddrs} = @maintaddrs; - push(@maintaddrs, - grep {$_ ne $replyto and - not exists $temp{$_}} @maints); - $anymaintfound++; - } else { - print {$debugfh} "maintainer none >$p<\n"; - push(@maintaddrs,$gUnknownMaintainerEmail) unless $anymaintnotfound; - $anymaintnotfound++; - last; - } - } - - if (defined $data->{owner} and length $data->{owner}) { - print {$debugfh} "owner add >$data->{package}|$data->{owner}<\n"; - my $addmaint = $data->{owner}; - push(@maintaddrs, $addmaint) unless - $addmaint eq $replyto or grep($_ eq $addmaint, @maintaddrs); - } -} =head2 bug_list_forward diff --git a/t/23_cc_all_mails.t b/t/23_cc_all_mails.t new file mode 100644 index 00000000..630cfc07 --- /dev/null +++ b/t/23_cc_all_mails.t @@ -0,0 +1,110 @@ +# -*- mode: cperl;-*- + +use Test::More tests => 4; + +use warnings; +use strict; + +# Here, we're going to shoot messages through a set of things that can +# happen. + +# First, we're going to send mesages to receive. +# To do so, we'll first send a message to submit, +# then send messages to the newly created bugnumber. + +use IO::File; +use File::Temp qw(tempdir); +use Cwd qw(getcwd); +use Debbugs::MIME qw(create_mime_message); +use File::Basename qw(dirname basename); + +# The test functions are placed here to make things easier +use lib qw(t/lib); +use DebbugsTest qw(:all); +use Data::Dumper; +use Encode qw(decode encode); + +# HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here. +$SIG{CHLD} = sub { }; +my %config = create_debbugs_configuration( additional_debbugs_config => + qq(\$gCcAllMailsToAddr='cc_addr\@example.com';\n) ); + +my $sendmail_dir = $config{sendmail_dir}; +my $spool_dir = $config{spool_dir}; +my $config_dir = $config{config_dir}; + +# We're going to use create mime message to create these messages, and +# then just send them to receive. + +send_message( + to => 'submit@bugs.something', + headers => [ + To => 'submit@bugs.something', + From => 'foo@bugs.something', + Subject => 'Submiting a bug', + ], + body => < '1@bugs.something', + headers => [ + To => '1@bugs.something', + From => 'foo@bugs.something', + Subject => 'Sending a message to a bug', + ], + body => < 'control@bugs.something', + headers => [ + To => 'control@bugs.something', + From => 'foo@bugs.something', + Subject => 'Munging a bug', + ], + body => < {type => BOOLEAN, optional => 1, }, + additional_debbugs_config => {type => SCALAR, + default => '', + }, }, ); $param{cleanup} = $param{debug}?0:1 if not exists $param{cleanup}; @@ -92,6 +95,7 @@ sub create_debbugs_configuration { \$gTemplateDir='@{[getcwd()]}/templates'; \$gWebDir='@{[getcwd()]}/html'; \$gWebHost='localhost'; +$param{additional_debbugs_config} 1; END "$spool_dir/nextnumber" => qq(1\n),