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);
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".
# 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;
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});
}
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
$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>),
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;
# 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);
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(
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(
}
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',
}
);
# force the maintainers to be rechecked
- $maintainerschecked = 0;
- &checkmaintainers;
+ add_recipients(
+ data => $data,
+ recipients => \%recipients,
+ received_at_quiet => $veryquiet,
+ );
+
}
}
$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];
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";
);
}
-@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
writebug($ref, $data);
}
-my $veryquiet= $codeletter eq 'Q';
if ($codeletter eq 'M' && !@maintaddrs) {
$veryquiet= 1;
$brokenness.= fill_template('mail/invalid_maintainer',
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>" : '').
".");
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#).
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" : '';
}
-# 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
--- /dev/null
+# -*- 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' );
+