2 # $Id: service.in,v 1.70 2003/03/10 00:10:52 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+$//;
151 &transcript("> $_\n");
154 if (m/^stop/i || m/^quit/i || m/^--/ || m/^thank/i) {
155 &transcript("Stopping processing here.\n\n");
157 } elsif (m/^debug\s+(\d+)$/i && $1 >= 0 && $1 <= 1000) {
159 &transcript("Debug level $dl.\n\n");
160 } elsif (m/^(send|get)\s+\#?(\d{2,})$/i) {
162 &sendlynxdoc("bugreport.cgi?bug=$ref","logs for $gBug#$ref");
163 } elsif (m/^send-detail\s+\#?(\d+)$/i) {
164 &transcript("This BTS function is currently disabled, sorry.\n\n");
165 $ok++; # well, it's not really ok, but it fixes #81224 :)
166 } elsif (m/^index(\s+full)?$/i) {
167 &transcript("This BTS function is currently disabled, sorry.\n\n");
168 $ok++; # well, it's not really ok, but it fixes #81224 :)
169 } elsif (m/^index-summary\s+by-package$/i) {
170 &transcript("This BTS function is currently disabled, sorry.\n\n");
171 $ok++; # well, it's not really ok, but it fixes #81224 :)
172 } elsif (m/^index-summary(\s+by-number)?$/i) {
173 &transcript("This BTS function is currently disabled, sorry.\n\n");
174 $ok++; # well, it's not really ok, but it fixes #81224 :)
175 } elsif (m/^index(\s+|-)pack(age)?s?$/i) {
176 &sendlynxdoc("pkgindex.cgi?indexon=pkg",'index of packages');
177 } elsif (m/^index(\s+|-)maints?$/i) {
178 &sendlynxdoc("pkgindex.cgi?indexon=maint",'index of maintainers');
179 } elsif (m/^index(\s+|-)maint\s+(\S+)$/i) {
181 &sendlynxdoc("pkgreport.cgi?maint=" . urlsanit($maint),
182 "$gBug list for maintainer \`$maint'");
184 } elsif (m/^index(\s+|-)pack(age)?s?\s+(\S.*\S)$/i) {
186 &sendlynxdoc("pkgreport.cgi?pkg=" . urlsanit($package),
187 "$gBug list for package $package");
189 } elsif (m/^send-unmatched(\s+this|\s+-?0)?$/i) {
190 &transcript("This BTS function is currently disabled, sorry.\n\n");
191 $ok++; # well, it's not really ok, but it fixes #81224 :)
192 } elsif (m/^send-unmatched\s+(last|-1)$/i) {
193 &transcript("This BTS function is currently disabled, sorry.\n\n");
194 $ok++; # well, it's not really ok, but it fixes #81224 :)
195 } elsif (m/^send-unmatched\s+(old|-2)$/i) {
196 &transcript("This BTS function is currently disabled, sorry.\n\n");
197 $ok++; # well, it's not really ok, but it fixes #81224 :)
198 } elsif (m/^getinfo\s+([\w-.]+)$/i) {
199 # the following is basically a Debian-specific kludge, but who cares
201 if ($req =~ /^maintainers$/i && -f "$gConfigDir/Maintainers") {
202 &sendinfo("local", "$gConfigDir/Maintainers", "Maintainers file");
203 } elsif ($req =~ /^override\.(\w+)\.([\w-.]+)$/i) {
205 &sendinfo("ftp.d.o", "$req", "override file for $2 part of $1 distribution");
206 } elsif ($req =~ /^pseudo-packages\.(description|maintainers)$/i && -f "$gConfigDir/$req") {
207 &sendinfo("local", "$gConfigDir/$req", "$req file");
209 &transcript("Info file $req does not exist.\n\n");
211 } elsif (m/^help/i) {
215 } elsif (m/^refcard/i) {
216 &sendtxthelp("bug-mailserver-refcard.txt","mail servers' reference card");
217 } elsif (m/^subscribe/i) {
219 There is no $gProject $gBug mailing list. If you wish to review bug reports
220 please do so via http://$gWebDomain/ or ask this mail server
222 soon: MAILINGLISTS_TEXT
224 } elsif (m/^unsubscribe/i) {
226 soon: UNSUBSCRIBE_TEXT
227 soon: MAILINGLISTS_TEXT
229 } elsif (!$control) {
231 Unknown command or malformed arguments to command.
232 (Use control\@$gEmailDomain to manipulate reports.)
235 if (++$unknowns >= 3) {
236 &transcript("Too many unknown commands, stopping here.\n\n");
239 #### interesting ones start here
240 } elsif (m/^close\s+\#?(-?\d+)$/i) {
244 &transcript("'close' is deprecated; see http://$gWebDomain/Developer$gHTMLSuffix#closing.\n");
245 if (length($s_done)) {
246 &transcript("$gBug is already closed, cannot re-close.\n\n");
249 $action= "$gBug closed, send any further explanations to $s_originator";
251 &addmaintainers($s_package);
252 if ( length( $gDoneList ) > 0 && length( $gListDomain ) >
253 0 ) { &addccaddress("$gDoneList\@$gListDomain"); }
256 From: $gMaintainerEmail ($gProject $gBug Tracking System)
258 Subject: $gBug#$ref acknowledged by developer
260 References: $header{'message-id'} $s_msgid
261 In-Reply-To: $s_msgid
262 Message-ID: <handler.$ref.$nn.notifdonectrl.$midix\@$gEmailDomain>
263 Reply-To: $ref\@$gEmailDomain
265 This is an automatic notification regarding your $gBug report
267 which was filed against the $s_package package.
269 It has been marked as closed by one of the developers, namely
272 You should be hearing from them with a substantive response shortly,
273 in case you haven't already. If not, please contact them directly.
276 (administrator, $gProject $gBugs database)
279 &sendmailmessage($message,$s_originator);
280 } while (&getnextbug);
283 } elsif (m/^reassign\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
285 $ref= $1; $newpackage= $2;
286 $newpackage =~ y/A-Z/a-z/;
288 if (length($s_package)) {
289 $action= "$gBug reassigned from package \`$s_package'".
290 " to \`$newpackage'.";
292 $action= "$gBug assigned to package \`$newpackage'.";
295 &addmaintainers($s_package);
296 &addmaintainers($newpackage);
297 $s_package= $newpackage;
298 } while (&getnextbug);
300 } elsif (m/^reopen\s+\#?(-?\d+)$/i ? ($noriginator='', 1) :
301 m/^reopen\s+\#?(-?\d+)\s+\=$/i ? ($noriginator='', 1) :
302 m/^reopen\s+\#?(-?\d+)\s+\!$/i ? ($noriginator=$replyto, 1) :
303 m/^reopen\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($noriginator=$2, 1) : 0) {
307 if (!length($s_done)) {
308 &transcript("$gBug is already open, cannot reopen.\n\n");
312 $noriginator eq '' ? "$gBug reopened, originator not changed." :
313 "$gBug reopened, originator set to $noriginator.";
315 &addmaintainers($s_package);
316 $s_originator= $noriginator eq '' ? $s_originator : $noriginator;
318 } while (&getnextbug);
321 } elsif (m/^submitter\s+\#?(-?\d+)\s+\!$/i ? ($newsubmitter=$replyto, 1) :
322 m/^submitter\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($newsubmitter=$2, 1) : 0) {
325 if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
326 $ref = $clonebugs{$ref};
330 &addmaintainers($s_package);
331 $oldsubmitter= $s_originator;
332 $s_originator= $newsubmitter;
333 $action= "Changed $gBug submitter from $oldsubmitter to $newsubmitter.";
335 &transcript("$action\n");
336 if (length($s_done)) {
337 &transcript("(By the way, that $gBug is currently marked as done.)\n");
341 From: $gMaintainerEmail ($gProject $gBug Tracking System)
343 Subject: $gBug#$ref submitter address changed
345 References: $header{'message-id'} $s_msgid
346 In-Reply-To: $s_msgid
347 Message-ID: <handler.$ref.$nn.newsubmitter.$midix\@$gEmailDomain>
348 Reply-To: $ref\@$gEmailDomain
350 The submitter address recorded for your $gBug report
354 The new submitter address for this report is
357 This change was made by
359 If it was incorrect, please contact them directly.
362 (administrator, $gProject $gBugs database)
365 &sendmailmessage($message,$oldsubmitter);
369 } elsif (m/^forwarded\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
371 $ref= $1; $whereto= $2;
373 if (length($s_forwarded)) {
374 $action= "Forwarded-to-address changed from $s_forwarded to $whereto.";
376 $action= "Noted your statement that $gBug has been forwarded to $whereto.";
378 if (length($s_done)) {
379 $extramessage= "(By the way, this $gBug is currently marked as done.)\n";
382 &addmaintainers($s_package);
383 if (length($gFowardList)>0 && length($gListDomain)>0 ) {
384 &addccaddress("$gFowardList\@$gListDomain");
386 $s_forwarded= $whereto;
387 } while (&getnextbug);
389 } elsif (m/^notforwarded\s+\#?(-?\d+)$/i) {
393 if (!length($s_forwarded)) {
394 &transcript("$gBug is not marked as having been forwarded.\n\n");
397 $action= "Removed annotation that $gBug had been forwarded to $s_forwarded.";
399 &addmaintainers($s_package);
401 } while (&getnextbug);
404 } elsif (m/^severity\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i ||
405 m/^priority\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i) {
409 if (!grep($_ eq $newseverity, @gSeverityList, "$gDefaultSeverity")) {
410 &transcript("Severity level \`$newseverity' is not known.\n".
411 "Recognized are: $gShowSeverities.\n\n");
412 } elsif (exists $gObsoleteSeverities{$newseverity}) {
413 &transcript("Severity level \`$newseverity' is obsolete. " .
414 "$gObsoleteSeverities{$newseverity}\n\n");
416 $printseverity= $s_severity;
417 $printseverity= "$gDefaultSeverity" if $printseverity eq '';
418 $action= "Severity set to \`$newseverity'.";
420 &addmaintainers($s_package);
421 $s_severity= $newseverity;
422 } while (&getnextbug);
424 } elsif (m/^tags?\s+\#?(-?\d+)\s+(([=+-])\s*)?(\S.*)?$/i) {
426 $ref = $1; $addsubcode = $3; $tags = $4;
428 if (defined $addsubcode) {
429 $addsub = "sub" if ($addsubcode eq "-");
430 $addsub = "add" if ($addsubcode eq "+");
431 $addsub = "set" if ($addsubcode eq "=");
435 foreach my $t (split /[\s,]+/, $tags) {
436 if (!grep($_ eq $t, @gTags)) {
443 &transcript("Unknown tag/s: ".join(', ', @badtags).".\n".
444 "Recognized are: ".join(' ', @gTags).".\n\n");
447 if ($s_keywords eq '') {
448 &transcript("There were no tags set.\n");
450 &transcript("Tags were: $s_keywords\n");
452 if ($addsub eq "set") {
453 $action= "Tags set to: " . join(", ", @okaytags);
454 } elsif ($addsub eq "add") {
455 $action= "Tags added: " . join(", ", @okaytags);
456 } elsif ($addsub eq "sub") {
457 $action= "Tags removed: " . join(", ", @okaytags);
460 &addmaintainers($s_package);
461 $s_keywords = '' if ($addsub eq "set");
462 if ($addsub eq "sub") {
463 foreach my $t (@badtags) {
464 $s_keywords = join ' ', grep $_ ne $t,
465 split ' ', $s_keywords;
468 foreach my $t (@okaytags) {
469 $s_keywords = join ' ', grep $_ ne $t,
470 split ' ', $s_keywords;
471 $s_keywords = "$t $s_keywords" unless($addsub eq "sub");
473 $s_keywords =~ s/\s*$//;
474 } while (&getnextbug);
476 } elsif (m/^retitle\s+\#?(-?\d+)\s+(\S.*\S)\s*$/i) {
478 $ref= $1; $newtitle= $2;
479 if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
480 $ref = $clonebugs{$ref};
484 &addmaintainers($s_package);
485 $s_subject= $newtitle;
486 $action= "Changed $gBug title.";
488 &transcript("$action\n");
489 if (length($s_done)) {
490 &transcript("(By the way, that $gBug is currently marked as done.)\n");
496 } elsif (m/^unmerge\s+\#?(-?\d+)$/i) {
500 if (!length($s_mergedwith)) {
501 &transcript("$gBug is not marked as being merged with any others.\n\n");
504 $mergelowstate eq 'locked' || die "$mergelowstate ?";
505 $action= "Disconnected #$ref from all other report(s).";
506 @newmergelist= split(/ /,$s_mergedwith);
509 &addmaintainers($s_package);
510 $s_mergedwith= ($ref == $discref) ? ''
511 : join(' ',grep($_ ne $ref,@newmergelist));
512 } while (&getnextbug);
515 } elsif (m/^merge\s+(\d+(\s+\d+)+)\s*$/i) {
517 @tomerge= sort { $a <=> $b } split(/\s+/,$1);
521 while (defined($ref= shift(@tomerge))) {
522 &transcript("D| checking merge $ref\n") if $dl;
524 next if grep($_ eq $ref,@newmergelist);
525 if (!&getbug) { ¬foundbug; @newmergelist=(); last }
527 &transcript("D| adding $ref ($s_mergedwith)\n") if $dl;
529 &checkmatch('package','m_package',$s_package);
530 &checkmatch('forwarded addr','m_forwarded',$s_forwarded);
531 $s_severity = '$gDefaultSeverity' if $s_severity eq '';
532 &checkmatch('severity','m_severity',$s_severity);
533 &checkmatch('done mark','m_done',length($s_done) ? 'done' : 'open');
534 foreach my $t (split /\s+/, $s_keywords) { $tags{$t} = 1; }
535 if (length($mismatch)) {
536 &transcript("Mismatch - only $gBugs in same state can be merged:\n".
538 &cancelbug; @newmergelist=(); last;
540 push(@newmergelist,$ref);
541 push(@tomerge,split(/ /,$s_mergedwith));
545 @newmergelist= sort { $a <=> $b } @newmergelist;
546 $action= "Merged @newmergelist.";
547 for $ref (@newmergelist) {
548 &getbug || die "huh ? $gBug $ref disappeared during merge";
549 &addmaintainers($s_package);
550 $s_mergedwith= join(' ',grep($_ ne $ref,@newmergelist));
551 $s_keywords= join(' ', keys %tags);
554 &transcript("$action\n\n");
557 } elsif (m/^clone\s+#?(\d+)\s+((-\d+\s+)*-\d+)\s*$/i) {
561 @newclonedids = split /\s+/, $2;
562 $newbugsneeded = scalar(@newclonedids);
566 if (length($s_mergedwith)) {
567 &transcript("$gBug is marked as being merged with others.\n\n");
570 &filelock("nextnumber.lock");
571 open(N,"nextnumber") || &quit("nextnumber: read: $!");
572 $v=<N>; $v =~ s/\n$// || &quit("nextnumber bad format");
573 $firstref= $v+0; $v += $newbugsneeded;
574 open(NN,">nextnumber"); print NN "$v\n"; close(NN);
577 $lastref = $firstref + $newbugsneeded - 1;
579 if ($newbugsneeded == 1) {
580 $action= "$gBug $origref cloned as bug $firstref.";
582 $action= "$gBug $origref cloned as bugs $firstref-$lastref.";
585 my $ohash = get_hashname($origref);
587 for $newclonedid (@newclonedids) {
588 $clonebugs{$newclonedid} = $ref;
590 my $hash = get_hashname($ref);
591 copy("db-h/$ohash/$origref.log", "db-h/$hash/$ref.log");
592 copy("db-h/$ohash/$origref.status", "db-h/$hash/$ref.status");
593 copy("db-h/$ohash/$origref.report", "db-h/$hash/$ref.report");
594 &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");
601 &transcript("Unknown command or malformed arguments to command.\n\n");
602 if (++$unknowns >= 5) {
603 &transcript("Too many unknown commands, stopping here.\n\n");
608 if ($procline>$#bodylines) {
609 &transcript(">\nEnd of message, stopping processing here.\n\n");
611 if (!$ok && !quickabort) {
612 &transcript("No commands successfully parsed; sending the help text(s).\n");
617 &transcript("MC\n") if $dl>1;
619 for $maint (keys %maintccreasons) {
620 &transcript("MM|$maint|\n") if $dl>1;
621 next if $maint eq $replyto;
623 $reasonsref= $maintccreasons{$maint};
624 &transcript("MY|$maint|\n") if $dl>2;
625 for $p (sort keys %$reasonsref) {
626 &transcript("MP|$p|\n") if $dl>2;
627 $reasonstring.= ', ' if length($reasonstring);
628 $reasonstring.= $p.' ' if length($p);
629 $reasonstring.= join(' ',map("#$_",sort keys %{$$reasonsref{$p}}));
631 if (length($reasonstring) > 40) {
632 (substr $reasonstring, 37) = "...";
634 $reasonstring = "" if (!defined($reasonstring));
635 push(@maintccs,"$maint ($reasonstring)");
636 push(@maintccaddrs,"$maint");
641 &transcript("MC|@maintccs|\n") if $dl>2;
642 $maintccs .= "Cc: " . join(",\n ",@maintccs) . "\n";
645 if (!defined $header{'subject'} || $header{'subject'} eq "") {
646 $header{'subject'} = "your mail";
650 From: $gMaintainerEmail ($gProject $gBug Tracking System)
652 ${maintccs}Subject: Processed: $header{'subject'}
653 In-Reply-To: $header{'message-id'}
654 References: $header{'message-id'}
655 Message-ID: <handler.s.$nn.transcript\@$gEmailDomain>
657 ${transcript}Please contact me if you need assistance.
660 (administrator, $gProject $gBugs database)
664 $repliedshow= join(', ',$replyto,@maintccaddrs);
665 &filelock("lock/-1");
666 open(AP,">>db-h/-1.log") || &quit("open db-h/-1.log: $!");
668 "\2\n$repliedshow\n\5\n$reply\n\3\n".
670 "<strong>Request received</strong> from <code>".
671 &sani($header{'from'})."</code>\n".
672 "to <code>".&sani($controlrequestaddr)."</code>\n".
674 "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/-1.log: $!");
675 close(AP) || &quit("open db-h/-1.log: $!");
677 utime(time,time,"db-h");
679 &sendmailmessage($reply,$replyto,@maintccaddrs,@bcc);
681 unlink("incoming/P$nn") || &quit("unlinking incoming/P$nn: $!");
685 map { $_->address() }
686 map { Mail::Address->parse($_) } @_;
689 sub sendmailmessage {
690 local ($message,@recips) = @_;
691 $message = "X-Loop: $gMaintainerEmail\n" . $message;
692 print "mailing to >@recips<\n" if $debug;
694 defined($c) || &quit("mailing forking for sendmail: $!");
695 if (!$c) { # ie, we are the child process
696 exec '/usr/lib/sendmail','-f'."$gMaintainerEmail",'-odb','-oem','-oi',get_addresses(@recips);
699 print(D $message) || &quit("writing to sendmail process: $!");
700 $!=0; close(D); $? && &quit("sendmail gave exit status $? ($!)");
705 &sendtxthelpraw("bug-log-mailserver.txt","instructions for request\@$gEmailDomain");
706 &sendtxthelpraw("bug-maint-mailcontrol.txt","instructions for control\@$gEmailDomain")
711 # &transcript("Sorry, command $_[0] not yet implemented.\n\n");
715 local ($string,$mvarname,$svarvalue) = @_;
718 eval "\$mvarvalue= \$$mvarname";
719 &transcript("D| checkmatch \`$string' /$mvarname/$mvarvalue/$svarvalue/\n")
722 "Values for \`$string' don't match:\n".
723 " #$newmergelist[0] has \`$mvarvalue';\n".
724 " #$ref has \`$svarvalue'\n"
725 if $mvarvalue ne $svarvalue;
727 &transcript("D| setupmatch \`$string' /$mvarname/$svarvalue/\n")
729 eval "\$$mvarname= \$svarvalue";
733 # High-level bug manipulation calls
734 # Do announcements themselves
736 # Possible calling sequences:
740 # &transcript(something)
744 # $action= (something)
746 # (modify s_* variables)
747 # } while (getnextbug);
750 &dlen("nochangebug");
751 $state eq 'single' || $state eq 'multiple' || die "$state ?";
753 &endmerge if $manybugs;
755 &dlex("nochangebug");
759 &dlen("setbug $ref");
760 if ($ref =~ m/^-\d+/) {
761 if (!defined $clonebugs{$ref}) {
763 &dlex("setbug => noclone");
766 $ref = $clonebugs{$ref};
768 $state eq 'idle' || die "$state ?";
771 &dlex("setbug => 0s");
774 @thisbugmergelist= split(/ /,$s_mergedwith);
775 if (!@thisbugmergelist) {
780 &dlex("setbug => 1s");
789 &dlex("setbug => 0mc");
793 $state= 'multiple'; $sref=$ref;
794 &dlex("setbug => 1m");
800 $state eq 'single' || $state eq 'multiple' || die "$state ?";
802 if (!$manybugs || !@thisbugmergelist) {
803 length($action) || die;
804 &transcript("$action\n$extramessage\n");
805 &endmerge if $manybugs;
807 &dlex("getnextbug => 0");
810 $ref= shift(@thisbugmergelist);
811 &getbug || die "bug $ref disappeared";
813 &dlex("getnextbug => 1");
817 # Low-level bug-manipulation calls
818 # Do no announcements
826 # $action= (something)
831 # [getbug (returns 0)]
832 # &transcript("$action\n\n")
835 sub notfoundbug { &transcript("$gBug number $ref not found.\n\n"); }
836 sub foundbug { &transcript("$gBug#$ref: $s_subject\n"); }
840 $mergelowstate eq 'idle' || die "$mergelowstate ?";
841 &filelock('lock/merge');
842 $mergelowstate='locked';
848 $mergelowstate eq 'locked' || die "$mergelowstate ?";
850 $mergelowstate='idle';
855 &dlen("getbug $ref");
856 $lowstate eq 'idle' || die "$state ?";
857 if (&lockreadbug($ref)) {
860 &dlex("getbug => 1");
865 &dlex("getbug => 0");
871 $lowstate eq 'open' || die "$state ?";
878 &dlen("savebug $ref");
879 $lowstate eq 'open' || die "$lowstate ?";
880 length($action) || die;
881 $ref == $sref || die "read $sref but saving $ref ?";
882 my $hash = get_hashname($ref);
883 open(L,">>db-h/$hash/$ref.log") || &quit("opening db-h/$hash/$ref.log: $!");
886 "<strong>".&sani($action)."</strong>\n".
887 "Request was from <code>".&sani($header{'from'})."</code>\n".
888 "to <code>".&sani($controlrequestaddr)."</code>. \n".
890 "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/$hash/$ref.log: $!");
891 close(L) || &quit("closing db-h/$hash/$ref.log: $!");
892 open(S,">db-h/$hash/$ref.status.new") || &quit("opening db-h/$hash/$ref.status.new: $!");
905 "$s_fixed_versions\n") || &quit("writing db-h/$hash/$ref.status.new: $!");
906 close(S) || &quit("closing db-h/$hash/$ref.status.new: $!");
907 rename("db-h/$hash/$ref.status.new","db-h/$hash/$ref.status") ||
908 &quit("installing new db-h/$hash/$ref.status: $!");
909 &bughook('change',$ref,
921 "$s_fixed_versions\n");
929 &transcript("C> @_ ($state $lowstate $mergelowstate)\n");
934 &transcript("R> @_ ($state $lowstate $mergelowstate)\n");
938 print $_[0] if $debug;
946 my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
947 $url =~ s/([<>&"])/\&$saniarray{$1};/g;
964 local ($relpath,$description) = @_;
966 open(D,"$gDocDir/$relpath") || &quit("open doc file $relpath: $!");
967 while(<D>) { $doc.=$_; }
969 &transcript("Sending $description in separate message.\n");
970 &sendmailmessage(<<END.$doc,$replyto);
971 From: $gMaintainerEmail ($gProject $gBug Tracking System)
973 Subject: $gProject $gBug help: $description
974 References: $header{'message-id'}
975 In-Reply-To: $header{'message-id'}
976 Message-ID: <handler.s.$nn.help.$midix\@$gEmailDomain>
983 local ($relpath,$description) = @_;
985 open(L,"lynx -nolist -dump $gCGIDomain/\Q$relpath\E 2>&1 |") || &quit("fork for lynx: $!");
986 while(<L>) { $doc.=$_; }
988 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
989 &transcript("Information ($description) is not available -\n".
990 "perhaps the $gBug does not exist or is not on the WWW yet.\n");
993 &transcript("Error getting $description (code $? $!):\n$doc\n");
995 &transcript("Sending $description.\n");
996 &sendmailmessage(<<END.$doc,$replyto);
997 From: $gMaintainerEmail ($gProject $gBug Tracking System)
999 Subject: $gProject $gBugs information: $description
1000 References: $header{'message-id'}
1001 In-Reply-To: $header{'message-id'}
1002 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1011 $maintccreasons{$cca}{''}{$ref}= 1;
1014 sub addmaintainers {
1015 # Data structure is:
1016 # maintainer email address &c -> assoc of packages -> assoc of bug#'s
1017 my ($p, $addmaint, $pshow);
1018 &ensuremaintainersloaded;
1019 $anymaintfound=0; $anymaintnotfound=0;
1020 for $p (split(m/[ \t?,()]+/,$_[0])) {
1022 $pshow= ($p =~ m/[-+.a-z0-9]+/ ? $& : '');
1023 if (defined $gSubscriptionDomain) {
1024 if (defined($pkgsrc{$p})) {
1025 push @bcc, "$pkgsrc{$p}\@$gSubscriptionDomain";
1027 push @bcc, "$p\@$gSubscriptionDomain";
1030 if (defined($maintainerof{$p})) {
1031 $addmaint= $maintainerof{$p};
1032 &transcript("MR|$addmaint|$p|$ref|\n") if $dl>2;
1033 $maintccreasons{$addmaint}{$p}{$ref}= 1;
1034 print "maintainer add >$p|$addmaint<\n" if $debug;
1036 print "maintainer none >$p<\n" if $debug;
1037 &transcript("MR|unknown-package|$p|$ref|\n") if $dl>2;
1038 $maintccreasons{$gUnknownMaintainerEmail}{$p}{$ref}= 1;
1043 sub ensuremaintainersloaded {
1045 return if $maintainersloaded++;
1046 open(MAINT,"$gMaintainerFile") || die &quit("maintainers open: $!");
1050 m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers bogus \`$_'");
1051 $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
1052 $maintainerof{$1}= $2;
1055 open(MAINT,"$gMaintainerFileOverride") || die &quit("maintainers.override open: $!");
1059 m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers.override bogus \`$_'");
1060 $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
1061 $maintainerof{$1}= $2;
1064 open(SOURCES, "$gPackageSource") || &quit("pkgsrc open: $!");
1066 next unless m/^(\S+)\s+\S+\s+(\S.*\S)\s*$/;
1067 my ($a, $b) = ($1, $2);
1068 $pkgsrc{lc($a)} = $b;
1074 local ($wherefrom,$path,$description) = @_;
1075 if ($wherefrom eq "ftp.d.o") {
1076 $doc = `lynx -nolist -dump http://ftp.debian.org/debian/indices/$path.gz 2>&1 | gunzip -cf` or &quit("fork for lynx/gunzip: $!");
1078 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1079 &transcript("$description is not available.\n");
1082 &transcript("Error getting $description (code $? $!):\n$doc\n");
1085 } elsif ($wherefrom eq "local") {
1087 $doc = do { local $/; <P> };
1090 &transcript("internal errror: info files location unknown.\n");
1093 &transcript("Sending $description.\n");
1094 &sendmailmessage(<<END.$doc,$replyto);
1095 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1097 Subject: $gProject $gBugs information: $description
1098 References: $header{'message-id'}
1099 In-Reply-To: $header{'message-id'}
1100 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1102 $description follows: