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} "Failed to forcibly merge $ref: ".cleanup_eval_fail($@,$debug)."\n";
888 } elsif (m/^clone\s+#?(\d+)\s+((-\d+\s+)*-\d+)\s*$/i) {
892 my @newclonedids = split /\s+/, $2;
893 my $newbugsneeded = scalar(@newclonedids);
896 if (exists $clonebugs{$ref}) {
897 $ref = $clonebugs{$ref};
899 $bug_affected{$ref} = 1;
902 clone_bug(@common_control_options,
904 new_bugs => \@newclonedids,
905 new_clones => \%new_clones,
907 %clonebugs = (%clonebugs,
912 print {$transcript} "Failed to clone $ref: ".cleanup_eval_fail($@,$debug)."\n";
914 } elsif (m/^package\:?\s+(\S.*\S)?\s*$/i) {
916 my @pkgs = split /\s+/, $1;
917 if (scalar(@pkgs) > 0) {
918 %limit_pkgs = map { ($_, 1) } @pkgs;
919 $limit{package} = [@pkgs];
920 print {$transcript} "Limiting to bugs with field 'package' containing at least one of ".join(', ',map {qq('$_')} @pkgs)."\n";
921 print {$transcript} "Limit currently set to";
922 for my $limit_field (keys %limit) {
923 print {$transcript} " '$limit_field':".join(', ',map {qq('$_')} @{$limit{$limit_field}})."\n";
925 print {$transcript} "\n";
928 $limit{package} = [];
929 print {$transcript} "Limit cleared.\n\n";
931 } elsif (m/^limit\:?\s+(\S.*\S)\s*$/) {
933 my ($field,@options) = split /\s+/, $1;
935 if ($field =~ /^(?:clear|unset|blank)$/) {
937 print {$transcript} "Limit cleared.\n\n";
939 elsif (exists $Debbugs::Status::fields{$field} or $field eq 'source') {
940 # %limit can actually contain regexes, but because they're
941 # not evaluated in Safe, DO NOT allow them through without
943 $limit{$field} = [@options];
944 print {$transcript} "Limiting to bugs with field '$field' containing at least one of ".join(', ',map {qq('$_')} @options)."\n";
945 print {$transcript} "Limit currently set to";
946 for my $limit_field (keys %limit) {
947 print {$transcript} " '$limit_field':".join(', ',map {qq('$_')} @{$limit{$limit_field}})."\n";
949 print {$transcript} "\n";
952 print {$transcript} "Limit key $field not understood. Stopping processing here.\n\n";
956 } elsif (m/^affects?\s+\#?(-?\d+)(?:\s+((?:[=+-])?)\s*(\S.*)?)?\s*$/i) {
959 my $add_remove = $2 || '';
960 my $packages = $3 || '';
961 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
963 affects(@common_control_options,
965 package => [splitpackages($3)],
966 ($add_remove eq '+'?(add => 1):()),
967 ($add_remove eq '-'?(remove => 1):()),
972 print {$transcript} "Failed to mark $ref as affecting package(s): ".cleanup_eval_fail($@,$debug)."\n";
975 } elsif (m/^summary\s+\#?(-?\d+)\s*(\d+|)\s*$/i) {
978 my $summary_msg = length($2)?$2:undef;
979 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
981 summary(@common_control_options,
983 summary => $summary_msg,
988 print {$transcript} "Failed to give $ref a summary: ".cleanup_eval_fail($@,$debug)."\n";
991 } elsif (m/^owner\s+\#?(-?\d+)\s+((?:\S.*\S)|\!)\s*$/i) {
994 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
996 if ($newowner eq '!') {
997 $newowner = $replyto;
1000 owner(@common_control_options,
1007 print {$transcript} "Failed to mark $ref as having an owner: ".cleanup_eval_fail($@,$debug)."\n";
1009 } elsif (m/^noowner\s+\#?(-?\d+)\s*$/i) {
1012 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
1014 owner(@common_control_options,
1021 print {$transcript} "Failed to mark $ref as not having an owner: ".cleanup_eval_fail($@,$debug)."\n";
1023 } elsif (m/^unarchive\s+#?(\d+)$/i) {
1026 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
1028 bug_unarchive(@common_control_options,
1030 recipients => \%recipients,
1036 } elsif (m/^archive\s+#?(\d+)$/i) {
1039 $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
1041 bug_archive(@common_control_options,
1044 archive_unarchived => 0,
1051 print {$transcript} "Unknown command or malformed arguments to command.\n\n";
1053 if (++$unknowns >= 5) {
1054 print {$transcript} "Too many unknown commands, stopping here.\n\n";
1059 if ($procline>$#bodylines) {
1060 print {$transcript} ">\nEnd of message, stopping processing here.\n\n";
1062 if (!$ok && !$quickabort) {
1064 print {$transcript} "No commands successfully parsed; sending the help text(s).\n";
1066 print {$transcript} "\n";
1069 my @maintccs = determine_recipients(recipients => \%recipients,
1073 my $maintccs = 'Cc: '.join(",\n ",
1074 determine_recipients(recipients => \%recipients,
1080 $packagepr = "X-${gProject}-PR-Package: " . join(keys %affected_packages) . "\n" if keys %affected_packages;
1082 # Add Bcc's to subscribed bugs
1083 # now handled by Debbugs::Recipients
1084 #push @bcc, map {"bugs=$_\@$gListDomain"} keys %bug_affected;
1086 if (!defined $header{'subject'} || $header{'subject'} eq "") {
1087 $header{'subject'} = "your mail";
1090 # Error text here advertises how many errors there were
1091 my $error_text = $errors > 0 ? " (with $errors errors)":'';
1094 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1096 ${maintccs}Subject: Processed${error_text}: $header{'subject'}
1097 In-Reply-To: $header{'message-id'}
1100 References: $header{'message-id'}
1101 Message-ID: <handler.s.$nn.transcript\@$gEmailDomain>
1103 ${packagepr}X-$gProject-PR-Message: transcript
1106 $reply .= fill_template('mail/message_body',
1107 {body => "${transcript_scalar}Please contact me if you need assistance."},
1110 my $repliedshow= join(', ',$replyto,
1111 determine_recipients(recipients => \%recipients,
1116 # -1 is the service.in log
1117 &filelock("lock/-1");
1118 open(AP,">>db-h/-1.log") || die "open db-h/-1.log: $!";
1120 "\2\n$repliedshow\n\5\n$reply\n\3\n".
1122 "<strong>Request received</strong> from <code>".
1123 html_escape($header{'from'})."</code>\n".
1124 "to <code>".html_escape($controlrequestaddr)."</code>\n".
1126 "\7\n",escape_log(@log),"\n\3\n") || die "writing db-h/-1.log: $!";
1127 close(AP) || die "open db-h/-1.log: $!";
1129 utime(time,time,"db-h");
1131 &sendmailmessage($reply,
1132 exists $header{'x-debbugs-no-ack'}?():$replyto,
1133 make_list(values %{{determine_recipients(recipients => \%recipients,
1139 unlink("incoming/P$nn") || die "unlinking incoming/P$nn: $!";
1141 sub sendmailmessage {
1142 my ($message,@recips) = @_;
1143 $message = "X-Loop: $gMaintainerEmail\n" . $message;
1144 send_mail_message(message => $message,
1145 recipients => \@recips,
1151 my ($template,$extra_var) = @_;
1153 my $variables = {config => \%config,
1154 defined($ref)?(ref => $ref):(),
1155 defined($data)?(data => $data):(),
1156 refs => [map {exists $clonebugs{$_}?$clonebugs{$_}:$_} keys %bug_affected],
1159 my $hole_var = {'&bugurl' =>
1161 'http://'.$config{cgi_domain}.'/'.
1162 Debbugs::CGI::bug_links(bug=>$_[0],
1167 return fill_in_template(template => $template,
1168 variables => $variables,
1169 hole_var => $hole_var,
1173 =head2 message_body_template
1175 message_body_template('mail/ack',{ref=>'foo'});
1177 Creates a message body using a template
1181 sub message_body_template{
1182 my ($template,$extra_var) = @_;
1184 my $body = fill_template($template,$extra_var);
1185 return fill_template('mail/message_body',
1194 &sendtxthelpraw("bug-maint-mailcontrol.txt","instructions for control\@$gEmailDomain")
1197 &sendtxthelpraw("bug-log-mailserver.txt","instructions for request\@$gEmailDomain");
1201 #sub unimplemented {
1202 # print {$transcript} "Sorry, command $_[0] not yet implemented.\n\n";
1204 our %checkmatch_values;
1206 my ($string,$mvarname,$svarvalue,@newmergelist) = @_;
1208 if (@newmergelist) {
1209 $mvarvalue = $checkmatch_values{$mvarname};
1210 print {$transcript} "D| checkmatch \`$string' /$mvarname/$mvarvalue/$svarvalue/\n"
1213 "Values for \`$string' don't match:\n".
1214 " #$newmergelist[0] has \`$mvarvalue';\n".
1215 " #$ref has \`$svarvalue'\n"
1216 if $mvarvalue ne $svarvalue;
1218 print {$transcript} "D| setupmatch \`$string' /$mvarname/$svarvalue/\n"
1220 $checkmatch_values{$mvarname} = $svarvalue;
1225 if (keys %limit_pkgs and not defined $limit_pkgs{$data->{package}}) {
1226 print {$transcript} "$gBug number $ref belongs to package $data->{package}, skipping.\n\n";
1238 my %h = map { $_ => 1 } split ' ', $list;
1245 return join ' ', sort keys %h;
1248 # High-level bug manipulation calls
1249 # Do announcements themselves
1251 # Possible calling sequences:
1252 # setbug (returns 0)
1254 # setbug (returns 1)
1255 # &transcript(something)
1258 # setbug (returns 1)
1259 # $action= (something)
1261 # (modify s_* variables)
1262 # } while (getnextbug);
1267 &dlen("nochangebug");
1268 $state eq 'single' || $state eq 'multiple' || die "$state ?";
1270 &endmerge if $manybugs;
1272 &dlex("nochangebug");
1276 our @thisbugmergelist;
1279 &dlen("setbug $ref");
1280 if ($ref =~ m/^-\d+/) {
1281 if (!defined $clonebugs{$ref}) {
1283 &dlex("setbug => noclone");
1286 $ref = $clonebugs{$ref};
1288 $state eq 'idle' || die "$state ?";
1291 &dlex("setbug => 0s");
1295 if (!&checkpkglimit) {
1300 @thisbugmergelist= split(/ /,$data->{mergedwith});
1301 if (!@thisbugmergelist) {
1306 &dlex("setbug => 1s");
1315 &dlex("setbug => 0mc");
1319 $state= 'multiple'; $sref=$ref;
1320 &dlex("setbug => 1m");
1325 &dlen("getnextbug");
1326 $state eq 'single' || $state eq 'multiple' || die "$state ?";
1328 if (!$manybugs || !@thisbugmergelist) {
1329 length($action) || die;
1330 print {$transcript} "$action\n$extramessage\n";
1331 &endmerge if $manybugs;
1333 &dlex("getnextbug => 0");
1336 $ref= shift(@thisbugmergelist);
1337 &getbug || die "bug $ref disappeared";
1339 &dlex("getnextbug => 1");
1343 # Low-level bug-manipulation calls
1344 # Do no announcements
1346 # getbug (returns 0)
1348 # getbug (returns 1)
1352 # $action= (something)
1353 # getbug (returns 1)
1355 # getbug (returns 1)
1357 # [getbug (returns 0)]
1358 # &transcript("$action\n\n")
1361 sub notfoundbug { print {$transcript} "$gBug number $ref not found. (Is it archived?)\n\n"; }
1362 sub foundbug { print {$transcript} "$gBug#$ref: $data->{subject}\n"; }
1366 $mergelowstate eq 'idle' || die "$mergelowstate ?";
1367 &filelock('lock/merge');
1368 $mergelowstate='locked';
1374 $mergelowstate eq 'locked' || die "$mergelowstate ?";
1376 $mergelowstate='idle';
1381 &dlen("getbug $ref");
1382 $lowstate eq 'idle' || die "$state ?";
1383 # Only use unmerged bugs here
1384 if (($data = &lockreadbug($ref,'db-h'))) {
1387 &dlex("getbug => 1");
1392 &dlex("getbug => 0");
1398 $lowstate eq 'open' || die "$state ?";
1405 &dlen("savebug $ref");
1406 $lowstate eq 'open' || die "$lowstate ?";
1407 length($action) || die;
1408 $ref == $sref || die "read $sref but saving $ref ?";
1409 append_action_to_log(bug => $ref,
1411 requester => $header{from},
1412 request_addr => $controlrequestaddr,
1416 unlockwritebug($ref, $data);
1423 print {$transcript} "C> @_ ($state $lowstate $mergelowstate)\n";
1428 print {$transcript} "R> @_ ($state $lowstate $mergelowstate)\n";
1435 my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
1436 $url =~ s/([<>&"])/\&$saniarray{$1};/g;
1442 print {$transcript} "\n";
1448 print {$transcript} "\n";
1454 sub sendtxthelpraw {
1455 my ($relpath,$description) = @_;
1457 if (not -e "$gDocDir/$relpath") {
1458 print {$transcript} "Unfortunatly, the help text doesn't exist, so it wasn't sent.\n";
1459 warn "Help text $gDocDir/$relpath not found";
1462 open(D,"$gDocDir/$relpath") || die "open doc file $relpath: $!";
1463 while(<D>) { $doc.=$_; }
1465 print {$transcript} "Sending $description in separate message.\n";
1466 &sendmailmessage(<<END.$doc,$replyto);
1467 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1469 Subject: $gProject $gBug help: $description
1470 References: $header{'message-id'}
1471 In-Reply-To: $header{'message-id'}
1472 Message-ID: <handler.s.$nn.help.$midix\@$gEmailDomain>
1474 X-$gProject-PR-Message: doc-text $relpath
1480 sub sendlynxdocraw {
1481 my ($relpath,$description) = @_;
1483 open(L,"lynx -nolist -dump http://$gCGIDomain/\Q$relpath\E 2>&1 |") || die "fork for lynx: $!";
1484 while(<L>) { $doc.=$_; }
1486 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1487 print {$transcript} "Information ($description) is not available -\n".
1488 "perhaps the $gBug does not exist or is not on the WWW yet.\n";
1491 print {$transcript} "Error getting $description (code $? $!):\n$doc\n";
1493 print {$transcript} "Sending $description.\n";
1494 &sendmailmessage(<<END.$doc,$replyto);
1495 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1497 Subject: $gProject $gBugs information: $description
1498 References: $header{'message-id'}
1499 In-Reply-To: $header{'message-id'}
1500 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1502 X-$gProject-PR-Message: doc-html $relpath
1511 my ($wherefrom,$path,$description) = @_;
1512 if ($wherefrom eq "ftp.d.o") {
1513 $doc = `lynx -nolist -dump http://ftp.debian.org/debian/indices/$path.gz 2>&1 | gunzip -cf` or die "fork for lynx/gunzip: $!";
1515 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1516 print {$transcript} "$description is not available.\n";
1519 print {$transcript} "Error getting $description (code $? $!):\n$doc\n";
1522 } elsif ($wherefrom eq "local") {
1524 $doc = do { local $/; <P> };
1527 print {$transcript} "internal errror: info files location unknown.\n";
1530 print {$transcript} "Sending $description.\n";
1531 &sendmailmessage(<<END.$doc,$replyto);
1532 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1534 Subject: $gProject $gBugs information: $description
1535 References: $header{'message-id'}
1536 In-Reply-To: $header{'message-id'}
1537 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1539 X-$gProject-PR-Message: getinfo
1541 $description follows:
1545 print {$transcript} "\n";