/usr/share/perl5/Debbugs/Recipients.pm is in libdebbugs-perl 2.6.0.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | # This module is part of debbugs, and is released
# under the terms of the GPL version 2, or any later version. See the
# file README and COPYING for more information.
# Copyright 2008 by Don Armstrong <don@donarmstrong.com>.
# $Id: perl_module_header.pm 1221 2008-05-19 15:00:40Z don $
package Debbugs::Recipients;
=head1 NAME
Debbugs::Recipients -- Determine recipients of messages from the bts
=head1 SYNOPSIS
=head1 DESCRIPTION
=head1 BUGS
None known.
=cut
use warnings;
use strict;
use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT);
use Exporter qw(import);
BEGIN{
($VERSION) = q$Revision: 1221 $ =~ /^Revision:\s+([^\s+])/;
$DEBUG = 0 unless defined $DEBUG;
@EXPORT = ();
%EXPORT_TAGS = (add => [qw(add_recipients)],
det => [qw(determine_recipients)],
);
@EXPORT_OK = ();
Exporter::export_ok_tags(keys %EXPORT_TAGS);
$EXPORT_TAGS{all} = [@EXPORT_OK];
}
use Debbugs::Config qw(:config);
use Params::Validate qw(:types validate_with);
use Debbugs::Common qw(:misc :util);
use Debbugs::Status qw(splitpackages isstrongseverity);
use Debbugs::Packages qw(binary_to_source);
use Debbugs::Mail qw(get_addresses);
use Carp;
=head2 add_recipients
add_recipients(data => $data,
recipients => \%recipients;
);
Given data (from read_bug or similar) (or an arrayref of data),
calculates the addresses which need to receive mail involving this
bug.
=over
=item data -- Data from read_bug or similar; can be an arrayref of data
=item recipients -- hashref of recipient data structure; pass to
subsequent calls of add_recipients or
=item debug -- optional
=back
=cut
sub add_recipients {
# Data structure is:
# maintainer email address &c -> assoc of packages -> assoc of bug#'s
my %param = validate_with(params => \@_,
spec => {data => {type => HASHREF|ARRAYREF,
},
recipients => {type => HASHREF,
},
debug => {type => HANDLE|SCALARREF,
optional => 1,
},
transcript => {type => HANDLE|SCALARREF,
optional => 1,
},
actions_taken => {type => HASHREF,
default => {},
},
unknown_packages => {type => HASHREF,
default => {},
},
},
);
$param{transcript} = globify_scalar($param{transcript});
$param{debug} = globify_scalar($param{debug});
if (ref ($param{data}) eq 'ARRAY') {
for my $data (@{$param{data}}) {
add_recipients(data => $data,
map {exists $param{$_}?($_,$param{$_}):()}
qw(recipients debug transcript actions_taken unknown_packages)
);
}
return;
}
my ($addmaint);
my $ref = $param{data}{bug_num};
for my $p (splitpackages($param{data}{package})) {
$p = lc($p);
if (defined $config{subscription_domain}) {
my @source_packages = binary_to_source(binary => $p,
source_only => 1,
);
if (@source_packages) {
for my $source (@source_packages) {
_add_address(recipients => $param{recipients},
address => "$source\@".$config{subscription_domain},
reason => $source,
type => 'bcc',
);
}
}
else {
_add_address(recipients => $param{recipients},
address => "$p\@".$config{subscription_domain},
reason => $p,
type => 'bcc',
);
}
}
if (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},
reason => $param{data}{severity},
type => 'bcc',
);
}
my @maints = package_maintainer(binary => $p);
if (@maints) {
print {$param{debug}} "MR|".join(',',@maints)."|$p|$ref|\n";
_add_address(recipients => $param{recipients},
address => \@maints,
reason => $p,
bug_num => $param{data}{bug_num},
type => 'cc',
);
print {$param{debug}} "maintainer add >$p|".join(',',@maints)."<\n";
}
else {
print {$param{debug}} "maintainer none >$p<\n";
if (not exists $param{unknown_packages}{$p}) {
print {$param{transcript}} "Warning: Unknown package '$p'\n";
$param{unknown_packages}{$p} = 1;
}
print {$param{debug}} "MR|unknown-package|$p|$ref|\n";
_add_address(recipients => $param{recipients},
address => $config{unknown_maintainer_email},
reason => $p,
bug_num => $param{data}{bug_num},
type => 'cc',
)
if defined $config{unknown_maintainer_email} and
length $config{unknown_maintainer_email};
}
}
if (defined $config{bug_subscription_domain} and
length $config{bug_subscription_domain}) {
_add_address(recipients => $param{recipients},
address => 'bugs='.$param{data}{bug_num}.'@'.
$config{bug_subscription_domain},
reason => "bug $param{data}{bug_num}",
bug_num => $param{data}{bug_num},
type => 'bcc',
);
}
if (defined $config{cc_all_mails_to_addr} and
length $config{cc_all_mails_to_addr}
) {
_add_address(recipients => $param{recipients},
address => $config{cc_all_mails_to},
reason => "cc_all_mails_to",
bug_num => $param{data}{bug_num},
type => 'bcc',
);
}
if (length $param{data}{owner}) {
$addmaint = $param{data}{owner};
print {$param{debug}} "MO|$addmaint|$param{data}{package}|$ref|\n";
_add_address(recipients => $param{recipients},
address => $addmaint,
reason => "owner of $param{data}{bug_num}",
bug_num => $param{data}{bug_num},
type => 'cc',
);
print {$param{debug}} "owner add >$param{data}{package}|$addmaint<\n";
}
if (exists $param{actions_taken}) {
if (exists $param{actions_taken}{done} and
$param{actions_taken}{done} and
length($config{done_list}) and
length($config{list_domain})
) {
_add_address(recipients => $param{recipients},
type => 'cc',
address => $config{done_list}.'@'.$config{list_domain},
bug_num => $param{data}{bug_num},
reason => "bug $param{data}{bug_num} done",
);
}
if (exists $param{actions_taken}{forwarded} and
$param{actions_taken}{forwarded} and
length($config{forward_list}) and
length($config{list_domain})
) {
_add_address(recipients => $param{recipients},
type => 'cc',
address => $config{forward_list}.'@'.$config{list_domain},
bug_num => $param{data}{bug_num},
reason => "bug $param{data}{bug_num} forwarded",
);
}
}
}
=head2 determine_recipients
my @recipients = determine_recipients(recipients => \%recipients,
bcc => 1,
);
my %recipients => determine_recipients(recipients => \%recipients,);
# or a crazy example:
send_mail_message(message => $message,
recipients =>
[make_list(
values %{{determine_recipients(
recipients => \%recipients)
}})
],
);
Using the recipient hashref, determines the set of recipients.
If you specify one of C<bcc>, C<cc>, or C<to>, you will receive only a
LIST of recipients which the main should be Bcc'ed, Cc'ed, or To'ed
respectively. By default, a LIST with keys bcc, cc, and to is returned
with ARRAYREF values corresponding to the users to whom a message
should be sent.
=over
=item address_only -- whether to only return mail addresses without reasons or realnamesq
=back
Passing more than one of bcc, cc or to is a fatal error.
=cut
sub determine_recipients {
my %param = validate_with(params => \@_,
spec => {recipients => {type => HASHREF,
},
bcc => {type => BOOLEAN,
default => 0,
},
cc => {type => BOOLEAN,
default => 0,
},
to => {type => BOOLEAN,
default => 0,
},
address_only => {type => BOOLEAN,
default => 0,
}
},
);
if (1 < scalar grep {$param{$_}} qw(to cc bcc)) {
croak "Passing more than one of to, cc, or bcc is non-sensical";
}
my %final_recipients;
# start with the to recipients
for my $addr (keys %{$param{recipients}}) {
my $level = 'bcc';
my @reasons;
for my $reason (keys %{$param{recipients}{$addr}}) {
my @bugs;
for my $bug (keys %{$param{recipients}{$addr}{$reason}}) {
push @bugs, $bug;
my $t_level = $param{recipients}{$addr}{$reason}{$bug};
if ($level eq 'to' or
$t_level eq 'to') {
$level = 'to';
}
elsif ($t_level eq 'cc') {
$level = 'cc';
}
}
# RFC 2822 comments cannot contain specials and
# unquoted () or \; there's no reason for us to allow
# insane things here, though, so we restrict this even
# more to 20-7E ( -~)
$reason =~ s/\\/\\\\/g;
$reason =~ s/([\)\(])/\\$1/g;
$reason =~ s/[^\x20-\x7E]//g;
push @reasons, $reason . ' for {'.join(',',@bugs).'}';
}
if ($param{address_only}) {
push @{$final_recipients{$level}}, get_addresses($addr);
}
else {
push @{$final_recipients{$level}}, $addr . ' ('.join(', ',@reasons).')';
}
}
for (qw(to cc bcc)) {
if ($param{$_}) {
if (exists $final_recipients{$_}) {
return @{$final_recipients{$_}||[]};
}
return ();
}
}
return %final_recipients;
}
=head1 PRIVATE FUNCTIONS
=head2 _add_address
_add_address(recipients => $param{recipients},
address => $addmaint,
reason => $param{data}{package},
bug_num => $param{data}{bug_num},
type => 'cc',
);
=cut
sub _add_address {
my %param = validate_with(params => \@_,
spec => {recipients => {type => HASHREF,
},
bug_num => {type => SCALAR,
regex => qr/^\d*$/,
default => '',
},
reason => {type => SCALAR,
default => '',
},
address => {type => SCALAR|ARRAYREF,
},
type => {type => SCALAR,
default => 'cc',
regex => qr/^(?:b?cc|to)$/i,
},
},
);
for my $addr (make_list($param{address})) {
if (lc($param{type}) eq 'bcc' and
exists $param{recipients}{$addr}{$param{reason}}{$param{bug_num}}
) {
next;
}
elsif (lc($param{type}) eq 'cc' and
exists $param{recipients}{$addr}{$param{reason}}{$param{bug_num}}
and $param{recipients}{$addr}{$param{reason}}{$param{bug_num}} eq 'to'
) {
next;
}
$param{recipients}{$addr}{$param{reason}}{$param{bug_num}} = lc($param{type});
}
}
1;
__END__
|