]> git.donarmstrong.com Git - debbugs.git/commitdiff
Enable $gCcAllmailsToAddr and switch to add_recipients in process
authorDon Armstrong <don@donarmstrong.com>
Thu, 4 Sep 2025 00:02:57 +0000 (17:02 -0700)
committerDon Armstrong <don@donarmstrong.com>
Thu, 4 Sep 2025 00:02:57 +0000 (17:02 -0700)
Debbugs/Config.pm
Debbugs/Recipients.pm
scripts/process
t/23_cc_all_mails.t [new file with mode: 0644]
t/lib/DebbugsTest.pm

index 5b650369cdc29d9a992ada8a84d02233c1cfdb72..812e265ee0ab7b6491b931c051b51d072ba3b2b8 100644 (file)
@@ -76,6 +76,7 @@ BEGIN {
                                 qw($gTemplateDir),
                                 qw($gDefaultPackage),
                                 qw($gSpamMaxThreads $gSpamSpamsPerThread $gSpamKeepRunning $gSpamRulesDir $gSpamCrossassassinDb),
+                                qw($gCcAllMailsToAddr),
                                ],
                     text     => [qw($gBadEmailPrefix $gHTMLTail $gHTMLExpireNote),
                                 ],
index 29b92f72a343d3626126205aad4b3de17b4df14f..dc39a3a4fdaf9c7d7e99a9f8a0b5be5226c4c9e6 100644 (file)
@@ -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',
                     );
index e5bba624fb938d92a84df898b56a27671035b73a..883c51240f94ddd3e77e60d193264a19f6d02911 100755 (executable)
@@ -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);
 
 =head1 NAME
@@ -141,6 +141,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".
@@ -151,14 +152,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;
@@ -373,7 +370,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});
@@ -386,10 +382,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
@@ -401,16 +394,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>),
@@ -434,12 +420,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;
@@ -480,18 +466,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);
@@ -525,7 +499,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(
@@ -551,7 +525,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(
@@ -648,9 +622,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',
@@ -658,8 +632,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,
+              );
+
         }
     }
 
@@ -704,6 +682,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 = $replyto;
     for my $field (@usertag_bits) {
@@ -741,7 +720,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";
 
@@ -764,16 +755,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
@@ -813,7 +794,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',
@@ -857,11 +837,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)),
              "<code>$gBug#$ref</code>".
              (length($data->{package})? "; Package <code>".html_escape($data->{package})."</code>" : '').
              ".");
@@ -880,8 +860,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#).
@@ -914,7 +894,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) ? "<p>\n".html_escape($brokenness)."\n<p>\n" : '';
@@ -1306,54 +1286,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 (file)
index 0000000..630cfc0
--- /dev/null
@@ -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 => <<EOF ) or fail('Unable to send message');
+Package: foo
+Severity: normal
+
+This is a silly bug
+EOF
+
+# next, we check to see that (at least) the proper messages have been
+# sent out. 1) ack to submitter 2) mail to maintainer 3) mail to cc
+
+# This keeps track of the previous size of the sendmail directory
+my $SD_SIZE = 0;
+$SD_SIZE =
+  num_messages_sent( $SD_SIZE, 2, $sendmail_dir,
+    'submit messages appear to have been sent out properly',
+  );
+
+# Validate that a message has been sent to cc_addr@example.com
+ok(
+    system( 'sh', '-c',
+            'find '
+          . $sendmail_dir
+          . q( -type f | xargs grep -q "called with:.*'cc_addr@example.com'") )
+      == 0,
+    'Message sent to cc_addr@example.com'
+);
+
+# now send a message to the bug
+
+send_message(
+    to      => '1@bugs.something',
+    headers => [
+        To      => '1@bugs.something',
+        From    => 'foo@bugs.something',
+        Subject => 'Sending a message to a bug',
+    ],
+    body => <<EOF ) or fail('sending message to 1@bugs.someting failed');
+Package: foo
+Severity: normal
+
+This is a silly bug
+EOF
+
+$SD_SIZE =
+  num_messages_sent( $SD_SIZE, 2, $sendmail_dir,
+    '1@bugs.something messages appear to have been sent out properly' );
+
+# just check to see that control doesn't explode
+send_message(
+    to      => 'control@bugs.something',
+    headers => [
+        To      => 'control@bugs.something',
+        From    => 'foo@bugs.something',
+        Subject => 'Munging a bug',
+    ],
+    body => <<EOF ) or fail 'message to control@bugs.something failed';
+severity 1 wishlist
+retitle 1 new title
+thanks
+EOF
+
+$SD_SIZE =
+  num_messages_sent( $SD_SIZE, 1, $sendmail_dir,
+    'control@bugs.something messages appear to have been sent out properly' );
+
index 1fa4a8458e1760c5341241850afc2c1f401fe93d..34a4115a4b643ee1b65c13001e25c65a7a29e6cd 100644 (file)
@@ -64,6 +64,9 @@ sub create_debbugs_configuration {
                                          cleanup => {type => BOOLEAN,
                                                      optional => 1,
                                                     },
+                                         additional_debbugs_config => {type => SCALAR,
+                                                                       default => '',
+                                                                      },
                                         },
                              );
      $param{cleanup} = $param{debug}?0:1 if not exists $param{cleanup};
@@ -87,6 +90,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),