]> git.donarmstrong.com Git - debbugs.git/commitdiff
Enable $gCcAllmailsToAddr and switch to add_recipients in process
authorDon Armstrong <don@donarmstrong.com>
Wed, 3 Sep 2025 21:41:29 +0000 (14:41 -0700)
committerDon Armstrong <don@donarmstrong.com>
Wed, 3 Sep 2025 21:44:07 +0000 (14:44 -0700)
lib/Debbugs/Config.pm
lib/Debbugs/Recipients.pm
scripts/process
t/23_cc_all_mails.t [new file with mode: 0644]
t/lib/DebbugsTest.pm

index bfddacc4e4dec657dda4fc3b8d0e511ca41c1115..2a7cf8420b9cd986bbcdba0e201b2d3e1d8f4048 100644 (file)
@@ -80,6 +80,7 @@ BEGIN {
                                 qw($gTemplateDir),
                                 qw($gDefaultPackage),
                                 qw($gSpamMaxThreads $gSpamSpamsPerThread $gSpamKeepRunning $gSpamScan $gSpamCrossassassinDb),
+                                qw($gCcAllMailsToAddr),
                                  qw($gDatabase),
                                ],
                     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 e1364c5ce3a51ca0c908c01642604ad9f53a86a1..0a1d4ab2a2b3684abdc50dacf3304ecb47500394 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);
 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)),
              "<code>$gBug#$ref</code>".
              (length($data->{package})? "; Package <code>".html_escape($data->{package})."</code>" : '').
              ".");
@@ -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) ? "<p>\n".html_escape($brokenness)."\n<p>\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 (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 463b710b326cee164a2685beba5e24ac486642d4..64802668f98a6cd3ea2d7925d6fda0babf56ccbe 100644 (file)
@@ -69,6 +69,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};
@@ -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),