2 # $Id: service.in,v 1.118 2005/10/19 01:22:14 don Exp $
4 # Usage: service <code>.nn
5 # Temps: incoming/P<code>.nn
11 use Debbugs::Config qw(:globals :config);
16 use Params::Validate qw(:types validate_with);
18 use Debbugs::Common qw(:util :quit :misc :lock);
20 use Debbugs::Status qw(:read :status :write :versions :hook);
22 use Debbugs::MIME qw(decode_rfc1522 encode_rfc1522);
23 use Debbugs::Mail qw(send_mail_message);
25 use Debbugs::Recipients qw(:all);
26 use HTML::Entities qw(encode_entities);
27 use Debbugs::Versions::Dpkg;
29 use Debbugs::Status qw(splitpackages);
31 use Debbugs::CGI qw(html_escape);
32 use Debbugs::Control qw(:all);
33 use Debbugs::Log qw(:misc);
34 use Debbugs::Text qw(:templates);
36 use Scalar::Util qw(looks_like_number);
38 use List::Util qw(first);
40 use Mail::RFC822::Address;
42 chdir($config{spool_dir}) or
43 die "Unable to chdir to spool_dir '$config{spool_dir}': $!";
48 my ($nn,$control) = $ARGV[0] =~ m/^(([RC])\.\d+)$/;
49 if (not defined $control or not defined $nn) {
50 die "Bad argument to service.in";
52 if (!rename("incoming/G$nn","incoming/P$nn")) {
53 defined $! and $! =~ m/no such file or directory/i and exit 0;
54 die "Failed to rename incoming/G$nn to incoming/P$nn: $!";
57 my $log_fh = IO::File->new("incoming/P$nn",'r') or
58 die "Unable to open incoming/P$nn for reading: $!";
65 print "###\n",join("##\n",@msg),"\n###\n" if $debug;
67 # Bug numbers to send e-mail to, hash so that we don't send to the
71 my (@headerlines,@bodylines);
73 my $parse_output = Debbugs::MIME::parse(join('',@log));
74 @headerlines = @{$parse_output->{header}};
75 @bodylines = @{$parse_output->{body}};
79 $_ = decode_rfc1522($_);
81 print ">$_<\n" if $debug;
84 print ">$v=$_<\n" if $debug;
87 print "!>$_<\n" if $debug;
90 $header{'message-id'} ||= '';
91 $header{subject} ||= '';
93 grep(s/\s+$//,@bodylines);
95 print "***\n",join("\n",@bodylines),"\n***\n" if $debug;
97 if (defined $header{'resent-from'} && !defined $header{'from'}) {
98 $header{'from'} = $header{'resent-from'};
101 defined($header{'from'}) || die "no From header";
103 delete $header{'reply-to'}
104 if ( defined($header{'reply-to'}) && $header{'reply-to'} =~ m/^\s*$/ );
107 if ( defined($header{'reply-to'}) && $header{'reply-to'} ne "" ) {
108 $replyto = $header{'reply-to'};
110 $replyto = $header{'from'};
113 # This is an error counter which should be incremented every time there is an error.
115 my $controlrequestaddr= ($control ? 'control' : 'request').'@'.$config{email_domain};
116 my $transcript_scalar = '';
117 my $transcript = IO::Scalar->new(\$transcript_scalar) or
118 die "Unable to create new IO::Scalar";
119 print {$transcript} "Processing commands for $controlrequestaddr:\n\n";
123 my %affected_packages;
125 # this is the hashref which is passed to all control calls
129 my @common_control_options =
130 (transcript => $transcript,
131 requester => $header{from},
132 request_addr => $controlrequestaddr,
133 request_msgid => $header{'message-id'},
134 request_subject => $header{subject},
136 request_replyto => $replyto,
138 affected_bugs => \%bug_affected,
139 affected_packages => \%affected_packages,
140 recipients => \%recipients,
145 my $lowstate= 'idle';
146 my $mergelowstate= 'idle';
151 $user =~ s/^.*<(.*)>.*$/$1/;
152 $user =~ s/[(].*[)]//;
153 $user =~ s/^\s*(\S+)\s+.*$/$1/;
154 $user = "" unless (Debbugs::User::is_valid_user($user));
155 my $indicated_user = 0;
160 if (@gExcludeFromControl and grep {$replyto =~ m/\Q$_\E/} @gExcludeFromControl) {
161 print {$transcript} fill_template('mail/excluded_from_control');
172 push @bcc, $_[0] unless grep { $_ eq $_[0] } @bcc;
187 for ($procline=0; $procline<=$#bodylines; $procline++) {
192 $state eq 'idle' || print "state: $state ?\n";
193 $lowstate eq 'idle' || print "lowstate: $lowstate ?\n";
194 $mergelowstate eq 'idle' || print "mergelowstate: $mergelowstate ?\n";
196 print {$transcript} "Stopping processing here.\n\n";
199 $_= $bodylines[$procline]; s/\s+$//;
200 # Remove BOM markers from UTF-8 strings
204 print {$transcript} "> $_\n";
207 if (m/^(?:stop|quit|--|thank(?:s|\s*you)?|kthxbye)\.*\s*$/i) {
208 print {$transcript} "Stopping processing here.\n\n";
210 } elsif (m/^debug\s+(\d+)$/i && $1 >= 0 && $1 <= 1000) {
212 if ($dl > 0 and not grep /debug/,@common_control_options) {
213 push @common_control_options,(debug => $transcript);
215 print {$transcript} "Debug level $dl.\n\n";
216 } elsif (m/^(send|get)\s+\#?(\d{2,})$/i) {
218 &sendlynxdoc("bugreport.cgi?bug=$ref","logs for $gBug#$ref");
219 } elsif (m/^send-detail\s+\#?(\d{2,})$/i) {
221 &sendlynxdoc("bugreport.cgi?bug=$ref&boring=yes",
222 "detailed logs for $gBug#$ref");
223 } elsif (m/^index(\s+full)?$/i) {
224 print {$transcript} "This BTS function is currently disabled, sorry.\n\n";
226 $ok++; # well, it's not really ok, but it fixes #81224 :)
227 } elsif (m/^index-summary\s+by-package$/i) {
228 print {$transcript} "This BTS function is currently disabled, sorry.\n\n";
230 $ok++; # well, it's not really ok, but it fixes #81224 :)
231 } elsif (m/^index-summary(\s+by-number)?$/i) {
232 print {$transcript} "This BTS function is currently disabled, sorry.\n\n";
234 $ok++; # well, it's not really ok, but it fixes #81224 :)
235 } elsif (m/^index(\s+|-)pack(age)?s?$/i) {
236 &sendlynxdoc("pkgindex.cgi?indexon=pkg",'index of packages');
237 } elsif (m/^index(\s+|-)maints?$/i) {
238 &sendlynxdoc("pkgindex.cgi?indexon=maint",'index of maintainers');
239 } elsif (m/^index(\s+|-)maint\s+(\S+)$/i) {
241 &sendlynxdoc("pkgreport.cgi?maint=" . urlsanit($maint),
242 "$gBug list for maintainer \`$maint'");
244 } elsif (m/^index(\s+|-)pack(age)?s?\s+(\S.*\S)$/i) {
246 &sendlynxdoc("pkgreport.cgi?pkg=" . urlsanit($package),
247 "$gBug list for package $package");
249 } elsif (m/^send-unmatched(\s+this|\s+-?0)?$/i) {
250 print {$transcript} "This BTS function is currently disabled, sorry.\n\n";
252 $ok++; # well, it's not really ok, but it fixes #81224 :)
253 } elsif (m/^send-unmatched\s+(last|-1)$/i) {
254 print {$transcript} "This BTS function is currently disabled, sorry.\n\n";
256 $ok++; # well, it's not really ok, but it fixes #81224 :)
257 } elsif (m/^send-unmatched\s+(old|-2)$/i) {
258 print {$transcript} "This BTS function is currently disabled, sorry.\n\n";
260 $ok++; # well, it's not really ok, but it fixes #81224 :)
261 } elsif (m/^getinfo\s+([\w.-]+)$/i) {
262 # the following is basically a Debian-specific kludge, but who cares
264 if ($req =~ /^maintainers$/i && -f "$gConfigDir/Maintainers") {
265 &sendinfo("local", "$gConfigDir/Maintainers", "Maintainers file");
266 } elsif ($req =~ /^override\.(\w+)\.([\w.-]+)$/i) {
268 &sendinfo("ftp.d.o", "$req", "override file for $2 part of $1 distribution");
269 } elsif ($req =~ /^pseudo-packages\.(description|maintainers)$/i && -f "$gConfigDir/$req") {
270 &sendinfo("local", "$gConfigDir/$req", "$req file");
272 print {$transcript} "Info file $req does not exist.\n\n";
274 } elsif (m/^help/i) {
276 print {$transcript} "\n";
278 } elsif (m/^refcard/i) {
279 &sendtxthelp("bug-mailserver-refcard.txt","mail servers' reference card");
280 } elsif (m/^subscribe/i) {
281 print {$transcript} <<END;
282 There is no $gProject $gBug mailing list. If you wish to review bug reports
283 please do so via http://$gWebDomain/ or ask this mail server
285 soon: MAILINGLISTS_TEXT
287 } elsif (m/^unsubscribe/i) {
288 print {$transcript} <<END;
289 soon: UNSUBSCRIBE_TEXT
290 soon: MAILINGLISTS_TEXT
292 } elsif (m/^user\s+(\S+)\s*$/i) {
294 if (Debbugs::User::is_valid_user($newuser)) {
295 my $olduser = ($user ne "" ? " (was $user)" : "");
296 print {$transcript} "Setting user to $newuser$olduser.\n";
300 print {$transcript} "Selected user id ($newuser) invalid, sorry\n";
305 } elsif (m/^usercategory\s+(\S+)(\s+\[hidden\])?\s*$/i) {
308 my $hidden = (defined $2 and $2 ne "");
315 print {$transcript} "No valid user selected\n";
319 if (not $indicated_user and defined $user) {
320 print {$transcript} "User is $user\n";
324 while (++$procline <= $#bodylines) {
325 unless ($bodylines[$procline] =~ m/^\s*([*+])\s*(\S.*)$/) {
329 print {$transcript} "> $bodylines[$procline]\n";
331 my ($o, $txt) = ($1, $2);
332 if ($#cats == -1 && $o eq "+") {
333 print {$transcript} "User defined category specification must start with a category name. Skipping.\n\n";
339 unless (ref($cats[-1]) eq "HASH") {
340 $cats[-1] = { "nam" => $cats[-1],
341 "pri" => [], "ttl" => [] };
344 my ($desc, $ord, $op);
345 if ($txt =~ m/^(.*\S)\s*\[((\d+):\s*)?\]\s*$/) {
346 $desc = $1; $ord = $3; $op = "";
347 } elsif ($txt =~ m/^(.*\S)\s*\[((\d+):\s*)?(\S+)\]\s*$/) {
348 $desc = $1; $ord = $3; $op = $4;
349 } elsif ($txt =~ m/^([^[\s]+)\s*$/) {
350 $desc = ""; $op = $1;
352 print {$transcript} "Unrecognised syntax for category section. Skipping.\n\n";
357 $ord = 999 unless defined $ord;
360 push @{$cats[-1]->{"pri"}}, $prefix . $op;
361 push @{$cats[-1]->{"ttl"}}, $desc;
362 push @ords, "$ord $catsec";
364 $cats[-1]->{"def"} = $desc;
365 push @ords, "$ord DEF";
369 my ($a1, $a2, $b1, $b2) = split / /, "$a $b";
370 ((looks_like_number($a1) and looks_like_number($a2))?$a1 <=> $b1:$a1 cmp $b1) ||
371 ((looks_like_number($a2) and looks_like_number($b2))?$a2 <=> $b2:$a2 cmp $b2);
373 $cats[-1]->{"ord"} = [map { m/^.* (\S+)/; $1 eq "DEF" ? $catsec + 1 : $1 } @ords];
374 } elsif ($o eq "*") {
377 if ($txt =~ m/^(.*\S)(\s*\[(\S+)\])\s*$/) {
378 $name = $1; $prefix = $3;
380 $name = $txt; $prefix = "";
385 # XXX: got @cats, now do something with it
386 my $u = Debbugs::User::get_user($user);
388 print {$transcript} "Added usercategory $catname.\n\n";
389 $u->{"categories"}->{$catname} = [ @cats ];
391 push @{$u->{visible_cats}},$catname;
394 print {$transcript} "Removed usercategory $catname.\n\n";
395 delete $u->{"categories"}->{$catname};
396 @{$u->{visible_cats}} = grep {$_ ne $catname} @{$u->{visible_cats}};
399 } elsif (m/^usertags?\s+\#?(-?\d+)\s+(([=+-])\s*)?(\S.*)?$/i) {
402 my $addsubcode = $3 || "+";
404 if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
405 $ref = $clonebugs{$ref};
408 print {$transcript} "No valid user selected\n";
412 if (not $indicated_user and defined $user) {
413 print {$transcript} "User is $user\n";
418 Debbugs::User::read_usertags(\%ut, $user);
419 my @oldtags = (); my @newtags = (); my @badtags = ();
421 if (defined $tags and length $tags) {
422 for my $t (split /[,\s]+/, $tags) {
423 if ($t =~ m/^[a-zA-Z0-9.+\@-]+$/) {
431 print {$transcript} "Ignoring illegal tag/s: ".join(', ', @badtags).".\nPlease use only alphanumerics, at, dot, plus and dash.\n";
434 for my $t (keys %chtags) {
435 $ut{$t} = [] unless defined $ut{$t};
437 for my $t (keys %ut) {
438 my %res = map { ($_, 1) } @{$ut{$t}};
439 push @oldtags, $t if defined $res{$ref};
440 my $addop = ($addsubcode eq "+" or $addsubcode eq "=");
441 my $del = (defined $chtags{$t} ? $addsubcode eq "-"
442 : $addsubcode eq "=");
443 $res{$ref} = 1 if ($addop && defined $chtags{$t});
444 delete $res{$ref} if ($del);
445 push @newtags, $t if defined $res{$ref};
446 $ut{$t} = [ sort { $a <=> $b } (keys %res) ];
449 print {$transcript} "There were no usertags set.\n";
451 print {$transcript} "Usertags were: " . join(" ", @oldtags) . ".\n";
453 print {$transcript} "Usertags are now: " . join(" ", @newtags) . ".\n";
454 Debbugs::User::write_usertags(\%ut, $user);
456 } elsif (!$control) {
457 print {$transcript} <<END;
458 Unknown command or malformed arguments to command.
459 (Use control\@$gEmailDomain to manipulate reports.)
463 if (++$unknowns >= 3) {
464 print {$transcript} "Too many unknown commands, stopping here.\n\n";
467 #### "developer only" ones start here
468 } elsif (m/^close\s+\#?(-?\d+)(?:\s+(\d.*))?$/i) {
471 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
474 set_fixed(@common_control_options,
482 print {$transcript} "Failed to add fixed version '$2' to $ref: ".cleanup_eval_fail($@,$debug)."\n";
486 set_done(@common_control_options,
490 notify_submitter => 1,
496 print {$transcript} "Failed to mark $ref as done: ".cleanup_eval_fail($@,$debug)."\n";
498 } elsif (m/^reassign\s+\#?(-?\d+)\s+ # bug and command
499 (?:(?:((?:src:|source:)?$config{package_name_re}) # new package
500 (?:\s+((?:$config{package_name_re}\/)?
501 $config{package_version_re}))?)| # optional version
502 ((?:src:|source:)?$config{package_name_re} # multiple package form
503 (?:\s*\,\s*(?:src:|source:)?$config{package_name_re})+))
508 if (not defined $2) {
509 push @new_packages, split /\s*\,\s*/,$4;
512 push @new_packages, $2;
514 @new_packages = map {y/A-Z/a-z/; s/^(?:src|source):/src:/; $_;} @new_packages;
515 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
518 set_package(@common_control_options,
520 package => \@new_packages,
522 # if there is a version passed, we make an internal call
524 if (defined($version) && length $version) {
525 set_found(@common_control_options,
533 print {$transcript} "Failed to clear fixed versions and reopen on $ref: ".cleanup_eval_fail($@,$debug)."\n";
535 } elsif (m/^reopen\s+\#?(-?\d+)(?:\s+([\=\!]|(?:\S.*\S)))?$/i) {
538 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
539 my $new_submitter = $2;
540 if (defined $new_submitter) {
541 if ($new_submitter eq '=') {
542 undef $new_submitter;
544 elsif ($new_submitter eq '!') {
545 $new_submitter = $replyto;
549 set_done(@common_control_options,
552 submitter => $new_submitter,
557 print {$transcript} "Failed to reopen $ref: ".cleanup_eval_fail($@,$debug)."\n";
559 } elsif (m{^(?:(?i)found)\s+\#?(-?\d+)
560 (?:\s+((?:$config{package_name_re}\/)?
561 $config{package_version_re}
562 # allow for multiple packages
563 (?:\s*,\s*(?:$config{package_name_re}\/)?
564 $config{package_version_re})*)
568 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
571 @versions = split /\s*,\s*/,$2;
573 set_found(@common_control_options,
581 print {$transcript} "Failed to add found on $ref: ".cleanup_eval_fail($@,$debug)."\n";
586 set_fixed(@common_control_options,
594 print {$transcript} "Failed to clear fixed versions and reopen on $ref: ".cleanup_eval_fail($@,$debug)."\n";
598 elsif (m{^(?:(?i)notfound)\s+\#?(-?\d+)
599 \s+((?:$config{package_name_re}\/)?
600 $config{package_version_re}
601 # allow for multiple packages
602 (?:\s*,\s*(?:$config{package_name_re}\/)?
603 $config{package_version_re})*
607 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
609 @versions = split /\s*,\s*/,$2;
611 set_found(@common_control_options,
619 print {$transcript} "Failed to remove found on $ref: ".cleanup_eval_fail($@,$debug)."\n";
622 elsif (m{^(?:(?i)fixed)\s+\#?(-?\d+)
623 \s+((?:$config{package_name_re}\/)?
624 $config{package_version_re}
625 # allow for multiple packages
626 (?:\s*,\s*(?:$config{package_name_re}\/)?
627 $config{package_version_re})*)
631 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
633 @versions = split /\s*,\s*/,$2;
635 set_fixed(@common_control_options,
643 print {$transcript} "Failed to add fixed on $ref: ".cleanup_eval_fail($@,$debug)."\n";
646 elsif (m{^(?:(?i)notfixed)\s+\#?(-?\d+)
647 \s+((?:$config{package_name_re}\/)?
648 $config{package_version_re}
649 # allow for multiple packages
650 (?:\s*,\s*(?:$config{package_name_re}\/)?
651 $config{package_version_re})*)
655 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
657 @versions = split /\s*,\s*/,$2;
659 set_fixed(@common_control_options,
667 print {$transcript} "Failed to remove fixed on $ref: ".cleanup_eval_fail($@,$debug)."\n";
670 elsif (m/^submitter\s+\#?(-?\d+)\s+(\!|\S.*\S)$/i) {
673 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
674 my $newsubmitter = $2 eq '!' ? $replyto : $2;
675 if (not Mail::RFC822::Address::valid($newsubmitter)) {
676 print {$transcript} "$newsubmitter is not a valid e-mail address; not changing submitter\n";
681 set_submitter(@common_control_options,
683 submitter => $newsubmitter,
688 print {$transcript} "Failed to set submitter on $ref: ".cleanup_eval_fail($@,$debug)."\n";
691 } elsif (m/^forwarded\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
695 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
697 set_forwarded(@common_control_options,
699 forwarded => $forward_to,
704 print {$transcript} "Failed to set the forwarded-to-address of $ref: ".cleanup_eval_fail($@,$debug)."\n";
706 } elsif (m/^notforwarded\s+\#?(-?\d+)$/i) {
709 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
711 set_forwarded(@common_control_options,
718 print {$transcript} "Failed to clear the forwarded-to-address of $ref: ".cleanup_eval_fail($@,$debug)."\n";
720 } elsif (m/^(?:severity|priority)\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i) {
723 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
725 if (exists $gObsoleteSeverities{$newseverity}) {
726 print {$transcript} "Severity level \`$newseverity' is obsolete. " .
727 "Use $gObsoleteSeverities{$newseverity} instead.\n\n";
729 } elsif (not defined first {$_ eq $newseverity}
730 (@gSeverityList, "$gDefaultSeverity")) {
731 print {$transcript} "Severity level \`$newseverity' is not known.\n".
732 "Recognized are: $gShowSeverities.\n\n";
736 set_severity(@common_control_options,
738 severity => $newseverity,
743 print {$transcript} "Failed to set severity of $config{bug} $ref to $newseverity: ".cleanup_eval_fail($@,$debug)."\n";
746 } elsif (m/^tags?\s+\#?(-?\d+)\s+(\S.*)$/i) {
749 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
751 my @tags = map {m/^([+=-])(.+)/ ? ($1,$2):($_)} split /[\s,]+/, $tags;
752 # this is an array of hashrefs which contain two elements, the
753 # first of which is the array of tags, the second is the
754 # option to pass to set_tag (we use a hashref here to make it
755 # more obvious what is happening)
758 for my $tag (@tags) {
759 if ($tag =~ /^[=+-]$/) {
761 @tag_operations = {tags => [],
765 elsif ($tag eq '-') {
766 push @tag_operations,
768 option => [remove => 1],
771 elsif ($tag eq '+') {
772 push @tag_operations,
774 option => [add => 1],
779 if (not defined first {$_ eq $tag} @{$config{tags}}) {
783 if (not @tag_operations) {
784 @tag_operations = {tags => [],
785 option => [add => 1],
788 push @{$tag_operations[-1]{tags}},$tag;
791 print {$transcript} "Unknown tag/s: ".join(', ', @badtags).".\n".
792 "Recognized are: ".join(' ', @gTags).".\n\n";
796 for my $operation (@tag_operations) {
797 set_tag(@common_control_options,
799 tag => [@{$operation->{tags}}],
800 warn_on_bad_tags => 0, # don't warn on bad tags,
801 # 'cause we do that above
802 @{$operation->{option}},
807 # we intentionally have two errors here if there is a bad
808 # tag and the above fails for some reason
810 print {$transcript} "Failed to alter tags of $config{bug} $ref: ".cleanup_eval_fail($@,$debug)."\n";
812 } elsif (m/^(un)?block\s+\#?(-?\d+)\s+(?:by|with)\s+(\S.*)?$/i) {
815 my $add_remove = defined $1 && $1 eq 'un';
816 my @blockers = map {exists $clonebugs{$_}?$clonebugs{$_}:$_} split /[\s,]+/, $3;
817 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
819 set_blocks(@common_control_options,
822 $add_remove ? (remove => 1):(add => 1),
827 print {$transcript} "Failed to set blocking bugs of $ref: ".cleanup_eval_fail($@,$debug)."\n";
829 } elsif (m/^retitle\s+\#?(-?\d+)\s+(\S.*\S)\s*$/i) {
831 $ref= $1; my $newtitle= $2;
832 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
834 set_title(@common_control_options,
841 print {$transcript} "Failed to set the title of $ref: ".cleanup_eval_fail($@,$debug)."\n";
843 } elsif (m/^unmerge\s+\#?(-?\d+)$/i) {
846 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
848 set_merged(@common_control_options,
854 print {$transcript} "Failed to unmerge $ref: $@".cleanup_eval_fail($@,$debug)."\n";
856 } elsif (m/^merge\s+#?(-?\d+(\s+#?-?\d+)+)\s*$/i) {
859 ($ref,@tomerge) = map {exists $clonebugs{$_}?$clonebugs{$_}:$_}
862 set_merged(@common_control_options,
864 merge_with => \@tomerge,
869 print {$transcript} "Failed to merge $ref: $@".cleanup_eval_fail($@,$debug)."\n";
871 } elsif (m/^forcemerge\s+\#?(-?\d+(?:\s+\#?-?\d+)+)\s*$/i) {
874 ($ref,@tomerge) = map {exists $clonebugs{$_}?$clonebugs{$_}:$_}
877 set_merged(@common_control_options,
879 merge_with => \@tomerge,
886 print {$transcript} $@;
887 print {$transcript} "Failed to forcibly merge $ref: ".cleanup_eval_fail($@,$debug)."\n";
889 } elsif (m/^clone\s+#?(\d+)\s+((-\d+\s+)*-\d+)\s*$/i) {
893 my @newclonedids = split /\s+/, $2;
894 my $newbugsneeded = scalar(@newclonedids);
897 $bug_affected{$ref} = 1;
899 $affected_packages{$data->{package}} = 1;
900 if (length($data->{mergedwith})) {
901 print {$transcript} "$gBug is marked as being merged with others. Use an existing clone.\n\n";
905 &filelock("nextnumber.lock");
906 open(N,"nextnumber") || die "nextnumber: read: $!";
907 my $v=<N>; $v =~ s/\n$// || die "nextnumber bad format";
908 my $firstref= $v+0; $v += $newbugsneeded;
909 open(NN,">nextnumber"); print NN "$v\n"; close(NN);
912 my $lastref = $firstref + $newbugsneeded - 1;
914 if ($newbugsneeded == 1) {
915 $action= "$gBug $origref cloned as bug $firstref.";
917 $action= "$gBug $origref cloned as bugs $firstref-$lastref.";
920 my $blocks = $data->{blocks};
921 my $blockedby = $data->{blockedby};
924 my $ohash = get_hashname($origref);
925 my $clone = $firstref;
926 @bug_affected{@newclonedids} = 1 x @newclonedids;
927 for my $newclonedid (@newclonedids) {
928 $clonebugs{$newclonedid} = $clone;
930 my $hash = get_hashname($clone);
931 copy("db-h/$ohash/$origref.log", "db-h/$hash/$clone.log");
932 copy("db-h/$ohash/$origref.status", "db-h/$hash/$clone.status");
933 copy("db-h/$ohash/$origref.summary", "db-h/$hash/$clone.summary");
934 copy("db-h/$ohash/$origref.report", "db-h/$hash/$clone.report");
935 &bughook('new', $clone, $data);
937 # Update blocking info of bugs blocked by or blocking the
939 foreach $ref (split ' ', $blocks) {
941 $data->{blockedby} = manipset($data->{blockedby}, $clone, 1);
944 foreach $ref (split ' ', $blockedby) {
946 $data->{blocks} = manipset($data->{blocks}, $clone, 1);
954 } elsif (m/^package\:?\s+(\S.*\S)?\s*$/i) {
956 my @pkgs = split /\s+/, $1;
957 if (scalar(@pkgs) > 0) {
958 %limit_pkgs = map { ($_, 1) } @pkgs;
959 $limit{package} = [@pkgs];
960 print {$transcript} "Limiting to bugs with field 'package' containing at least one of ".join(', ',map {qq('$_')} @pkgs)."\n";
961 print {$transcript} "Limit currently set to";
962 for my $limit_field (keys %limit) {
963 print {$transcript} " '$limit_field':".join(', ',map {qq('$_')} @{$limit{$limit_field}})."\n";
965 print {$transcript} "\n";
968 $limit{package} = [];
969 print {$transcript} "Limit cleared.\n\n";
971 } elsif (m/^limit\:?\s+(\S.*\S)\s*$/) {
973 my ($field,@options) = split /\s+/, $1;
975 if ($field =~ /^(?:clear|unset|blank)$/) {
977 print {$transcript} "Limit cleared.\n\n";
979 elsif (exists $Debbugs::Status::fields{$field} or $field eq 'source') {
980 # %limit can actually contain regexes, but because they're
981 # not evaluated in Safe, DO NOT allow them through without
983 $limit{$field} = [@options];
984 print {$transcript} "Limiting to bugs with field '$field' containing at least one of ".join(', ',map {qq('$_')} @options)."\n";
985 print {$transcript} "Limit currently set to";
986 for my $limit_field (keys %limit) {
987 print {$transcript} " '$limit_field':".join(', ',map {qq('$_')} @{$limit{$limit_field}})."\n";
989 print {$transcript} "\n";
992 print {$transcript} "Limit key $field not understood. Stopping processing here.\n\n";
996 } elsif (m/^affects?\s+\#?(-?\d+)(?:\s+((?:[=+-])?)\s*(\S.*)?)?\s*$/i) {
999 my $add_remove = $2 || '';
1000 my $packages = $3 || '';
1001 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
1003 affects(@common_control_options,
1005 package => [splitpackages($3)],
1006 ($add_remove eq '+'?(add => 1):()),
1007 ($add_remove eq '-'?(remove => 1):()),
1012 print {$transcript} "Failed to mark $ref as affecting package(s): ".cleanup_eval_fail($@,$debug)."\n";
1015 } elsif (m/^summary\s+\#?(-?\d+)\s*(\d+|)\s*$/i) {
1018 my $summary_msg = length($2)?$2:undef;
1019 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
1021 summary(@common_control_options,
1023 summary => $summary_msg,
1028 print {$transcript} "Failed to give $ref a summary: ".cleanup_eval_fail($@,$debug)."\n";
1031 } elsif (m/^owner\s+\#?(-?\d+)\s+((?:\S.*\S)|\!)\s*$/i) {
1034 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
1036 if ($newowner eq '!') {
1037 $newowner = $replyto;
1040 owner(@common_control_options,
1047 print {$transcript} "Failed to mark $ref as having an owner: ".cleanup_eval_fail($@,$debug)."\n";
1049 } elsif (m/^noowner\s+\#?(-?\d+)\s*$/i) {
1052 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
1054 owner(@common_control_options,
1061 print {$transcript} "Failed to mark $ref as not having an owner: ".cleanup_eval_fail($@,$debug)."\n";
1063 } elsif (m/^unarchive\s+#?(\d+)$/i) {
1066 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
1068 bug_unarchive(@common_control_options,
1070 recipients => \%recipients,
1076 } elsif (m/^archive\s+#?(\d+)$/i) {
1079 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
1081 bug_archive(@common_control_options,
1084 archive_unarchived => 0,
1091 print {$transcript} "Unknown command or malformed arguments to command.\n\n";
1093 if (++$unknowns >= 5) {
1094 print {$transcript} "Too many unknown commands, stopping here.\n\n";
1099 if ($procline>$#bodylines) {
1100 print {$transcript} ">\nEnd of message, stopping processing here.\n\n";
1102 if (!$ok && !$quickabort) {
1104 print {$transcript} "No commands successfully parsed; sending the help text(s).\n";
1106 print {$transcript} "\n";
1109 my @maintccs = determine_recipients(recipients => \%recipients,
1113 my $maintccs = 'Cc: '.join(",\n ",
1114 determine_recipients(recipients => \%recipients,
1120 $packagepr = "X-${gProject}-PR-Package: " . join(keys %affected_packages) . "\n" if keys %affected_packages;
1122 # Add Bcc's to subscribed bugs
1123 # now handled by Debbugs::Recipients
1124 #push @bcc, map {"bugs=$_\@$gListDomain"} keys %bug_affected;
1126 if (!defined $header{'subject'} || $header{'subject'} eq "") {
1127 $header{'subject'} = "your mail";
1130 # Error text here advertises how many errors there were
1131 my $error_text = $errors > 0 ? " (with $errors errors)":'';
1134 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1136 ${maintccs}Subject: Processed${error_text}: $header{'subject'}
1137 In-Reply-To: $header{'message-id'}
1140 References: $header{'message-id'}
1141 Message-ID: <handler.s.$nn.transcript\@$gEmailDomain>
1143 ${packagepr}X-$gProject-PR-Message: transcript
1146 $reply .= fill_template('mail/message_body',
1147 {body => "${transcript_scalar}Please contact me if you need assistance."},
1150 my $repliedshow= join(', ',$replyto,
1151 determine_recipients(recipients => \%recipients,
1156 # -1 is the service.in log
1157 &filelock("lock/-1");
1158 open(AP,">>db-h/-1.log") || die "open db-h/-1.log: $!";
1160 "\2\n$repliedshow\n\5\n$reply\n\3\n".
1162 "<strong>Request received</strong> from <code>".
1163 html_escape($header{'from'})."</code>\n".
1164 "to <code>".html_escape($controlrequestaddr)."</code>\n".
1166 "\7\n",escape_log(@log),"\n\3\n") || die "writing db-h/-1.log: $!";
1167 close(AP) || die "open db-h/-1.log: $!";
1169 utime(time,time,"db-h");
1171 &sendmailmessage($reply,
1172 exists $header{'x-debbugs-no-ack'}?():$replyto,
1173 make_list(values %{{determine_recipients(recipients => \%recipients,
1179 unlink("incoming/P$nn") || die "unlinking incoming/P$nn: $!";
1181 sub sendmailmessage {
1182 my ($message,@recips) = @_;
1183 $message = "X-Loop: $gMaintainerEmail\n" . $message;
1184 send_mail_message(message => $message,
1185 recipients => \@recips,
1191 my ($template,$extra_var) = @_;
1193 my $variables = {config => \%config,
1194 defined($ref)?(ref => $ref):(),
1195 defined($data)?(data => $data):(),
1196 refs => [map {exists $clonebugs{$_}?$clonebugs{$_}:$_} keys %bug_affected],
1199 my $hole_var = {'&bugurl' =>
1201 'http://'.$config{cgi_domain}.'/'.
1202 Debbugs::CGI::bug_links(bug=>$_[0],
1207 return fill_in_template(template => $template,
1208 variables => $variables,
1209 hole_var => $hole_var,
1213 =head2 message_body_template
1215 message_body_template('mail/ack',{ref=>'foo'});
1217 Creates a message body using a template
1221 sub message_body_template{
1222 my ($template,$extra_var) = @_;
1224 my $body = fill_template($template,$extra_var);
1225 return fill_template('mail/message_body',
1234 &sendtxthelpraw("bug-maint-mailcontrol.txt","instructions for control\@$gEmailDomain")
1237 &sendtxthelpraw("bug-log-mailserver.txt","instructions for request\@$gEmailDomain");
1241 #sub unimplemented {
1242 # print {$transcript} "Sorry, command $_[0] not yet implemented.\n\n";
1244 our %checkmatch_values;
1246 my ($string,$mvarname,$svarvalue,@newmergelist) = @_;
1248 if (@newmergelist) {
1249 $mvarvalue = $checkmatch_values{$mvarname};
1250 print {$transcript} "D| checkmatch \`$string' /$mvarname/$mvarvalue/$svarvalue/\n"
1253 "Values for \`$string' don't match:\n".
1254 " #$newmergelist[0] has \`$mvarvalue';\n".
1255 " #$ref has \`$svarvalue'\n"
1256 if $mvarvalue ne $svarvalue;
1258 print {$transcript} "D| setupmatch \`$string' /$mvarname/$svarvalue/\n"
1260 $checkmatch_values{$mvarname} = $svarvalue;
1265 if (keys %limit_pkgs and not defined $limit_pkgs{$data->{package}}) {
1266 print {$transcript} "$gBug number $ref belongs to package $data->{package}, skipping.\n\n";
1278 my %h = map { $_ => 1 } split ' ', $list;
1285 return join ' ', sort keys %h;
1288 # High-level bug manipulation calls
1289 # Do announcements themselves
1291 # Possible calling sequences:
1292 # setbug (returns 0)
1294 # setbug (returns 1)
1295 # &transcript(something)
1298 # setbug (returns 1)
1299 # $action= (something)
1301 # (modify s_* variables)
1302 # } while (getnextbug);
1307 &dlen("nochangebug");
1308 $state eq 'single' || $state eq 'multiple' || die "$state ?";
1310 &endmerge if $manybugs;
1312 &dlex("nochangebug");
1316 our @thisbugmergelist;
1319 &dlen("setbug $ref");
1320 if ($ref =~ m/^-\d+/) {
1321 if (!defined $clonebugs{$ref}) {
1323 &dlex("setbug => noclone");
1326 $ref = $clonebugs{$ref};
1328 $state eq 'idle' || die "$state ?";
1331 &dlex("setbug => 0s");
1335 if (!&checkpkglimit) {
1340 @thisbugmergelist= split(/ /,$data->{mergedwith});
1341 if (!@thisbugmergelist) {
1346 &dlex("setbug => 1s");
1355 &dlex("setbug => 0mc");
1359 $state= 'multiple'; $sref=$ref;
1360 &dlex("setbug => 1m");
1365 &dlen("getnextbug");
1366 $state eq 'single' || $state eq 'multiple' || die "$state ?";
1368 if (!$manybugs || !@thisbugmergelist) {
1369 length($action) || die;
1370 print {$transcript} "$action\n$extramessage\n";
1371 &endmerge if $manybugs;
1373 &dlex("getnextbug => 0");
1376 $ref= shift(@thisbugmergelist);
1377 &getbug || die "bug $ref disappeared";
1379 &dlex("getnextbug => 1");
1383 # Low-level bug-manipulation calls
1384 # Do no announcements
1386 # getbug (returns 0)
1388 # getbug (returns 1)
1392 # $action= (something)
1393 # getbug (returns 1)
1395 # getbug (returns 1)
1397 # [getbug (returns 0)]
1398 # &transcript("$action\n\n")
1401 sub notfoundbug { print {$transcript} "$gBug number $ref not found. (Is it archived?)\n\n"; }
1402 sub foundbug { print {$transcript} "$gBug#$ref: $data->{subject}\n"; }
1406 $mergelowstate eq 'idle' || die "$mergelowstate ?";
1407 &filelock('lock/merge');
1408 $mergelowstate='locked';
1414 $mergelowstate eq 'locked' || die "$mergelowstate ?";
1416 $mergelowstate='idle';
1421 &dlen("getbug $ref");
1422 $lowstate eq 'idle' || die "$state ?";
1423 # Only use unmerged bugs here
1424 if (($data = &lockreadbug($ref,'db-h'))) {
1427 &dlex("getbug => 1");
1432 &dlex("getbug => 0");
1438 $lowstate eq 'open' || die "$state ?";
1445 &dlen("savebug $ref");
1446 $lowstate eq 'open' || die "$lowstate ?";
1447 length($action) || die;
1448 $ref == $sref || die "read $sref but saving $ref ?";
1449 append_action_to_log(bug => $ref,
1451 requester => $header{from},
1452 request_addr => $controlrequestaddr,
1456 unlockwritebug($ref, $data);
1463 print {$transcript} "C> @_ ($state $lowstate $mergelowstate)\n";
1468 print {$transcript} "R> @_ ($state $lowstate $mergelowstate)\n";
1475 my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
1476 $url =~ s/([<>&"])/\&$saniarray{$1};/g;
1482 print {$transcript} "\n";
1488 print {$transcript} "\n";
1494 sub sendtxthelpraw {
1495 my ($relpath,$description) = @_;
1497 if (not -e "$gDocDir/$relpath") {
1498 print {$transcript} "Unfortunatly, the help text doesn't exist, so it wasn't sent.\n";
1499 warn "Help text $gDocDir/$relpath not found";
1502 open(D,"$gDocDir/$relpath") || die "open doc file $relpath: $!";
1503 while(<D>) { $doc.=$_; }
1505 print {$transcript} "Sending $description in separate message.\n";
1506 &sendmailmessage(<<END.$doc,$replyto);
1507 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1509 Subject: $gProject $gBug help: $description
1510 References: $header{'message-id'}
1511 In-Reply-To: $header{'message-id'}
1512 Message-ID: <handler.s.$nn.help.$midix\@$gEmailDomain>
1514 X-$gProject-PR-Message: doc-text $relpath
1520 sub sendlynxdocraw {
1521 my ($relpath,$description) = @_;
1523 open(L,"lynx -nolist -dump http://$gCGIDomain/\Q$relpath\E 2>&1 |") || die "fork for lynx: $!";
1524 while(<L>) { $doc.=$_; }
1526 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1527 print {$transcript} "Information ($description) is not available -\n".
1528 "perhaps the $gBug does not exist or is not on the WWW yet.\n";
1531 print {$transcript} "Error getting $description (code $? $!):\n$doc\n";
1533 print {$transcript} "Sending $description.\n";
1534 &sendmailmessage(<<END.$doc,$replyto);
1535 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1537 Subject: $gProject $gBugs information: $description
1538 References: $header{'message-id'}
1539 In-Reply-To: $header{'message-id'}
1540 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1542 X-$gProject-PR-Message: doc-html $relpath
1551 my ($wherefrom,$path,$description) = @_;
1552 if ($wherefrom eq "ftp.d.o") {
1553 $doc = `lynx -nolist -dump http://ftp.debian.org/debian/indices/$path.gz 2>&1 | gunzip -cf` or die "fork for lynx/gunzip: $!";
1555 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1556 print {$transcript} "$description is not available.\n";
1559 print {$transcript} "Error getting $description (code $? $!):\n$doc\n";
1562 } elsif ($wherefrom eq "local") {
1564 $doc = do { local $/; <P> };
1567 print {$transcript} "internal errror: info files location unknown.\n";
1570 print {$transcript} "Sending $description.\n";
1571 &sendmailmessage(<<END.$doc,$replyto);
1572 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1574 Subject: $gProject $gBugs information: $description
1575 References: $header{'message-id'}
1576 In-Reply-To: $header{'message-id'}
1577 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1579 X-$gProject-PR-Message: getinfo
1581 $description follows:
1585 print {$transcript} "\n";