1 # This module is part of debbugs, and is released
2 # under the terms of the GPL version 2, or any later version. See the
3 # file README and COPYING for more information.
4 # Copyright 2008 by Don Armstrong <don@donarmstrong.com>.
5 # $Id: perl_module_header.pm 1221 2008-05-19 15:00:40Z don $
7 package Debbugs::Recipients;
11 Debbugs::Recipients -- Determine recipients of messages from the bts
27 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT);
28 use base qw(Exporter);
31 ($VERSION) = q$Revision: 1221 $ =~ /^Revision:\s+([^\s+])/;
32 $DEBUG = 0 unless defined $DEBUG;
35 %EXPORT_TAGS = (add => [qw(add_recipients)],
36 det => [qw(determine_recipients)],
39 Exporter::export_ok_tags(keys %EXPORT_TAGS);
40 $EXPORT_TAGS{all} = [@EXPORT_OK];
44 use Debbugs::Config qw(:config);
48 add_recipients(data => $data,
49 recipients => \%recipients;
52 Given data (from read_bug or similar) (or an arrayref of data),
53 calculates the addresses which need to receive mail involving this
58 =item data -- Data from read_bug or similar; can be an arrayref of data
60 =item recipients -- hashref of recipient data structure; pass to
61 subsequent calls of add_recipients or
63 =item debug -- optional
73 # maintainer email address &c -> assoc of packages -> assoc of bug#'s
74 my %param = validate_with(params => \@_,
75 spec => {data => {type => HASHREF|ARRAYREF,
77 recipients => {type => HASHREF,
79 debug => {type => HANDLE|SCALARREF,
84 if (ref ($param{data}) eq 'ARRAY') {
85 for (@{$param{data}}) {
86 add_recipients(map {exists $param{$_}?:($_,$param{$_}):()}
92 my $anymaintfound=0; my $anymaintnotfound=0;
93 for my $p (splitpackages($param{data}{package})) {
95 if (defined $config{subscription_domain}) {
96 my @source_packages = binarytosource($p);
97 if (@source_packages) {
98 for my $source (@source_packages) {
99 _add_address(recipients => $param{recipients},
100 address => "$source\@".$config{subscription_domain},
107 _add_address(recipients => $param{recipients},
108 address => "$p\@".$config{subscription_domain},
114 if (defined $param{data}{severity} and defined $config{strong_list} and
115 isstrongseverity($param{data}{severity})) {
116 _add_address(recipients => $param{recipients},
117 address => "$config{strong_list}\@".$config{list_domain},
118 reason => $param{data}{severity},
122 if (defined(getmaintainers->{$p})) {
123 $addmaint= getmaintainers->{$p};
124 print {$transcript} "MR|$addmaint|$p|$ref|\n" if $dl>2;
125 _add_address(recipients => $param{recipients},
126 address => $addmaint,
128 bug_num => $param{data}{bug_num},
131 print "maintainer add >$p|$addmaint<\n" if $debug;
134 print "maintainer none >$p<\n" if $debug;
135 print {$transcript} "Warning: Unknown package '$p'\n";
136 print {$transcript} "MR|unknown-package|$p|$ref|\n" if $dl>2;
137 _add_address(recipients => $param{recipients},
138 address => $config{unknown_maintainer_email},
140 bug_num => $param{data}{bug_num},
143 if defined $config{unknown_maintainer_email} and
144 length $config{unknown_maintainer_email};
147 if (defined $config{bug_subscription_domain} and
148 length $config{bug_subscription_domain}) {
149 _add_address(recipients => $param{recipients},
150 address => 'bug='.$param{data}{bug_num}.'@'.
151 $config{bug_subscription_domain},
152 reason => "bug $param{data}{bug_num}",
153 bug_num => $param{data}{bug_num},
158 if (length $param{data}{owner}) {
159 $addmaint = $param{data}{owner};
160 print {$transcript} "MO|$addmaint|$param{data}{package}|$ref|\n" if $dl>2;
161 _add_address(recipients => $param{recipients},
162 address => $addmaint,
163 reason => "owner of $param{data}{bug_num}",
164 bug_num => $param{data}{bug_num},
167 print "owner add >$param{data}{package}|$addmaint<\n" if $debug;
171 =head1 PRIVATE FUNCTIONS
175 _add_address(recipients => $param{recipients},
176 address => $addmaint,
177 reason => $param{data}{package},
178 bug_num => $param{data}{bug_num},
187 my %param = validate_with(params => \@_,
188 spec => {recipients => {type => HASHREF,
190 bug_num => {type => SCALAR,
194 reason => {type => SCALAR,
197 address => {type => SCALAR|ARRAYREF,
199 type => {type => SCALAR,
205 for my $addr (make_list($param{address})) {
206 if (lc($param{type}) eq 'bcc' and
207 exists $param{recipients}{$addr}{$param{reason}}{$param{bug_num}}
211 $param{recipients}{$addr}{$param{reason}}{$param{bug_num}} = $param{type};