2 # $Id: service.in,v 1.108 2005/07/29 04:34:11 don Exp $
4 # Usage: service <code>.nn
5 # Temps: incoming/P<code>.nn
9 use Debbugs::MIME qw(decode_rfc1522);
11 $config_path = '/etc/debbugs';
12 $lib_path = '/usr/lib/debbugs';
14 require "$config_path/config";
15 require "$lib_path/errorlib";
16 $ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
18 chdir("$gSpoolDir") || die "chdir spool: $!\n";
21 open DEBUG, ">/dev/null";
26 m/^[RC]\.\d+$/ || &quit("bad argument");
29 if (!rename("incoming/G$nn","incoming/P$nn")) {
30 $_=$!.''; m/no such file or directory/i && exit 0;
31 &quit("renaming to lock: $!");
34 open(M,"incoming/P$nn");
41 print "###\n",join("##\n",@msg),"\n###\n" if $debug;
43 my $parser = new MIME::Parser;
44 mkdir "$gSpoolDir/mime.tmp", 0777;
45 $parser->output_under("$gSpoolDir/mime.tmp");
46 my $entity = eval { $parser->parse_data(join('',@log)) };
48 # header and decoded body respectively
49 my (@headerlines, @bodylines);
50 # Bug numbers to send e-mail to, hash so that we don't send to the
54 if ($entity and $entity->head->tags) {
55 @headerlines = @{$entity->head->header};
58 my $entity_body = getmailbody($entity);
59 @bodylines = $entity_body ? $entity_body->as_lines() : ();
62 # Legacy pre-MIME code, kept around in case MIME::Parser fails.
64 for ($i = 0; $i <= $#msg; $i++) {
66 last unless length($_);
67 while ($msg[$i+1] =~ m/^\s/) {
71 push @headerlines, $_;
74 @bodylines = @msg[$i..$#msg];
79 print ">$_<\n" if $debug;
82 print ">$v=$_<\n" if $debug;
83 $header{$v} = decode_rfc1522($_);
85 print "!>$_<\n" if $debug;
89 # Strip off RFC2440-style PGP clearsigning.
90 if (@bodylines and $bodylines[0] =~ /^-----BEGIN PGP SIGNED/) {
91 shift @bodylines while @bodylines and length $bodylines[0];
92 shift @bodylines while @bodylines and $bodylines[0] !~ /\S/;
93 for my $findsig (0 .. $#bodylines) {
94 if ($bodylines[$findsig] =~ /^-----BEGIN PGP SIGNATURE/) {
95 $#bodylines = $findsig - 1;
99 map { s/^- // } @bodylines;
102 grep(s/\s+$//,@bodylines);
104 print "***\n",join("\n",@bodylines),"\n***\n" if $debug;
106 if (defined $header{'resent-from'} && !defined $header{'from'}) {
107 $header{'from'} = $header{'resent-from'};
110 defined($header{'from'}) || &quit("no From header");
112 delete $header{'reply-to'}
113 if ( defined($header{'reply-to'}) && $header{'reply-to'} =~ m/^\s*$/ );
115 if ( defined($header{'reply-to'}) && $header{'reply-to'} ne "" ) {
116 $replyto = $header{'reply-to'};
118 $replyto = $header{'from'};
121 $controlrequestaddr= $control ? "control\@$gEmailDomain" : "request\@$gEmailDomain";
123 &transcript("Processing commands for $controlrequestaddr:\n\n");
128 $mergelowstate= 'idle';
134 my $fuckheads = "(" . join("|", @gFuckheads) . ")";
135 if (@gFuckheads and $replyto =~ m/$fuckheads/) {
136 &transcript("This service is unavailable.\n\n");
145 push @bcc, $_[0] unless grep { $_ eq $_[0] } @bcc;
148 for ($procline=0; $procline<=$#bodylines; $procline++) {
149 $state eq 'idle' || print "$state ?\n";
150 $lowstate eq 'idle' || print "$lowstate ?\n";
151 $mergelowstate eq 'idle' || print "$mergelowstate ?\n";
153 &transcript("Stopping processing here.\n\n");
156 $_= $bodylines[$procline]; s/\s+$//;
158 &transcript("> $_\n");
161 if (m/^stop/i || m/^quit/i || m/^--/ || m/^thank/i) {
162 &transcript("Stopping processing here.\n\n");
164 } elsif (m/^debug\s+(\d+)$/i && $1 >= 0 && $1 <= 1000) {
166 &transcript("Debug level $dl.\n\n");
167 } elsif (m/^(send|get)\s+\#?(\d{2,})$/i) {
169 &sendlynxdoc("bugreport.cgi?bug=$ref","logs for $gBug#$ref");
170 } elsif (m/^send-detail\s+\#?(\d{2,})$/i) {
172 &sendlynxdoc("bugreport.cgi?bug=$ref&boring=yes",
173 "detailed logs for $gBug#$ref");
174 } elsif (m/^index(\s+full)?$/i) {
175 &transcript("This BTS function is currently disabled, sorry.\n\n");
176 $ok++; # well, it's not really ok, but it fixes #81224 :)
177 } elsif (m/^index-summary\s+by-package$/i) {
178 &transcript("This BTS function is currently disabled, sorry.\n\n");
179 $ok++; # well, it's not really ok, but it fixes #81224 :)
180 } elsif (m/^index-summary(\s+by-number)?$/i) {
181 &transcript("This BTS function is currently disabled, sorry.\n\n");
182 $ok++; # well, it's not really ok, but it fixes #81224 :)
183 } elsif (m/^index(\s+|-)pack(age)?s?$/i) {
184 &sendlynxdoc("pkgindex.cgi?indexon=pkg",'index of packages');
185 } elsif (m/^index(\s+|-)maints?$/i) {
186 &sendlynxdoc("pkgindex.cgi?indexon=maint",'index of maintainers');
187 } elsif (m/^index(\s+|-)maint\s+(\S+)$/i) {
189 &sendlynxdoc("pkgreport.cgi?maint=" . urlsanit($maint),
190 "$gBug list for maintainer \`$maint'");
192 } elsif (m/^index(\s+|-)pack(age)?s?\s+(\S.*\S)$/i) {
194 &sendlynxdoc("pkgreport.cgi?pkg=" . urlsanit($package),
195 "$gBug list for package $package");
197 } elsif (m/^send-unmatched(\s+this|\s+-?0)?$/i) {
198 &transcript("This BTS function is currently disabled, sorry.\n\n");
199 $ok++; # well, it's not really ok, but it fixes #81224 :)
200 } elsif (m/^send-unmatched\s+(last|-1)$/i) {
201 &transcript("This BTS function is currently disabled, sorry.\n\n");
202 $ok++; # well, it's not really ok, but it fixes #81224 :)
203 } elsif (m/^send-unmatched\s+(old|-2)$/i) {
204 &transcript("This BTS function is currently disabled, sorry.\n\n");
205 $ok++; # well, it's not really ok, but it fixes #81224 :)
206 } elsif (m/^getinfo\s+([\w-.]+)$/i) {
207 # the following is basically a Debian-specific kludge, but who cares
209 if ($req =~ /^maintainers$/i && -f "$gConfigDir/Maintainers") {
210 &sendinfo("local", "$gConfigDir/Maintainers", "Maintainers file");
211 } elsif ($req =~ /^override\.(\w+)\.([\w-.]+)$/i) {
213 &sendinfo("ftp.d.o", "$req", "override file for $2 part of $1 distribution");
214 } elsif ($req =~ /^pseudo-packages\.(description|maintainers)$/i && -f "$gConfigDir/$req") {
215 &sendinfo("local", "$gConfigDir/$req", "$req file");
217 &transcript("Info file $req does not exist.\n\n");
219 } elsif (m/^help/i) {
223 } elsif (m/^refcard/i) {
224 &sendtxthelp("bug-mailserver-refcard.txt","mail servers' reference card");
225 } elsif (m/^subscribe/i) {
227 There is no $gProject $gBug mailing list. If you wish to review bug reports
228 please do so via http://$gWebDomain/ or ask this mail server
230 soon: MAILINGLISTS_TEXT
232 } elsif (m/^unsubscribe/i) {
234 soon: UNSUBSCRIBE_TEXT
235 soon: MAILINGLISTS_TEXT
237 } elsif (!$control) {
239 Unknown command or malformed arguments to command.
240 (Use control\@$gEmailDomain to manipulate reports.)
243 if (++$unknowns >= 3) {
244 &transcript("Too many unknown commands, stopping here.\n\n");
247 #### interesting ones start here
248 } elsif (m/^close\s+\#?(-?\d+)(?:\s+(\d.*))?$/i) {
251 $bug_affected{$ref}=1;
254 &transcript("'close' is deprecated; see http://$gWebDomain/Developer$gHTMLSuffix#closing.\n");
255 if (length($data->{done}) and not defined($version)) {
256 &transcript("$gBug is already closed, cannot re-close.\n\n");
261 "marked as fixed in version $version" :
263 ", send any further explanations to $data->{originator}";
265 &addmaintainers($data);
266 if ( length( $gDoneList ) > 0 && length( $gListDomain ) >
267 0 ) { &addccaddress("$gDoneList\@$gListDomain"); }
268 $data->{done}= $replyto;
269 my @keywords= split ' ', $data->{keywords};
270 if (grep $_ eq 'pending', @keywords) {
271 $extramessage= "Removed pending tag.\n";
272 $data->{keywords}= join ' ', grep $_ ne 'pending',
275 addfixedversions($data, $data->{package}, $version, 'binary');
278 From: $gMaintainerEmail ($gProject $gBug Tracking System)
279 To: $data->{originator}
280 Subject: $gBug#$ref acknowledged by developer
282 References: $header{'message-id'} $data->{msgid}
283 In-Reply-To: $data->{msgid}
284 Message-ID: <handler.$ref.$nn.notifdonectrl.$midix\@$gEmailDomain>
285 Reply-To: $ref\@$gEmailDomain
286 X-$gProject-PR-Message: they-closed-control $ref
288 This is an automatic notification regarding your $gBug report
289 #$ref: $data->{subject},
290 which was filed against the $data->{package} package.
292 It has been marked as closed by one of the developers, namely
295 You should be hearing from them with a substantive response shortly,
296 in case you haven't already. If not, please contact them directly.
299 (administrator, $gProject $gBugs database)
302 &sendmailmessage($message,$data->{originator});
303 } while (&getnextbug);
306 } elsif (m/^reassign\s+\#?(-?\d+)\s+(\S+)(?:\s+(\d.*))?$/i) {
308 $ref= $1; $newpackage= $2;
309 $bug_affected{$ref}=1;
311 $newpackage =~ y/A-Z/a-z/;
313 if (length($data->{package})) {
314 $action= "$gBug reassigned from package \`$data->{package}'".
315 " to \`$newpackage'.";
317 $action= "$gBug assigned to package \`$newpackage'.";
320 &addmaintainers($data);
321 $data->{package}= $newpackage;
322 $data->{found_versions}= [];
323 $data->{fixed_versions}= [];
324 # TODO: what if $newpackage is a source package?
325 addfoundversions($data, $data->{package}, $version, 'binary');
326 &addmaintainers($data);
327 } while (&getnextbug);
329 } elsif (m/^reopen\s+\#?(-?\d+)$/i ? ($noriginator='', 1) :
330 m/^reopen\s+\#?(-?\d+)\s+\=$/i ? ($noriginator='', 1) :
331 m/^reopen\s+\#?(-?\d+)\s+\!$/i ? ($noriginator=$replyto, 1) :
332 m/^reopen\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($noriginator=$2, 1) : 0) {
335 $bug_affected{$ref}=1;
337 if (@{$data->{fixed_versions}}) {
338 &transcript("'reopen' is deprecated when a bug has been closed with a version;\nuse 'found' or 'submitter' as appropriate instead.\n");
340 if (!length($data->{done})) {
341 &transcript("$gBug is already open, cannot reopen.\n\n");
345 $noriginator eq '' ? "$gBug reopened, originator not changed." :
346 "$gBug reopened, originator set to $noriginator.";
348 &addmaintainers($data);
349 $data->{originator}= $noriginator eq '' ? $data->{originator} : $noriginator;
350 $data->{fixed_versions}= [];
352 } while (&getnextbug);
355 } elsif (m/^found\s+\#?(-?\d+)(?:\s+(\d.*))?$/i) {
360 if (!length($data->{done}) and not defined($version)) {
361 &transcript("$gBug is already open, cannot reopen.\n\n");
366 "$gBug marked as found in version $version." :
369 &addmaintainers($data);
370 # The 'done' field gets a bit weird with version
371 # tracking, because a bug may be closed by multiple
372 # people in different branches. Until we have something
373 # more flexible, we set it every time a bug is fixed,
374 # and clear it precisely when a found command is
375 # received for the rightmost fixed-in version, which
376 # equates to the most recent fixing of the bug, or when
377 # a versionless found command is received.
378 if (defined $version) {
380 (reverse @{$data->{fixed_versions}})[0];
381 # TODO: what if $data->{package} is a source package?
382 addfoundversions($data, $data->{package}, $version, 'binary');
383 if (defined $lastfixed and not grep { $_ eq $lastfixed } @{$data->{fixed_versions}}) {
387 # Versionless found; assume old-style "not fixed at
389 $data->{fixed_versions} = [];
392 } while (&getnextbug);
395 } elsif (m/^submitter\s+\#?(-?\d+)\s+\!$/i ? ($newsubmitter=$replyto, 1) :
396 m/^submitter\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($newsubmitter=$2, 1) : 0) {
399 $bug_affected{$ref}=1;
400 if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
401 $ref = $clonebugs{$ref};
404 if (&checkpkglimit) {
406 &addmaintainers($data);
407 $oldsubmitter= $data->{originator};
408 $data->{originator}= $newsubmitter;
409 $action= "Changed $gBug submitter from $oldsubmitter to $newsubmitter.";
411 &transcript("$action\n");
412 if (length($data->{done})) {
413 &transcript("(By the way, that $gBug is currently marked as done.)\n");
417 From: $gMaintainerEmail ($gProject $gBug Tracking System)
419 Subject: $gBug#$ref submitter address changed
421 References: $header{'message-id'} $data->{msgid}
422 In-Reply-To: $data->{msgid}
423 Message-ID: <handler.$ref.$nn.newsubmitter.$midix\@$gEmailDomain>
424 Reply-To: $ref\@$gEmailDomain
425 X-$gProject-PR-Message: submitter-changed $ref
427 The submitter address recorded for your $gBug report
428 #$ref: $data->{subject}
431 The new submitter address for this report is
434 This change was made by
436 If it was incorrect, please contact them directly.
439 (administrator, $gProject $gBugs database)
442 &sendmailmessage($message,$oldsubmitter);
449 } elsif (m/^forwarded\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
451 $ref= $1; $whereto= $2;
452 $bug_affected{$ref}=1;
454 if (length($data->{forwarded})) {
455 $action= "Forwarded-to-address changed from $data->{forwarded} to $whereto.";
457 $action= "Noted your statement that $gBug has been forwarded to $whereto.";
459 if (length($data->{done})) {
460 $extramessage= "(By the way, this $gBug is currently marked as done.)\n";
463 &addmaintainers($data);
464 if (length($gForwardList)>0 && length($gListDomain)>0 ) {
465 &addccaddress("$gForwardList\@$gListDomain");
467 $data->{forwarded}= $whereto;
468 } while (&getnextbug);
470 } elsif (m/^notforwarded\s+\#?(-?\d+)$/i) {
473 $bug_affected{$ref}=1;
475 if (!length($data->{forwarded})) {
476 &transcript("$gBug is not marked as having been forwarded.\n\n");
479 $action= "Removed annotation that $gBug had been forwarded to $data->{forwarded}.";
481 &addmaintainers($data);
482 $data->{forwarded}= '';
483 } while (&getnextbug);
486 } elsif (m/^severity\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i ||
487 m/^priority\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i) {
490 $bug_affected{$ref}=1;
492 if (!grep($_ eq $newseverity, @gSeverityList, "$gDefaultSeverity")) {
493 &transcript("Severity level \`$newseverity' is not known.\n".
494 "Recognized are: $gShowSeverities.\n\n");
495 } elsif (exists $gObsoleteSeverities{$newseverity}) {
496 &transcript("Severity level \`$newseverity' is obsolete. " .
497 "$gObsoleteSeverities{$newseverity}\n\n");
499 $printseverity= $data->{severity};
500 $printseverity= "$gDefaultSeverity" if $printseverity eq '';
501 $action= "Severity set to \`$newseverity' from \`$printseverity'";
503 &addmaintainers($data);
504 if (defined $gStrongList and isstrongseverity($newseverity)) {
505 addbcc("$gStrongList\@$gListDomain");
507 $data->{severity}= $newseverity;
508 } while (&getnextbug);
510 } elsif (m/^tags?\s+\#?(-?\d+)\s+(([=+-])\s*)?(\S.*)?$/i) {
512 $ref = $1; $addsubcode = $3; $tags = $4;
513 $bug_affected{$ref}=1;
515 if (defined $addsubcode) {
516 $addsub = "sub" if ($addsubcode eq "-");
517 $addsub = "add" if ($addsubcode eq "+");
518 $addsub = "set" if ($addsubcode eq "=");
522 foreach my $t (split /[\s,]+/, $tags) {
523 if (!grep($_ eq $t, @gTags)) {
530 &transcript("Unknown tag/s: ".join(', ', @badtags).".\n".
531 "Recognized are: ".join(' ', @gTags).".\n\n");
534 if ($data->{keywords} eq '') {
535 &transcript("There were no tags set.\n");
537 &transcript("Tags were: $data->{keywords}\n");
539 if ($addsub eq "set") {
540 $action= "Tags set to: " . join(", ", @okaytags);
541 } elsif ($addsub eq "add") {
542 $action= "Tags added: " . join(", ", @okaytags);
543 } elsif ($addsub eq "sub") {
544 $action= "Tags removed: " . join(", ", @okaytags);
547 &addmaintainers($data);
548 $data->{keywords} = '' if ($addsub eq "set");
549 # Allow removing obsolete tags.
550 if ($addsub eq "sub") {
551 foreach my $t (@badtags) {
552 $data->{keywords} = join ' ', grep $_ ne $t,
553 split ' ', $data->{keywords};
556 # Now process all other additions and subtractions.
557 foreach my $t (@okaytags) {
558 $data->{keywords} = join ' ', grep $_ ne $t,
559 split ' ', $data->{keywords};
560 $data->{keywords} = "$t $data->{keywords}" unless($addsub eq "sub");
562 $data->{keywords} =~ s/\s*$//;
563 } while (&getnextbug);
565 } elsif (m/^retitle\s+\#?(-?\d+)\s+(\S.*\S)\s*$/i) {
567 $ref= $1; $newtitle= $2;
568 $bug_affected{$ref}=1;
569 if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
570 $ref = $clonebugs{$ref};
573 if (&checkpkglimit) {
575 &addmaintainers($data);
576 $data->{subject}= $newtitle;
577 $action= "Changed $gBug title.";
579 &transcript("$action\n");
580 if (length($data->{done})) {
581 &transcript("(By the way, that $gBug is currently marked as done.)\n");
590 } elsif (m/^unmerge\s+\#?(-?\d+)$/i) {
593 $bug_affected{$ref} = 1;
595 if (!length($data->{mergedwith})) {
596 &transcript("$gBug is not marked as being merged with any others.\n\n");
599 $mergelowstate eq 'locked' || die "$mergelowstate ?";
600 $action= "Disconnected #$ref from all other report(s).";
601 @newmergelist= split(/ /,$data->{mergedwith});
603 @bug_affected{@newmergelist} = 1 x @newmergelist;
605 &addmaintainers($data);
606 $data->{mergedwith}= ($ref == $discref) ? ''
607 : join(' ',grep($_ ne $ref,@newmergelist));
608 } while (&getnextbug);
611 } elsif (m/^merge\s+#?(-?\d+(\s+#?-?\d+)+)\s*$/i) {
613 @tomerge= sort { $a <=> $b } split(/\s+#?/,$1);
619 while (defined($ref= shift(@tomerge))) {
620 &transcript("D| checking merge $ref\n") if $dl;
622 if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
623 $ref = $clonebugs{$ref};
625 next if grep($_ eq $ref,@newmergelist);
626 if (!&getbug) { ¬foundbug; @newmergelist=(); last }
627 if (!&checkpkglimit) { &cancelbug; @newmergelist=(); last; }
629 &transcript("D| adding $ref ($data->{mergedwith})\n") if $dl;
631 &checkmatch('package','m_package',$data->{package});
632 &checkmatch('forwarded addr','m_forwarded',$data->{forwarded});
633 $data->{severity} = '$gDefaultSeverity' if $data->{severity} eq '';
634 &checkmatch('severity','m_severity',$data->{severity});
635 &checkmatch('done mark','m_done',length($data->{done}) ? 'done' : 'open');
636 &checkmatch('owner','m_owner',$data->{owner});
637 foreach my $t (split /\s+/, $data->{keywords}) { $tags{$t} = 1; }
638 foreach my $f (@{$data->{found_versions}}) { $found{$f} = 1; }
639 foreach my $f (@{$data->{fixed_versions}}) { $fixed{$f} = 1; }
640 if (length($mismatch)) {
641 &transcript("Mismatch - only $gBugs in same state can be merged:\n".
643 &cancelbug; @newmergelist=(); last;
645 push(@newmergelist,$ref);
646 push(@tomerge,split(/ /,$data->{mergedwith}));
650 @newmergelist= sort { $a <=> $b } @newmergelist;
651 $action= "Merged @newmergelist.";
652 delete @fixed{keys %found};
653 for $ref (@newmergelist) {
654 &getbug || die "huh ? $gBug $ref disappeared during merge";
655 &addmaintainers($data);
656 @bug_affected{@newmergelist} = 1 x @newmergelist;
657 $data->{mergedwith}= join(' ',grep($_ ne $ref,@newmergelist));
658 $data->{keywords}= join(' ', keys %tags);
659 $data->{found_versions}= [sort keys %found];
660 $data->{fixed_versions}= [sort keys %fixed];
663 &transcript("$action\n\n");
666 } elsif (m/^clone\s+#?(\d+)\s+((-\d+\s+)*-\d+)\s*$/i) {
670 @newclonedids = split /\s+/, $2;
671 $newbugsneeded = scalar(@newclonedids);
674 $bug_affected{$ref} = 1;
676 if (length($data->{mergedwith})) {
677 &transcript("$gBug is marked as being merged with others.\n\n");
680 &filelock("nextnumber.lock");
681 open(N,"nextnumber") || &quit("nextnumber: read: $!");
682 $v=<N>; $v =~ s/\n$// || &quit("nextnumber bad format");
683 $firstref= $v+0; $v += $newbugsneeded;
684 open(NN,">nextnumber"); print NN "$v\n"; close(NN);
687 $lastref = $firstref + $newbugsneeded - 1;
689 if ($newbugsneeded == 1) {
690 $action= "$gBug $origref cloned as bug $firstref.";
692 $action= "$gBug $origref cloned as bugs $firstref-$lastref.";
695 my $ohash = get_hashname($origref);
697 @bug_affected{@newclonedids} = 1 x @newclonedids;
698 for $newclonedid (@newclonedids) {
699 $clonebugs{$newclonedid} = $ref;
701 my $hash = get_hashname($ref);
702 copy("db-h/$ohash/$origref.log", "db-h/$hash/$ref.log");
703 copy("db-h/$ohash/$origref.status", "db-h/$hash/$ref.status");
704 copy("db-h/$ohash/$origref.summary", "db-h/$hash/$ref.summary");
705 copy("db-h/$ohash/$origref.report", "db-h/$hash/$ref.report");
706 &bughook('new', $ref, $data);
712 } elsif (m/^package\s+(\S.*\S)?\s*$/i) {
714 my @pkgs = split /\s+/, $1;
715 if (scalar(@pkgs) > 0) {
716 %limit_pkgs = map { ($_, 1) } @pkgs;
717 &transcript("Ignoring bugs not assigned to: " .
718 join(" ", keys(%limit_pkgs)) . "\n\n");
721 &transcript("Not ignoring any bugs.\n\n");
723 } elsif (m/^owner\s+\#?(-?\d+)\s+!$/i ? ($newowner = $replyto, 1) :
724 m/^owner\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($newowner = $2, 1) : 0) {
727 $bug_affected{$ref} = 1;
729 if (length $data->{owner}) {
730 $action = "Owner changed from $data->{owner} to $newowner.";
732 $action = "Owner recorded as $newowner.";
734 if (length $data->{done}) {
735 $extramessage = "(By the way, this $gBug is currently " .
736 "marked as done.)\n";
739 &addmaintainers($data);
740 $data->{owner} = $newowner;
741 } while (&getnextbug);
743 } elsif (m/^noowner\s+\#?(-?\d+)$/i) {
746 $bug_affected{$ref} = 1;
748 if (length $data->{owner}) {
749 $action = "Removed annotation that $gBug was owned by " .
752 &addmaintainers($data);
754 } while (&getnextbug);
756 &transcript("$gBug is not marked as having an owner.\n\n");
761 &transcript("Unknown command or malformed arguments to command.\n\n");
762 if (++$unknowns >= 5) {
763 &transcript("Too many unknown commands, stopping here.\n\n");
768 if ($procline>$#bodylines) {
769 &transcript(">\nEnd of message, stopping processing here.\n\n");
771 if (!$ok && !quickabort) {
772 &transcript("No commands successfully parsed; sending the help text(s).\n");
777 &transcript("MC\n") if $dl>1;
779 for $maint (keys %maintccreasons) {
780 &transcript("MM|$maint|\n") if $dl>1;
781 next if $maint eq $replyto;
783 $reasonsref= $maintccreasons{$maint};
784 &transcript("MY|$maint|\n") if $dl>2;
785 for $p (sort keys %$reasonsref) {
786 &transcript("MP|$p|\n") if $dl>2;
787 $reasonstring.= ', ' if length($reasonstring);
788 $reasonstring.= $p.' ' if length($p);
789 $reasonstring.= join(' ',map("#$_",sort keys %{$$reasonsref{$p}}));
791 if (length($reasonstring) > 40) {
792 (substr $reasonstring, 37) = "...";
794 $reasonstring = "" if (!defined($reasonstring));
795 push(@maintccs,"$maint ($reasonstring)");
796 push(@maintccaddrs,"$maint");
801 &transcript("MC|@maintccs|\n") if $dl>2;
802 $maintccs .= "Cc: " . join(",\n ",@maintccs) . "\n";
805 # Add Bcc's to subscribed bugs
806 push @bcc, map {"bugs=$_\@$gListDomain"} keys %bug_affected;
808 if (!defined $header{'subject'} || $header{'subject'} eq "") {
809 $header{'subject'} = "your mail";
813 From: $gMaintainerEmail ($gProject $gBug Tracking System)
815 ${maintccs}Subject: Processed: $header{'subject'}
816 In-Reply-To: $header{'message-id'}
817 References: $header{'message-id'}
818 Message-ID: <handler.s.$nn.transcript\@$gEmailDomain>
820 X-$gProject-PR-Message: transcript
822 ${transcript}Please contact me if you need assistance.
825 (administrator, $gProject $gBugs database)
829 $repliedshow= join(', ',$replyto,@maintccaddrs);
830 &filelock("lock/-1");
831 open(AP,">>db-h/-1.log") || &quit("open db-h/-1.log: $!");
833 "\2\n$repliedshow\n\5\n$reply\n\3\n".
835 "<strong>Request received</strong> from <code>".
836 &sani($header{'from'})."</code>\n".
837 "to <code>".&sani($controlrequestaddr)."</code>\n".
839 "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/-1.log: $!");
840 close(AP) || &quit("open db-h/-1.log: $!");
842 utime(time,time,"db-h");
844 &sendmailmessage($reply,$replyto,@maintccaddrs,@bcc);
846 unlink("incoming/P$nn") || &quit("unlinking incoming/P$nn: $!");
848 sub sendmailmessage {
849 local ($message,@recips) = @_;
850 $message = "X-Loop: $gMaintainerEmail\n" . $message;
851 print "mailing to >@recips<\n" if $debug;
853 defined($c) || &quit("mailing forking for sendmail: $!");
854 if (!$c) { # ie, we are the child process
855 exec '/usr/lib/sendmail','-f'."$gMaintainerEmail",'-odb','-oem','-oi',get_addresses(@recips);
858 print(D $message) || &quit("writing to sendmail process: $!");
859 $!=0; close(D); $? && &quit("sendmail gave exit status $? ($!)");
864 &sendtxthelpraw("bug-log-mailserver.txt","instructions for request\@$gEmailDomain");
865 &sendtxthelpraw("bug-maint-mailcontrol.txt","instructions for control\@$gEmailDomain")
870 # &transcript("Sorry, command $_[0] not yet implemented.\n\n");
874 local ($string,$mvarname,$svarvalue) = @_;
877 eval "\$mvarvalue= \$$mvarname";
878 &transcript("D| checkmatch \`$string' /$mvarname/$mvarvalue/$svarvalue/\n")
881 "Values for \`$string' don't match:\n".
882 " #$newmergelist[0] has \`$mvarvalue';\n".
883 " #$ref has \`$svarvalue'\n"
884 if $mvarvalue ne $svarvalue;
886 &transcript("D| setupmatch \`$string' /$mvarname/$svarvalue/\n")
888 eval "\$$mvarname= \$svarvalue";
893 if (keys %limit_pkgs and not defined $limit_pkgs{$data->{package}}) {
894 &transcript("$gBug number $ref belongs to package $data->{package}, skipping.\n\n");
900 # High-level bug manipulation calls
901 # Do announcements themselves
903 # Possible calling sequences:
907 # &transcript(something)
911 # $action= (something)
913 # (modify s_* variables)
914 # } while (getnextbug);
917 &dlen("nochangebug");
918 $state eq 'single' || $state eq 'multiple' || die "$state ?";
920 &endmerge if $manybugs;
922 &dlex("nochangebug");
926 &dlen("setbug $ref");
927 if ($ref =~ m/^-\d+/) {
928 if (!defined $clonebugs{$ref}) {
930 &dlex("setbug => noclone");
933 $ref = $clonebugs{$ref};
935 $state eq 'idle' || die "$state ?";
938 &dlex("setbug => 0s");
942 if (!&checkpkglimit) {
947 @thisbugmergelist= split(/ /,$data->{mergedwith});
948 if (!@thisbugmergelist) {
953 &dlex("setbug => 1s");
962 &dlex("setbug => 0mc");
966 $state= 'multiple'; $sref=$ref;
967 &dlex("setbug => 1m");
973 $state eq 'single' || $state eq 'multiple' || die "$state ?";
975 if (!$manybugs || !@thisbugmergelist) {
976 length($action) || die;
977 &transcript("$action\n$extramessage\n");
978 &endmerge if $manybugs;
980 &dlex("getnextbug => 0");
983 $ref= shift(@thisbugmergelist);
984 &getbug || die "bug $ref disappeared";
986 &dlex("getnextbug => 1");
990 # Low-level bug-manipulation calls
991 # Do no announcements
999 # $action= (something)
1000 # getbug (returns 1)
1002 # getbug (returns 1)
1004 # [getbug (returns 0)]
1005 # &transcript("$action\n\n")
1008 sub notfoundbug { &transcript("$gBug number $ref not found.\n\n"); }
1009 sub foundbug { &transcript("$gBug#$ref: $data->{subject}\n"); }
1013 $mergelowstate eq 'idle' || die "$mergelowstate ?";
1014 &filelock('lock/merge');
1015 $mergelowstate='locked';
1021 $mergelowstate eq 'locked' || die "$mergelowstate ?";
1023 $mergelowstate='idle';
1028 &dlen("getbug $ref");
1029 $lowstate eq 'idle' || die "$state ?";
1030 if (($data = &lockreadbug($ref))) {
1033 &dlex("getbug => 1");
1038 &dlex("getbug => 0");
1044 $lowstate eq 'open' || die "$state ?";
1051 &dlen("savebug $ref");
1052 $lowstate eq 'open' || die "$lowstate ?";
1053 length($action) || die;
1054 $ref == $sref || die "read $sref but saving $ref ?";
1055 my $hash = get_hashname($ref);
1056 open(L,">>db-h/$hash/$ref.log") || &quit("opening db-h/$hash/$ref.log: $!");
1059 "<strong>".&sani($action)."</strong>\n".
1060 "Request was from <code>".&sani($header{'from'})."</code>\n".
1061 "to <code>".&sani($controlrequestaddr)."</code>. \n".
1063 "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/$hash/$ref.log: $!");
1064 close(L) || &quit("closing db-h/$hash/$ref.log: $!");
1065 unlockwritebug($ref, $data);
1072 &transcript("C> @_ ($state $lowstate $mergelowstate)\n");
1077 &transcript("R> @_ ($state $lowstate $mergelowstate)\n");
1081 print $_[0] if $debug;
1082 $transcript.= $_[0];
1089 my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
1090 $url =~ s/([<>&"])/\&$saniarray{$1};/g;
1106 sub sendtxthelpraw {
1107 local ($relpath,$description) = @_;
1109 open(D,"$gDocDir/$relpath") || &quit("open doc file $relpath: $!");
1110 while(<D>) { $doc.=$_; }
1112 &transcript("Sending $description in separate message.\n");
1113 &sendmailmessage(<<END.$doc,$replyto);
1114 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1116 Subject: $gProject $gBug help: $description
1117 References: $header{'message-id'}
1118 In-Reply-To: $header{'message-id'}
1119 Message-ID: <handler.s.$nn.help.$midix\@$gEmailDomain>
1121 X-$gProject-PR-Message: doc-text $relpath
1127 sub sendlynxdocraw {
1128 local ($relpath,$description) = @_;
1130 open(L,"lynx -nolist -dump http://$gCGIDomain/\Q$relpath\E 2>&1 |") || &quit("fork for lynx: $!");
1131 while(<L>) { $doc.=$_; }
1133 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1134 &transcript("Information ($description) is not available -\n".
1135 "perhaps the $gBug does not exist or is not on the WWW yet.\n");
1138 &transcript("Error getting $description (code $? $!):\n$doc\n");
1140 &transcript("Sending $description.\n");
1141 &sendmailmessage(<<END.$doc,$replyto);
1142 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1144 Subject: $gProject $gBugs information: $description
1145 References: $header{'message-id'}
1146 In-Reply-To: $header{'message-id'}
1147 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1149 X-$gProject-PR-Message: doc-html $relpath
1158 $maintccreasons{$cca}{''}{$ref}= 1;
1161 sub addmaintainers {
1162 # Data structure is:
1163 # maintainer email address &c -> assoc of packages -> assoc of bug#'s
1166 &ensuremaintainersloaded;
1167 $anymaintfound=0; $anymaintnotfound=0;
1168 for $p (split(m/[ \t?,():]+/, $data->{package})) {
1170 $p =~ /([a-z0-9.+-]+)/;
1172 next unless defined $p;
1173 if (defined $gSubscriptionDomain) {
1174 if (defined($pkgsrc{$p})) {
1175 addbcc("$pkgsrc{$p}\@$gSubscriptionDomain");
1177 addbcc("$p\@$gSubscriptionDomain");
1180 if (defined $data->{severity} and defined $gStrongList and
1181 isstrongseverity($data->{severity})) {
1182 addbcc("$gStrongList\@$gListDomain");
1184 if (defined($maintainerof{$p})) {
1185 $addmaint= $maintainerof{$p};
1186 &transcript("MR|$addmaint|$p|$ref|\n") if $dl>2;
1187 $maintccreasons{$addmaint}{$p}{$ref}= 1;
1188 print "maintainer add >$p|$addmaint<\n" if $debug;
1190 print "maintainer none >$p<\n" if $debug;
1191 &transcript("Warning: Unknown package '$p'\n");
1192 &transcript("MR|unknown-package|$p|$ref|\n") if $dl>2;
1193 $maintccreasons{$gUnknownMaintainerEmail}{$p}{$ref}= 1;
1197 if (length $data->{owner}) {
1198 $addmaint = $data->{owner};
1199 &transcript("MO|$addmaint|$data->{package}|$ref|\n") if $dl>2;
1200 $maintccreasons{$addmaint}{$data->{package}}{$ref} = 1;
1201 print "owner add >$data->{package}|$addmaint<\n" if $debug;
1205 sub ensuremaintainersloaded {
1207 return if $maintainersloaded++;
1208 open(MAINT,"$gMaintainerFile") || die &quit("maintainers open: $!");
1212 m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers bogus \`$_'");
1213 $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
1214 $maintainerof{$1}= $2;
1217 open(MAINT,"$gMaintainerFileOverride") || die &quit("maintainers.override open: $!");
1221 m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers.override bogus \`$_'");
1222 $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
1223 $maintainerof{$1}= $2;
1226 open(SOURCES, "$gPackageSource") || &quit("pkgsrc open: $!");
1228 next unless m/^(\S+)\s+\S+\s+(\S.*\S)\s*$/;
1229 my ($a, $b) = ($1, $2);
1230 $pkgsrc{lc($a)} = $b;
1236 local ($wherefrom,$path,$description) = @_;
1237 if ($wherefrom eq "ftp.d.o") {
1238 $doc = `lynx -nolist -dump http://ftp.debian.org/debian/indices/$path.gz 2>&1 | gunzip -cf` or &quit("fork for lynx/gunzip: $!");
1240 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1241 &transcript("$description is not available.\n");
1244 &transcript("Error getting $description (code $? $!):\n$doc\n");
1247 } elsif ($wherefrom eq "local") {
1249 $doc = do { local $/; <P> };
1252 &transcript("internal errror: info files location unknown.\n");
1255 &transcript("Sending $description.\n");
1256 &sendmailmessage(<<END.$doc,$replyto);
1257 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1259 Subject: $gProject $gBugs information: $description
1260 References: $header{'message-id'}
1261 In-Reply-To: $header{'message-id'}
1262 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1264 X-$gProject-PR-Message: getinfo
1266 $description follows: