]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/Recipients.pm
* Make service use warnings; use strict;
[debbugs.git] / Debbugs / Recipients.pm
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 $
6
7 package Debbugs::Recipients;
8
9 =head1 NAME
10
11 Debbugs::Recipients -- Determine recipients of messages from the bts
12
13 =head1 SYNOPSIS
14
15
16 =head1 DESCRIPTION
17
18
19 =head1 BUGS
20
21 None known.
22
23 =cut
24
25 use warnings;
26 use strict;
27 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT);
28 use base qw(Exporter);
29
30 BEGIN{
31      ($VERSION) = q$Revision: 1221 $ =~ /^Revision:\s+([^\s+])/;
32      $DEBUG = 0 unless defined $DEBUG;
33
34      @EXPORT = ();
35      %EXPORT_TAGS = (add    => [qw(add_recipients)],
36                      det    => [qw(determine_recipients)],
37                     );
38      @EXPORT_OK = ();
39      Exporter::export_ok_tags(keys %EXPORT_TAGS);
40      $EXPORT_TAGS{all} = [@EXPORT_OK];
41
42 }
43
44 use Debbugs::Config qw(:config);
45
46 =head2 add_recipients
47
48      add_recipients(data => $data,
49                     recipients => \%recipients;
50                    );
51
52 Given data (from read_bug or similar) (or an arrayref of data),
53 calculates the addresses which need to receive mail involving this
54 bug.
55
56 =over
57
58 =item data -- Data from read_bug or similar; can be an arrayref of data
59
60 =item recipients -- hashref of recipient data structure; pass to
61 subsequent calls of add_recipients or
62
63 =item debug -- optional 
64
65
66 =back
67
68 =cut
69
70
71 sub add_recipients {
72      # Data structure is:
73      #   maintainer email address &c -> assoc of packages -> assoc of bug#'s
74      my %param = validate_with(params => \@_,
75                                spec   => {data => {type => HASHREF|ARRAYREF,
76                                                   },
77                                           recipients => {type => HASHREF,
78                                                         },
79                                           debug => {type => HANDLE|SCALARREF,
80                                                     optional => 1,
81                                                    },
82                                          },
83                               );
84      if (ref ($param{data}) eq 'ARRAY') {
85           for (@{$param{data}}) {
86                add_recipients(map {exists $param{$_}?:($_,$param{$_}):()}
87                               qw(recipients debug)
88                              );
89           }
90      }
91      my ($p, $addmaint);
92      my $anymaintfound=0; my $anymaintnotfound=0;
93      for my $p (splitpackages($param{data}{package})) {
94           $p = lc($p);
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},
101                                       reason => $source,
102                                       type  => 'bcc',
103                                      );
104                     }
105                }
106                else {
107                     _add_address(recipients => $param{recipients},
108                                  address => "$p\@".$config{subscription_domain},
109                                  reason => $p,
110                                  type  => 'bcc',
111                                 );
112                }
113           }
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},
119                             type  => 'bcc',
120                            );
121           }
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,
127                             reason => $p,
128                             bug_num => $param{data}{bug_num},
129                             type  => 'cc',
130                            );
131                print "maintainer add >$p|$addmaint<\n" if $debug;
132           }
133           else { 
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},
139                             reason => $p,
140                             bug_num => $param{data}{bug_num},
141                             type  => 'cc',
142                            )
143                     if defined $config{unknown_maintainer_email} and
144                          length $config{unknown_maintainer_email};
145           }
146       }
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},
154                        type       => 'bcc',
155                       );
156      }
157
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},
165                        type  => 'cc',
166                       );
167         print "owner add >$param{data}{package}|$addmaint<\n" if $debug;
168      }
169 }
170
171 =head1 PRIVATE FUNCTIONS
172
173 =head2 _add_address
174
175           _add_address(recipients => $param{recipients},
176                        address => $addmaint,
177                        reason => $param{data}{package},
178                        bug_num => $param{data}{bug_num},
179                        type  => 'cc',
180                       );
181
182
183 =cut
184
185
186 sub _add_address {
187      my %param = validate_with(params => \@_,
188                                spec => {recipients => {type => HASHREF,
189                                                       },
190                                         bug_num    => {type => SCALAR,
191                                                        regex => qr/^\d*$/,
192                                                        default => '',
193                                                       },
194                                         reason     => {type => SCALAR,
195                                                        default => '',
196                                                       },
197                                         address    => {type => SCALAR|ARRAYREF,
198                                                       },
199                                         type       => {type => SCALAR,
200                                                        default => 'cc',
201                                                        regex   => qr/^b?cc/i,
202                                                       },
203                                        },
204                               );
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}}
208              ) {
209                next;
210           }
211           $param{recipients}{$addr}{$param{reason}}{$param{bug_num}} = $param{type};
212      }
213 }
214
215 1;
216
217
218 __END__
219
220
221
222
223
224