2 # $Id: service.in,v 1.64 2002/11/26 04:21:06 cjwatson Exp $
5 # Usage: service <code>.nn
6 # Temps: incoming/P<code>.nn
12 $config_path = '/etc/debbugs';
13 $lib_path = '/usr/lib/debbugs';
15 require "$config_path/config";
16 require "$lib_path/errorlib";
17 $ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
19 chdir("$gSpoolDir") || die "chdir spool: $!\n";
22 open DEBUG, ">/dev/null";
27 m/^[RC]\.\d+$/ || &quit("bad argument");
30 if (!rename("incoming/G$nn","incoming/P$nn")) {
31 $_=$!.''; m/no such file or directory/i && exit 0;
32 &quit("renaming to lock: $!");
35 open(M,"incoming/P$nn");
42 print "###\n",join("##\n",@msg),"\n###\n" if $debug;
44 my $parser = new MIME::Parser;
45 mkdir "$gSpoolDir/mime.tmp", 0777;
46 $parser->output_under("$gSpoolDir/mime.tmp");
47 my $entity = eval { $parser->parse_data(join('',@log)) };
49 # header and decoded body respectively
50 my (@headerlines, @bodylines);
52 if ($entity and $entity->head->tags) {
53 @headerlines = @{$entity->head->header};
56 my $entity_body = getmailbody($entity);
57 @bodylines = $entity_body ? $entity_body->as_lines() : ();
60 # Legacy pre-MIME code, kept around in case MIME::Parser fails.
62 for ($i = 0; $i <= $#msg; $i++) {
64 last unless length($_);
65 while ($msg[$i+1] =~ m/^\s/) {
69 push @headerlines, $_;
72 @bodylines = @msg[$i..$#msg];
77 print ">$_<\n" if $debug;
80 print ">$v=$_<\n" if $debug;
83 print "!>$_<\n" if $debug;
87 # Strip off RFC2440-style PGP clearsigning.
88 if (@bodylines and $bodylines[0] =~ /^-----BEGIN PGP SIGNED/) {
89 shift @bodylines while @bodylines and length $bodylines[0];
90 shift @bodylines while @bodylines and $bodylines[0] !~ /\S/;
91 for my $findsig (0 .. $#bodylines) {
92 if ($bodylines[$findsig] =~ /^-----BEGIN PGP SIGNATURE/) {
93 $#bodylines = $findsig - 1;
97 map { s/^- // } @bodylines;
100 grep(s/\s+$//,@bodylines);
102 print "***\n",join("\n",@bodylines),"\n***\n" if $debug;
104 if (defined $header{'resent-from'} && !defined $header{'from'}) {
105 $header{'from'} = $header{'resent-from'};
108 defined($header{'from'}) || &quit("no From header");
110 delete $header{'reply-to'}
111 if ( defined($header{'reply-to'}) && $header{'reply-to'} =~ m/^\s*$/ );
113 if ( defined($header{'reply-to'}) && $header{'reply-to'} ne "" ) {
114 $replyto = $header{'reply-to'};
116 $replyto = $header{'from'};
119 $controlrequestaddr= $control ? "control\@$gEmailDomain" : "request\@$gEmailDomain";
121 &transcript("Processing commands for $controlrequestaddr:\n\n");
126 $mergelowstate= 'idle';
132 my $fuckheads = "(" . join("|", @gFuckheads) . ")";
133 if (@gFuckheads and $replyto =~ m/$fuckheads/) {
134 &transcript("This service is unavailable.\n\n");
141 for ($procline=0; $procline<=$#bodylines; $procline++) {
142 $state eq 'idle' || print "$state ?\n";
143 $lowstate eq 'idle' || print "$lowstate ?\n";
144 $mergelowstate eq 'idle' || print "$mergelowstate ?\n";
146 &transcript("Stopping processing here.\n\n");
149 $_= $bodylines[$procline]; s/\s+$//;
150 next unless m/\S/; next if m/^\s*\#/;
151 &transcript("> $_\n");
153 if (m/^stop/i || m/^quit/i || m/^--/ || m/^thank/i) {
154 &transcript("Stopping processing here.\n\n");
156 } elsif (m/^debug\s+(\d+)$/i && $1 >= 0 && $1 <= 1000) {
158 &transcript("Debug level $dl.\n\n");
159 } elsif (m/^(send|get)\s+\#?(\d{2,})$/i) {
161 &sendlynxdoc("$ref","logs for $gBug#$ref");
162 } elsif (m/^send-detail\s+\#?(\d+)$/i) {
163 &transcript("This BTS function is currently disabled, sorry.\n\n");
164 $ok++; # well, it's not really ok, but it fixes #81224 :)
165 } elsif (m/^index(\s+full)?$/i) {
166 &transcript("This BTS function is currently disabled, sorry.\n\n");
167 $ok++; # well, it's not really ok, but it fixes #81224 :)
168 } elsif (m/^index-summary\s+by-package$/i) {
169 &transcript("This BTS function is currently disabled, sorry.\n\n");
170 $ok++; # well, it's not really ok, but it fixes #81224 :)
171 } elsif (m/^index-summary(\s+by-number)?$/i) {
172 &transcript("This BTS function is currently disabled, sorry.\n\n");
173 $ok++; # well, it's not really ok, but it fixes #81224 :)
174 } elsif (m/^index(\s+|-)pack(age)?s?$/i) {
175 &sendlynxdoc("cgi-bin/pkgindex.cgi?indexon=pkg",'index of packages');
176 } elsif (m/^index(\s+|-)maints?$/i) {
177 &sendlynxdoc("cgi-bin/pkgindex.cgi?indexon=maint",'index of maintainers');
178 } elsif (m/^index(\s+|-)maint\s+(\S+)$/i) {
180 # check for crap in $maint
181 if ($maint =~ m/^\./ || $maint !~ m/^[\d\w-+.@]+$/) {
182 &transcript("Invalid request $maint!\n");
185 &sendlynxdoc("$maint","$gBug list for maintainer \`$maint'");
187 } elsif (m/^index(\s+|-)pack(age)?s?\s+(\S.*\S)$/i) {
189 # check for crap in $package
190 if ($package =~ m/^\./ || $package !~ m/^[\d\w-+.@]+$/) {
191 &transcript("Invalid request $package!\n");
194 &sendlynxdoc("$package","$gBug list for package $package sent.\n\n");
196 } elsif (m/^send-unmatched(\s+this|\s+-?0)?$/i) {
197 &transcript("This BTS function is currently disabled, sorry.\n\n");
198 $ok++; # well, it's not really ok, but it fixes #81224 :)
199 } elsif (m/^send-unmatched\s+(last|-1)$/i) {
200 &transcript("This BTS function is currently disabled, sorry.\n\n");
201 $ok++; # well, it's not really ok, but it fixes #81224 :)
202 } elsif (m/^send-unmatched\s+(old|-2)$/i) {
203 &transcript("This BTS function is currently disabled, sorry.\n\n");
204 $ok++; # well, it's not really ok, but it fixes #81224 :)
205 } elsif (m/^getinfo\s+([\w-.]+)$/i) {
206 # the following is basically a Debian-specific kludge, but who cares
208 if ($req =~ /^maintainers$/i && -f "$gConfigDir/Maintainers") {
209 &sendinfo("local", "$gConfigDir/Maintainers", "Maintainers file");
210 } elsif ($req =~ /^override\.(\w+)\.([\w-.]+)$/i) {
212 &sendinfo("ftp.d.o", "$req", "override file for $2 part of $1 distribution");
213 } elsif ($req =~ /^pseudo-packages\.(description|maintainers)$/i && -f "$gConfigDir/$req") {
214 &sendinfo("local", "$gConfigDir/$req", "$req file");
216 &transcript("Info file $req does not exist.\n\n");
218 } elsif (m/^help/i) {
222 } elsif (m/^refcard/i) {
223 &sendtxthelp("bug-mailserver-refcard.txt","mail servers' reference card");
224 } elsif (m/^subscribe/i) {
226 There is no $gProject $gBug mailing list. If you wish to review bug reports
227 please do so via http://$gWebDomain/ or ask this mail server
229 soon: MAILINGLISTS_TEXT
231 } elsif (m/^unsubscribe/i) {
233 soon: UNSUBSCRIBE_TEXT
234 soon: MAILINGLISTS_TEXT
236 } elsif (!$control) {
238 Unknown command or malformed arguments to command.
239 (Use control\@$gEmailDomain to manipulate reports.)
242 if (++$unknowns >= 3) {
243 &transcript("Too many unknown commands, stopping here.\n\n");
246 #### interesting ones start here
247 } elsif (m/^close\s+\#?(-?\d+)$/i) {
251 if (length($s_done)) {
252 &transcript("$gBug is already closed, cannot re-close.\n\n");
255 $action= "$gBug closed, send any further explanations to $s_originator";
257 &addmaintainers($s_package);
258 if ( length( $gDoneList ) > 0 && length( $gListDomain ) >
259 0 ) { &addccaddress("$gDoneList\@$gListDomain"); }
262 From: $gMaintainerEmail ($gProject $gBug Tracking System)
264 Subject: $gBug#$ref acknowledged by developer
266 References: $header{'message-id'} $s_msgid
267 In-Reply-To: $s_msgid
268 Message-ID: <handler.$ref.$nn.notifdonectrl.$midix\@$gEmailDomain>
269 Reply-To: $ref\@$gEmailDomain
271 This is an automatic notification regarding your $gBug report
273 which was filed against the $s_package package.
275 It has been marked as closed by one of the developers, namely
278 You should be hearing from them with a substantive response shortly,
279 in case you haven't already. If not, please contact them directly.
282 (administrator, $gProject $gBugs database)
285 &sendmailmessage($message,$s_originator);
286 } while (&getnextbug);
289 } elsif (m/^reassign\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
291 $ref= $1; $newpackage= $2;
292 $newpackage =~ y/A-Z/a-z/;
294 if (length($s_package)) {
295 $action= "$gBug reassigned from package \`$s_package'".
296 " to \`$newpackage'.";
298 $action= "$gBug assigned to package \`$newpackage'.";
301 &addmaintainers($s_package);
302 &addmaintainers($newpackage);
303 $s_package= $newpackage;
304 } while (&getnextbug);
306 } elsif (m/^reopen\s+\#?(-?\d+)$/i ? ($noriginator='', 1) :
307 m/^reopen\s+\#?(-?\d+)\s+\=$/i ? ($noriginator='', 1) :
308 m/^reopen\s+\#?(-?\d+)\s+\!$/i ? ($noriginator=$replyto, 1) :
309 m/^reopen\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($noriginator=$2, 1) : 0) {
313 if (!length($s_done)) {
314 &transcript("$gBug is already open, cannot reopen.\n\n");
318 $noriginator eq '' ? "$gBug reopened, originator not changed." :
319 "$gBug reopened, originator set to $noriginator.";
321 &addmaintainers($s_package);
322 $s_originator= $noriginator eq '' ? $s_originator : $noriginator;
324 } while (&getnextbug);
327 } elsif (m/^submitter\s+\#?(-?\d+)\s+\!$/i ? ($newsubmitter=$replyto, 1) :
328 m/^submitter\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($newsubmitter=$2, 1) : 0) {
331 if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
332 $ref = $clonebugs{$ref};
336 &addmaintainers($s_package);
337 $oldsubmitter= $s_originator;
338 $s_originator= $newsubmitter;
339 $action= "Changed $gBug submitter.";
341 &transcript("$action\n");
342 if (length($s_done)) {
343 &transcript("(By the way, that $gBug is currently marked as done.)\n");
347 From: $gMaintainerEmail ($gProject $gBug Tracking System)
349 Subject: $gBug#$ref submitter address changed
351 References: $header{'message-id'} $s_msgid
352 In-Reply-To: $s_msgid
353 Message-ID: <handler.$ref.$nn.newsubmitter.$midix\@$gEmailDomain>
354 Reply-To: $ref\@$gEmailDomain
356 The submitter address recorded for your $gBug report
360 The new submitter address for this report is
363 This change was made by
365 If it was incorrect, please contact them directly.
368 (administrator, $gProject $gBugs database)
371 &sendmailmessage($message,$oldsubmitter);
375 } elsif (m/^forwarded\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
377 $ref= $1; $whereto= $2;
379 if (length($s_forwarded)) {
380 $action= "Forwarded-to-address changed from $s_forwarded to $whereto.";
382 $action= "Noted your statement that $gBug has been forwarded to $whereto.";
384 if (length($s_done)) {
385 $extramessage= "(By the way, this $gBug is currently marked as done.)\n";
388 &addmaintainers($s_package);
389 if (length($gFowardList)>0 && length($gListDomain)>0 ) {
390 &addccaddress("$gFowardList\@$gListDomain");
392 $s_forwarded= $whereto;
393 } while (&getnextbug);
395 } elsif (m/^notforwarded\s+\#?(-?\d+)$/i) {
399 if (!length($s_forwarded)) {
400 &transcript("$gBug is not marked as having been forwarded.\n\n");
403 $action= "Removed annotation that $gBug had been forwarded to $s_forwarded.";
405 &addmaintainers($s_package);
407 } while (&getnextbug);
410 } elsif (m/^severity\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i ||
411 m/^priority\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i) {
415 if (!grep($_ eq $newseverity, @gSeverityList, "$gDefaultSeverity")) {
416 &transcript("Severity level \`$newseverity' is not known.\n".
417 "Recognized are: $gShowSeverities.\n\n");
419 $printseverity= $s_severity;
420 $printseverity= "$gDefaultSeverity" if $printseverity eq '';
421 $action= "Severity set to \`$newseverity'.";
423 &addmaintainers($s_package);
424 $s_severity= $newseverity;
425 } while (&getnextbug);
427 } elsif (m/^tags?\s+\#?(-?\d+)\s+(([=+-])\s*)?(\S.*)?$/i) {
429 $ref = $1; $addsubcode = $3; $tags = $4;
431 if (defined $addsubcode) {
432 $addsub = "sub" if ($addsubcode eq "-");
433 $addsub = "add" if ($addsubcode eq "+");
434 $addsub = "set" if ($addsubcode eq "=");
438 foreach my $t (split /[\s,]+/, $tags) {
439 if (!grep($_ eq $t, @gTags)) {
446 &transcript("Unknown tag/s: ".join(', ', @badtags).".\n".
447 "Recognized are: ".join(' ', @gTags).".\n\n");
450 if ($s_keywords eq '') {
451 &transcript("There were no tags set.\n");
453 &transcript("Tags were: $s_keywords\n");
455 if ($addsub eq "set") {
456 $action= "Tags set to: " . join(", ", @okaytags);
457 } elsif ($addsub eq "add") {
458 $action= "Tags added: " . join(", ", @okaytags);
459 } elsif ($addsub eq "sub") {
460 $action= "Tags removed: " . join(", ", @okaytags);
463 &addmaintainers($s_package);
464 $s_keywords = '' if ($addsub eq "set");
465 if ($addsub eq "sub") {
466 foreach my $t (@badtags) {
467 $s_keywords = join ' ', grep $_ ne $t,
468 split ' ', $s_keywords;
471 foreach my $t (@okaytags) {
472 $s_keywords = join ' ', grep $_ ne $t,
473 split ' ', $s_keywords;
474 $s_keywords = "$t $s_keywords" unless($addsub eq "sub");
476 $s_keywords =~ s/\s*$//;
477 } while (&getnextbug);
479 } elsif (m/^retitle\s+\#?(-?\d+)\s+(\S.*\S)\s*$/i) {
481 $ref= $1; $newtitle= $2;
482 if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
483 $ref = $clonebugs{$ref};
487 &addmaintainers($s_package);
488 $s_subject= $newtitle;
489 $action= "Changed $gBug title.";
491 &transcript("$action\n");
492 if (length($s_done)) {
493 &transcript("(By the way, that $gBug is currently marked as done.)\n");
499 } elsif (m/^unmerge\s+\#?(-?\d+)$/i) {
503 if (!length($s_mergedwith)) {
504 &transcript("$gBug is not marked as being merged with any others.\n\n");
507 $mergelowstate eq 'locked' || die "$mergelowstate ?";
508 $action= "Disconnected #$ref from all other report(s).";
509 @newmergelist= split(/ /,$s_mergedwith);
512 &addmaintainers($s_package);
513 $s_mergedwith= ($ref == $discref) ? ''
514 : join(' ',grep($_ ne $ref,@newmergelist));
515 } while (&getnextbug);
518 } elsif (m/^merge\s+(\d+(\s+\d+)+)\s*$/i) {
520 @tomerge= sort { $a <=> $b } split(/\s+/,$1);
524 while (defined($ref= shift(@tomerge))) {
525 &transcript("D| checking merge $ref\n") if $dl;
527 next if grep($_ eq $ref,@newmergelist);
528 if (!&getbug) { ¬foundbug; @newmergelist=(); last }
530 &transcript("D| adding $ref ($s_mergedwith)\n") if $dl;
532 &checkmatch('package','m_package',$s_package);
533 &checkmatch('forwarded addr','m_forwarded',$s_forwarded);
534 $s_severity = '$gDefaultSeverity' if $s_severity eq '';
535 &checkmatch('severity','m_severity',$s_severity);
536 &checkmatch('done mark','m_done',length($s_done) ? 'done' : 'open');
537 foreach my $t (split /\s+/, $s_keywords) { $tags{$t} = 1; }
538 if (length($mismatch)) {
539 &transcript("Mismatch - only $gBugs in same state can be merged:\n".
541 &cancelbug; @newmergelist=(); last;
543 push(@newmergelist,$ref);
544 push(@tomerge,split(/ /,$s_mergedwith));
548 @newmergelist= sort { $a <=> $b } @newmergelist;
549 $action= "Merged @newmergelist.";
550 for $ref (@newmergelist) {
551 &getbug || die "huh ? $gBug $ref disappeared during merge";
552 &addmaintainers($s_package);
553 $s_mergedwith= join(' ',grep($_ ne $ref,@newmergelist));
554 $s_keywords= join(' ', keys %tags);
557 &transcript("$action\n\n");
560 } elsif (m/^clone\s+#?(\d+)\s+((-\d+\s+)*-\d+)\s*$/i) {
564 @newclonedids = split /\s+/, $2;
565 $newbugsneeded = scalar(@newclonedids);
569 if (length($s_mergedwith)) {
570 &transcript("$gBug is marked as being merged with others.\n\n");
573 &filelock("nextnumber.lock");
574 open(N,"nextnumber") || &quit("nextnumber: read: $!");
575 $v=<N>; $v =~ s/\n$// || &quit("nextnumber bad format");
576 $firstref= $v+0; $v += $newbugsneeded;
577 open(NN,">nextnumber"); print NN "$v\n"; close(NN);
580 $lastref = $firstref + $newbugsneeded - 1;
582 if ($newbugsneeded == 1) {
583 $action= "$gBug $origref cloned as bug $firstref.";
585 $action= "$gBug $origref cloned as bugs $firstref-$lastref.";
588 my $ohash = get_hashname($origref);
590 for $newclonedid (@newclonedids) {
591 $clonebugs{$newclonedid} = $ref;
593 my $hash = get_hashname($ref);
594 copy("db-h/$ohash/$origref.log", "db-h/$hash/$ref.log");
595 copy("db-h/$ohash/$origref.status", "db-h/$hash/$ref.status");
596 copy("db-h/$ohash/$origref.report", "db-h/$hash/$ref.report");
597 &bughook('new', $ref, "$s_originator\n$s_date\n$s_subject\n$s_msgid\n$s_package\n$s_keywords\n$s_done\n$s_forwarded\n$s_mergedwith\n$s_severity\n");
604 &transcript("Unknown command or malformed arguments to command.\n\n");
605 if (++$unknowns >= 5) {
606 &transcript("Too many unknown commands, stopping here.\n\n");
611 if ($procline>$#bodylines) {
612 &transcript(">\nEnd of message, stopping processing here.\n\n");
614 if (!$ok && !quickabort) {
615 &transcript("No commands successfully parsed; sending the help text(s).\n");
620 &transcript("MC\n") if $dl>1;
622 for $maint (keys %maintccreasons) {
623 &transcript("MM|$maint|\n") if $dl>1;
624 next if $maint eq $replyto;
626 $reasonsref= $maintccreasons{$maint};
627 &transcript("MY|$maint|\n") if $dl>2;
628 for $p (sort keys %$reasonsref) {
629 &transcript("MP|$p|\n") if $dl>2;
630 $reasonstring.= ', ' if length($reasonstring);
631 $reasonstring.= $p.' ' if length($p);
632 $reasonstring.= join(' ',map("#$_",sort keys %{$$reasonsref{$p}}));
634 if (length($reasonstring) > 40) {
635 (substr $reasonstring, 37) = "...";
637 $reasonstring = "" if (!defined($reasonstring));
638 push(@maintccs,"$maint ($reasonstring)");
639 push(@maintccaddrs,"$maint");
644 &transcript("MC|@maintccs|\n") if $dl>2;
645 $maintccs .= "Cc: " . join(",\n ",@maintccs) . "\n";
648 if (!defined $header{'subject'} || $header{'subject'} eq "") {
649 $header{'subject'} = "your mail";
653 From: $gMaintainerEmail ($gProject $gBug Tracking System)
655 ${maintccs}Subject: Processed: $header{'subject'}
656 In-Reply-To: $header{'message-id'}
657 References: $header{'message-id'}
658 Message-ID: <handler.s.$nn.transcript\@$gEmailDomain>
660 ${transcript}Please contact me if you need assistance.
663 (administrator, $gProject $gBugs database)
667 $repliedshow= join(', ',$replyto,@maintccaddrs);
668 &filelock("lock/-1");
669 open(AP,">>db-h/-1.log") || &quit("open db-h/-1.log: $!");
671 "\2\n$repliedshow\n\5\n$reply\n\3\n".
673 "<strong>Request received</strong> from <code>".
674 &sani($header{'from'})."</code>\n".
675 "to <code>".&sani($controlrequestaddr)."</code>\n".
677 "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/-1.log: $!");
678 close(AP) || &quit("open db-h/-1.log: $!");
680 utime(time,time,"db-h");
682 &sendmailmessage($reply,$replyto,@maintccaddrs,@bcc);
684 unlink("incoming/P$nn") || &quit("unlinking incoming/P$nn: $!");
688 map { $_->address() }
689 map { Mail::Address->parse($_) } @_;
692 sub sendmailmessage {
693 local ($message,@recips) = @_;
694 $message = "X-Loop: $gMaintainerEmail\n" . $message;
695 print "mailing to >@recips<\n" if $debug;
697 defined($c) || &quit("mailing forking for sendmail: $!");
698 if (!$c) { # ie, we are the child process
699 exec '/usr/lib/sendmail','-f'."$gMaintainerEmail",'-odb','-oem','-oi',get_addresses(@recips);
702 print(D $message) || &quit("writing to sendmail process: $!");
703 $!=0; close(D); $? && &quit("sendmail gave exit status $? ($!)");
708 &sendtxthelpraw("bug-log-mailserver.txt","instructions for request\@$gEmailDomain");
709 &sendtxthelpraw("bug-maint-mailcontrol.txt","instructions for control\@$gEmailDomain")
714 # &transcript("Sorry, command $_[0] not yet implemented.\n\n");
718 local ($string,$mvarname,$svarvalue) = @_;
721 eval "\$mvarvalue= \$$mvarname";
722 &transcript("D| checkmatch \`$string' /$mvarname/$mvarvalue/$svarvalue/\n")
725 "Values for \`$string' don't match:\n".
726 " #$newmergelist[0] has \`$mvarvalue';\n".
727 " #$ref has \`$svarvalue'\n"
728 if $mvarvalue ne $svarvalue;
730 &transcript("D| setupmatch \`$string' /$mvarname/$svarvalue/\n")
732 eval "\$$mvarname= \$svarvalue";
736 # High-level bug manipulation calls
737 # Do announcements themselves
739 # Possible calling sequences:
743 # &transcript(something)
747 # $action= (something)
749 # (modify s_* variables)
750 # } while (getnextbug);
753 &dlen("nochangebug");
754 $state eq 'single' || $state eq 'multiple' || die "$state ?";
756 &endmerge if $manybugs;
758 &dlex("nochangebug");
762 &dlen("setbug $ref");
763 if ($ref =~ m/^-\d+/) {
764 if (!defined $clonebugs{$ref}) {
766 &dlex("setbug => noclone");
769 $ref = $clonebugs{$ref};
771 $state eq 'idle' || die "$state ?";
774 &dlex("setbug => 0s");
777 @thisbugmergelist= split(/ /,$s_mergedwith);
778 if (!@thisbugmergelist) {
783 &dlex("setbug => 1s");
792 &dlex("setbug => 0mc");
796 $state= 'multiple'; $sref=$ref;
797 &dlex("setbug => 1m");
803 $state eq 'single' || $state eq 'multiple' || die "$state ?";
805 if (!$manybugs || !@thisbugmergelist) {
806 length($action) || die;
807 &transcript("$action\n$extramessage\n");
808 &endmerge if $manybugs;
810 &dlex("getnextbug => 0");
813 $ref= shift(@thisbugmergelist);
814 &getbug || die "bug $ref disappeared";
816 &dlex("getnextbug => 1");
820 # Low-level bug-manipulation calls
821 # Do no announcements
829 # $action= (something)
834 # [getbug (returns 0)]
835 # &transcript("$action\n\n")
838 sub notfoundbug { &transcript("$gBug number $ref not found.\n\n"); }
839 sub foundbug { &transcript("$gBug#$ref: $s_subject\n"); }
843 $mergelowstate eq 'idle' || die "$mergelowstate ?";
844 &filelock('lock/merge');
845 $mergelowstate='locked';
851 $mergelowstate eq 'locked' || die "$mergelowstate ?";
853 $mergelowstate='idle';
858 &dlen("getbug $ref");
859 $lowstate eq 'idle' || die "$state ?";
860 if (&lockreadbug($ref)) {
863 &dlex("getbug => 1");
868 &dlex("getbug => 0");
874 $lowstate eq 'open' || die "$state ?";
881 &dlen("savebug $ref");
882 $lowstate eq 'open' || die "$lowstate ?";
883 length($action) || die;
884 $ref == $sref || die "read $sref but saving $ref ?";
885 my $hash = get_hashname($ref);
886 open(L,">>db-h/$hash/$ref.log") || &quit("opening db-h/$hash/$ref.log: $!");
889 "<strong>".&sani($action)."</strong>\n".
890 "Request was from <code>".&sani($header{'from'})."</code>\n".
891 "to <code>".&sani($controlrequestaddr)."</code>. \n".
893 "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/$hash/$ref.log: $!");
894 close(L) || &quit("closing db-h/$hash/$ref.log: $!");
895 open(S,">db-h/$hash/$ref.status.new") || &quit("opening db-h/$hash/$ref.status.new: $!");
908 "$s_fixed_versions\n") || &quit("writing db-h/$hash/$ref.status.new: $!");
909 close(S) || &quit("closing db-h/$hash/$ref.status.new: $!");
910 rename("db-h/$hash/$ref.status.new","db-h/$hash/$ref.status") ||
911 &quit("installing new db-h/$hash/$ref.status: $!");
912 &bughook('change',$ref,
924 "$s_fixed_versions\n");
932 &transcript("C> @_ ($state $lowstate $mergelowstate)\n");
937 &transcript("R> @_ ($state $lowstate $mergelowstate)\n");
941 print $_[0] if $debug;
958 local ($relpath,$description) = @_;
960 open(D,"$gDocDir/$relpath") || &quit("open doc file $relpath: $!");
961 while(<D>) { $doc.=$_; }
963 &transcript("Sending $description in separate message.\n");
964 &sendmailmessage(<<END.$doc,$replyto);
965 From: $gMaintainerEmail ($gProject $gBug Tracking System)
967 Subject: $gProject $gBug help: $description
968 References: $header{'message-id'}
969 In-Reply-To: $header{'message-id'}
970 Message-ID: <handler.s.$nn.help.$midix\@$gEmailDomain>
977 local ($relpath,$description) = @_;
979 # the below oughta use $gWebDomain but it can't
980 open(L,"lynx -nolist -dump http://bugs.debian.org/$relpath 2>&1 |") || &quit("fork for lynx: $!");
981 while(<L>) { $doc.=$_; }
983 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
984 &transcript("Information ($description) is not available -\n".
985 "perhaps the $gBug does not exist or is not on the WWW yet.\n");
988 &transcript("Error getting $description (code $? $!):\n$doc\n");
990 &transcript("Sending $description.\n");
991 &sendmailmessage(<<END.$doc,$replyto);
992 From: $gMaintainerEmail ($gProject $gBug Tracking System)
994 Subject: $gProject $gBugs information: $description
995 References: $header{'message-id'}
996 In-Reply-To: $header{'message-id'}
997 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1006 $maintccreasons{$cca}{''}{$ref}= 1;
1009 sub addmaintainers {
1010 # Data structure is:
1011 # maintainer email address &c -> assoc of packages -> assoc of bug#'s
1012 my ($p, $addmaint, $pshow);
1013 &ensuremaintainersloaded;
1014 $anymaintfound=0; $anymaintnotfound=0;
1015 for $p (split(m/[ \t?,()]+/,$_[0])) {
1017 $pshow= ($p =~ m/[-+.a-z0-9]+/ ? $& : '');
1018 if (defined $gSubscriptionDomain) {
1019 if (defined($pkgsrc{$p})) {
1020 push @bcc, "$pkgsrc{$p}\@$gSubscriptionDomain";
1022 push @bcc, "$p\@$gSubscriptionDomain";
1025 if (defined($maintainerof{$p})) {
1026 $addmaint= $maintainerof{$p};
1027 &transcript("MR|$addmaint|$p|$ref|\n") if $dl>2;
1028 $maintccreasons{$addmaint}{$p}{$ref}= 1;
1029 print "maintainer add >$p|$addmaint<\n" if $debug;
1031 print "maintainer none >$p<\n" if $debug;
1032 &transcript("MR|unknown-package|$p|$ref|\n") if $dl>2;
1033 $maintccreasons{$gUnknownMaintainerEmail}{$p}{$ref}= 1;
1038 sub ensuremaintainersloaded {
1040 return if $maintainersloaded++;
1041 open(MAINT,"$gMaintainerFile") || die &quit("maintainers open: $!");
1045 m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers bogus \`$_'");
1046 $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
1047 $maintainerof{$1}= $2;
1050 open(MAINT,"$gMaintainerFileOverride") || die &quit("maintainers.override open: $!");
1054 m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers.override bogus \`$_'");
1055 $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
1056 $maintainerof{$1}= $2;
1059 open(SOURCES, "$gPackageSource") || &quit("pkgsrc open: $!");
1061 next unless m/^(\S+)\s+\S+\s+(\S.*\S)\s*$/;
1062 my ($a, $b) = ($1, $2);
1063 $pkgsrc{lc($a)} = $b;
1069 local ($wherefrom,$path,$description) = @_;
1070 if ($wherefrom eq "ftp.d.o") {
1071 $doc = `lynx -nolist -dump http://ftp.debian.org/debian/indices/$path.gz 2>&1 | gunzip -cf` or &quit("fork for lynx/gunzip: $!");
1073 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1074 &transcript("$description is not available.\n");
1077 &transcript("Error getting $description (code $? $!):\n$doc\n");
1080 } elsif ($wherefrom eq "local") {
1082 $doc = do { local $/; <P> };
1085 &transcript("internal errror: info files location unknown.\n");
1088 &transcript("Sending $description.\n");
1089 &sendmailmessage(<<END.$doc,$replyto);
1090 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1092 Subject: $gProject $gBugs information: $description
1093 References: $header{'message-id'}
1094 In-Reply-To: $header{'message-id'}
1095 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1097 $description follows: