2 # $Id: service.in,v 1.97 2004/10/26 13:55:26 cjwatson Exp $
4 # Usage: service <code>.nn
5 # Temps: incoming/P<code>.nn
10 $config_path = '/etc/debbugs';
11 $lib_path = '/usr/lib/debbugs';
13 require "$config_path/config";
14 require "$lib_path/errorlib";
15 $ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
17 chdir("$gSpoolDir") || die "chdir spool: $!\n";
20 open DEBUG, ">/dev/null";
25 m/^[RC]\.\d+$/ || &quit("bad argument");
28 if (!rename("incoming/G$nn","incoming/P$nn")) {
29 $_=$!.''; m/no such file or directory/i && exit 0;
30 &quit("renaming to lock: $!");
33 open(M,"incoming/P$nn");
40 print "###\n",join("##\n",@msg),"\n###\n" if $debug;
42 my $parser = new MIME::Parser;
43 mkdir "$gSpoolDir/mime.tmp", 0777;
44 $parser->output_under("$gSpoolDir/mime.tmp");
45 my $entity = eval { $parser->parse_data(join('',@log)) };
47 # header and decoded body respectively
48 my (@headerlines, @bodylines);
50 if ($entity and $entity->head->tags) {
51 @headerlines = @{$entity->head->header};
54 my $entity_body = getmailbody($entity);
55 @bodylines = $entity_body ? $entity_body->as_lines() : ();
58 # Legacy pre-MIME code, kept around in case MIME::Parser fails.
60 for ($i = 0; $i <= $#msg; $i++) {
62 last unless length($_);
63 while ($msg[$i+1] =~ m/^\s/) {
67 push @headerlines, $_;
70 @bodylines = @msg[$i..$#msg];
75 print ">$_<\n" if $debug;
78 print ">$v=$_<\n" if $debug;
81 print "!>$_<\n" if $debug;
85 # Strip off RFC2440-style PGP clearsigning.
86 if (@bodylines and $bodylines[0] =~ /^-----BEGIN PGP SIGNED/) {
87 shift @bodylines while @bodylines and length $bodylines[0];
88 shift @bodylines while @bodylines and $bodylines[0] !~ /\S/;
89 for my $findsig (0 .. $#bodylines) {
90 if ($bodylines[$findsig] =~ /^-----BEGIN PGP SIGNATURE/) {
91 $#bodylines = $findsig - 1;
95 map { s/^- // } @bodylines;
98 grep(s/\s+$//,@bodylines);
100 print "***\n",join("\n",@bodylines),"\n***\n" if $debug;
102 if (defined $header{'resent-from'} && !defined $header{'from'}) {
103 $header{'from'} = $header{'resent-from'};
106 defined($header{'from'}) || &quit("no From header");
108 delete $header{'reply-to'}
109 if ( defined($header{'reply-to'}) && $header{'reply-to'} =~ m/^\s*$/ );
111 if ( defined($header{'reply-to'}) && $header{'reply-to'} ne "" ) {
112 $replyto = $header{'reply-to'};
114 $replyto = $header{'from'};
117 $controlrequestaddr= $control ? "control\@$gEmailDomain" : "request\@$gEmailDomain";
119 &transcript("Processing commands for $controlrequestaddr:\n\n");
124 $mergelowstate= 'idle';
130 my $fuckheads = "(" . join("|", @gFuckheads) . ")";
131 if (@gFuckheads and $replyto =~ m/$fuckheads/) {
132 &transcript("This service is unavailable.\n\n");
141 push @bcc, $_[0] unless grep { $_ eq $_[0] } @bcc;
144 for ($procline=0; $procline<=$#bodylines; $procline++) {
145 $state eq 'idle' || print "$state ?\n";
146 $lowstate eq 'idle' || print "$lowstate ?\n";
147 $mergelowstate eq 'idle' || print "$mergelowstate ?\n";
149 &transcript("Stopping processing here.\n\n");
152 $_= $bodylines[$procline]; s/\s+$//;
154 &transcript("> $_\n");
157 if (m/^stop/i || m/^quit/i || m/^--/ || m/^thank/i) {
158 &transcript("Stopping processing here.\n\n");
160 } elsif (m/^debug\s+(\d+)$/i && $1 >= 0 && $1 <= 1000) {
162 &transcript("Debug level $dl.\n\n");
163 } elsif (m/^(send|get)\s+\#?(\d{2,})$/i) {
165 &sendlynxdoc("bugreport.cgi?bug=$ref","logs for $gBug#$ref");
166 } elsif (m/^send-detail\s+\#?(\d{2,})$/i) {
168 &sendlynxdoc("bugreport.cgi?bug=$ref&boring=yes",
169 "detailed logs for $gBug#$ref");
170 } elsif (m/^index(\s+full)?$/i) {
171 &transcript("This BTS function is currently disabled, sorry.\n\n");
172 $ok++; # well, it's not really ok, but it fixes #81224 :)
173 } elsif (m/^index-summary\s+by-package$/i) {
174 &transcript("This BTS function is currently disabled, sorry.\n\n");
175 $ok++; # well, it's not really ok, but it fixes #81224 :)
176 } elsif (m/^index-summary(\s+by-number)?$/i) {
177 &transcript("This BTS function is currently disabled, sorry.\n\n");
178 $ok++; # well, it's not really ok, but it fixes #81224 :)
179 } elsif (m/^index(\s+|-)pack(age)?s?$/i) {
180 &sendlynxdoc("pkgindex.cgi?indexon=pkg",'index of packages');
181 } elsif (m/^index(\s+|-)maints?$/i) {
182 &sendlynxdoc("pkgindex.cgi?indexon=maint",'index of maintainers');
183 } elsif (m/^index(\s+|-)maint\s+(\S+)$/i) {
185 &sendlynxdoc("pkgreport.cgi?maint=" . urlsanit($maint),
186 "$gBug list for maintainer \`$maint'");
188 } elsif (m/^index(\s+|-)pack(age)?s?\s+(\S.*\S)$/i) {
190 &sendlynxdoc("pkgreport.cgi?pkg=" . urlsanit($package),
191 "$gBug list for package $package");
193 } elsif (m/^send-unmatched(\s+this|\s+-?0)?$/i) {
194 &transcript("This BTS function is currently disabled, sorry.\n\n");
195 $ok++; # well, it's not really ok, but it fixes #81224 :)
196 } elsif (m/^send-unmatched\s+(last|-1)$/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+(old|-2)$/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/^getinfo\s+([\w-.]+)$/i) {
203 # the following is basically a Debian-specific kludge, but who cares
205 if ($req =~ /^maintainers$/i && -f "$gConfigDir/Maintainers") {
206 &sendinfo("local", "$gConfigDir/Maintainers", "Maintainers file");
207 } elsif ($req =~ /^override\.(\w+)\.([\w-.]+)$/i) {
209 &sendinfo("ftp.d.o", "$req", "override file for $2 part of $1 distribution");
210 } elsif ($req =~ /^pseudo-packages\.(description|maintainers)$/i && -f "$gConfigDir/$req") {
211 &sendinfo("local", "$gConfigDir/$req", "$req file");
213 &transcript("Info file $req does not exist.\n\n");
215 } elsif (m/^help/i) {
219 } elsif (m/^refcard/i) {
220 &sendtxthelp("bug-mailserver-refcard.txt","mail servers' reference card");
221 } elsif (m/^subscribe/i) {
223 There is no $gProject $gBug mailing list. If you wish to review bug reports
224 please do so via http://$gWebDomain/ or ask this mail server
226 soon: MAILINGLISTS_TEXT
228 } elsif (m/^unsubscribe/i) {
230 soon: UNSUBSCRIBE_TEXT
231 soon: MAILINGLISTS_TEXT
233 } elsif (!$control) {
235 Unknown command or malformed arguments to command.
236 (Use control\@$gEmailDomain to manipulate reports.)
239 if (++$unknowns >= 3) {
240 &transcript("Too many unknown commands, stopping here.\n\n");
243 #### interesting ones start here
244 } elsif (m/^close\s+\#?(-?\d+)$/i) {
248 &transcript("'close' is deprecated; see http://$gWebDomain/Developer$gHTMLSuffix#closing.\n");
249 if (length($data->{done})) {
250 &transcript("$gBug is already closed, cannot re-close.\n\n");
253 $action= "$gBug closed, send any further explanations to $data->{originator}";
255 &addmaintainers($data);
256 if ( length( $gDoneList ) > 0 && length( $gListDomain ) >
257 0 ) { &addccaddress("$gDoneList\@$gListDomain"); }
258 $data->{done}= $replyto;
259 my @keywords= split ' ', $data->{keywords};
260 if (grep $_ eq 'pending', @keywords) {
261 $extramessage= "Removed pending tag.\n";
262 $data->{keywords}= join ' ', grep $_ ne 'pending',
267 From: $gMaintainerEmail ($gProject $gBug Tracking System)
268 To: $data->{originator}
269 Subject: $gBug#$ref acknowledged by developer
271 References: $header{'message-id'} $data->{msgid}
272 In-Reply-To: $data->{msgid}
273 Message-ID: <handler.$ref.$nn.notifdonectrl.$midix\@$gEmailDomain>
274 Reply-To: $ref\@$gEmailDomain
275 X-$gProject-PR-Message: they-closed-control $ref
277 This is an automatic notification regarding your $gBug report
278 #$ref: $data->{subject},
279 which was filed against the $data->{package} package.
281 It has been marked as closed by one of the developers, namely
284 You should be hearing from them with a substantive response shortly,
285 in case you haven't already. If not, please contact them directly.
288 (administrator, $gProject $gBugs database)
291 &sendmailmessage($message,$data->{originator});
292 } while (&getnextbug);
295 } elsif (m/^reassign\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
297 $ref= $1; $newpackage= $2;
298 $newpackage =~ y/A-Z/a-z/;
300 if (length($data->{package})) {
301 $action= "$gBug reassigned from package \`$data->{package}'".
302 " to \`$newpackage'.";
304 $action= "$gBug assigned to package \`$newpackage'.";
307 &addmaintainers($data);
308 $data->{package}= $newpackage;
309 &addmaintainers($data);
310 } while (&getnextbug);
312 } elsif (m/^reopen\s+\#?(-?\d+)$/i ? ($noriginator='', 1) :
313 m/^reopen\s+\#?(-?\d+)\s+\=$/i ? ($noriginator='', 1) :
314 m/^reopen\s+\#?(-?\d+)\s+\!$/i ? ($noriginator=$replyto, 1) :
315 m/^reopen\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($noriginator=$2, 1) : 0) {
319 if (!length($data->{done})) {
320 &transcript("$gBug is already open, cannot reopen.\n\n");
324 $noriginator eq '' ? "$gBug reopened, originator not changed." :
325 "$gBug reopened, originator set to $noriginator.";
327 &addmaintainers($data);
328 $data->{originator}= $noriginator eq '' ? $data->{originator} : $noriginator;
330 } while (&getnextbug);
333 } elsif (m/^submitter\s+\#?(-?\d+)\s+\!$/i ? ($newsubmitter=$replyto, 1) :
334 m/^submitter\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($newsubmitter=$2, 1) : 0) {
337 if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
338 $ref = $clonebugs{$ref};
342 &addmaintainers($data);
343 $oldsubmitter= $data->{originator};
344 $data->{originator}= $newsubmitter;
345 $action= "Changed $gBug submitter from $oldsubmitter to $newsubmitter.";
347 &transcript("$action\n");
348 if (length($data->{done})) {
349 &transcript("(By the way, that $gBug is currently marked as done.)\n");
353 From: $gMaintainerEmail ($gProject $gBug Tracking System)
355 Subject: $gBug#$ref submitter address changed
357 References: $header{'message-id'} $data->{msgid}
358 In-Reply-To: $data->{msgid}
359 Message-ID: <handler.$ref.$nn.newsubmitter.$midix\@$gEmailDomain>
360 Reply-To: $ref\@$gEmailDomain
361 X-$gProject-PR-Message: submitter-changed $ref
363 The submitter address recorded for your $gBug report
364 #$ref: $data->{subject}
367 The new submitter address for this report is
370 This change was made by
372 If it was incorrect, please contact them directly.
375 (administrator, $gProject $gBugs database)
378 &sendmailmessage($message,$oldsubmitter);
382 } elsif (m/^forwarded\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
384 $ref= $1; $whereto= $2;
386 if (length($data->{forwarded})) {
387 $action= "Forwarded-to-address changed from $data->{forwarded} to $whereto.";
389 $action= "Noted your statement that $gBug has been forwarded to $whereto.";
391 if (length($data->{done})) {
392 $extramessage= "(By the way, this $gBug is currently marked as done.)\n";
395 &addmaintainers($data);
396 if (length($gForwardList)>0 && length($gListDomain)>0 ) {
397 &addccaddress("$gForwardList\@$gListDomain");
399 $data->{forwarded}= $whereto;
400 } while (&getnextbug);
402 } elsif (m/^notforwarded\s+\#?(-?\d+)$/i) {
406 if (!length($data->{forwarded})) {
407 &transcript("$gBug is not marked as having been forwarded.\n\n");
410 $action= "Removed annotation that $gBug had been forwarded to $data->{forwarded}.";
412 &addmaintainers($data);
413 $data->{forwarded}= '';
414 } while (&getnextbug);
417 } elsif (m/^severity\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i ||
418 m/^priority\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i) {
422 if (!grep($_ eq $newseverity, @gSeverityList, "$gDefaultSeverity")) {
423 &transcript("Severity level \`$newseverity' is not known.\n".
424 "Recognized are: $gShowSeverities.\n\n");
425 } elsif (exists $gObsoleteSeverities{$newseverity}) {
426 &transcript("Severity level \`$newseverity' is obsolete. " .
427 "$gObsoleteSeverities{$newseverity}\n\n");
429 $printseverity= $data->{severity};
430 $printseverity= "$gDefaultSeverity" if $printseverity eq '';
431 $action= "Severity set to \`$newseverity'.";
433 &addmaintainers($data);
434 if (defined $gStrongList and isstrongseverity($newseverity)) {
435 addbcc("$gStrongList\@$gListDomain");
437 $data->{severity}= $newseverity;
438 } while (&getnextbug);
440 } elsif (m/^tags?\s+\#?(-?\d+)\s+(([=+-])\s*)?(\S.*)?$/i) {
442 $ref = $1; $addsubcode = $3; $tags = $4;
444 if (defined $addsubcode) {
445 $addsub = "sub" if ($addsubcode eq "-");
446 $addsub = "add" if ($addsubcode eq "+");
447 $addsub = "set" if ($addsubcode eq "=");
451 foreach my $t (split /[\s,]+/, $tags) {
452 if (!grep($_ eq $t, @gTags)) {
459 &transcript("Unknown tag/s: ".join(', ', @badtags).".\n".
460 "Recognized are: ".join(' ', @gTags).".\n\n");
463 if ($data->{keywords} eq '') {
464 &transcript("There were no tags set.\n");
466 &transcript("Tags were: $data->{keywords}\n");
468 if ($addsub eq "set") {
469 $action= "Tags set to: " . join(", ", @okaytags);
470 } elsif ($addsub eq "add") {
471 $action= "Tags added: " . join(", ", @okaytags);
472 } elsif ($addsub eq "sub") {
473 $action= "Tags removed: " . join(", ", @okaytags);
476 &addmaintainers($data);
477 $data->{keywords} = '' if ($addsub eq "set");
478 if ($addsub eq "sub") {
479 foreach my $t (@badtags) {
480 $data->{keywords} = join ' ', grep $_ ne $t,
481 split ' ', $data->{keywords};
484 foreach my $t (@okaytags) {
485 $data->{keywords} = join ' ', grep $_ ne $t,
486 split ' ', $data->{keywords};
487 $data->{keywords} = "$t $data->{keywords}" unless($addsub eq "sub");
489 $data->{keywords} =~ s/\s*$//;
490 } while (&getnextbug);
492 } elsif (m/^retitle\s+\#?(-?\d+)\s+(\S.*\S)\s*$/i) {
494 $ref= $1; $newtitle= $2;
495 if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
496 $ref = $clonebugs{$ref};
500 &addmaintainers($data);
501 $data->{subject}= $newtitle;
502 $action= "Changed $gBug title.";
504 &transcript("$action\n");
505 if (length($data->{done})) {
506 &transcript("(By the way, that $gBug is currently marked as done.)\n");
512 } elsif (m/^unmerge\s+\#?(-?\d+)$/i) {
516 if (!length($data->{mergedwith})) {
517 &transcript("$gBug is not marked as being merged with any others.\n\n");
520 $mergelowstate eq 'locked' || die "$mergelowstate ?";
521 $action= "Disconnected #$ref from all other report(s).";
522 @newmergelist= split(/ /,$data->{mergedwith});
525 &addmaintainers($data);
526 $data->{mergedwith}= ($ref == $discref) ? ''
527 : join(' ',grep($_ ne $ref,@newmergelist));
528 } while (&getnextbug);
531 } elsif (m/^merge\s+#?(-?\d+(\s+#?-?\d+)+)\s*$/i) {
533 @tomerge= sort { $a <=> $b } split(/\s+#?/,$1);
537 while (defined($ref= shift(@tomerge))) {
538 &transcript("D| checking merge $ref\n") if $dl;
540 if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
541 $ref = $clonebugs{$ref};
543 next if grep($_ eq $ref,@newmergelist);
544 if (!&getbug) { ¬foundbug; @newmergelist=(); last }
546 &transcript("D| adding $ref ($data->{mergedwith})\n") if $dl;
548 &checkmatch('package','m_package',$data->{package});
549 &checkmatch('forwarded addr','m_forwarded',$data->{forwarded});
550 $data->{severity} = '$gDefaultSeverity' if $data->{severity} eq '';
551 &checkmatch('severity','m_severity',$data->{severity});
552 &checkmatch('done mark','m_done',length($data->{done}) ? 'done' : 'open');
553 &checkmatch('owner','m_owner',$data->{owner});
554 foreach my $t (split /\s+/, $data->{keywords}) { $tags{$t} = 1; }
555 if (length($mismatch)) {
556 &transcript("Mismatch - only $gBugs in same state can be merged:\n".
558 &cancelbug; @newmergelist=(); last;
560 push(@newmergelist,$ref);
561 push(@tomerge,split(/ /,$data->{mergedwith}));
565 @newmergelist= sort { $a <=> $b } @newmergelist;
566 $action= "Merged @newmergelist.";
567 for $ref (@newmergelist) {
568 &getbug || die "huh ? $gBug $ref disappeared during merge";
569 &addmaintainers($data);
570 $data->{mergedwith}= join(' ',grep($_ ne $ref,@newmergelist));
571 $data->{keywords}= join(' ', keys %tags);
574 &transcript("$action\n\n");
577 } elsif (m/^clone\s+#?(\d+)\s+((-\d+\s+)*-\d+)\s*$/i) {
581 @newclonedids = split /\s+/, $2;
582 $newbugsneeded = scalar(@newclonedids);
586 if (length($data->{mergedwith})) {
587 &transcript("$gBug is marked as being merged with others.\n\n");
590 &filelock("nextnumber.lock");
591 open(N,"nextnumber") || &quit("nextnumber: read: $!");
592 $v=<N>; $v =~ s/\n$// || &quit("nextnumber bad format");
593 $firstref= $v+0; $v += $newbugsneeded;
594 open(NN,">nextnumber"); print NN "$v\n"; close(NN);
597 $lastref = $firstref + $newbugsneeded - 1;
599 if ($newbugsneeded == 1) {
600 $action= "$gBug $origref cloned as bug $firstref.";
602 $action= "$gBug $origref cloned as bugs $firstref-$lastref.";
605 my $ohash = get_hashname($origref);
607 for $newclonedid (@newclonedids) {
608 $clonebugs{$newclonedid} = $ref;
610 my $hash = get_hashname($ref);
611 copy("db-h/$ohash/$origref.log", "db-h/$hash/$ref.log");
612 copy("db-h/$ohash/$origref.status", "db-h/$hash/$ref.status");
613 copy("db-h/$ohash/$origref.summary", "db-h/$hash/$ref.summary");
614 copy("db-h/$ohash/$origref.report", "db-h/$hash/$ref.report");
615 &bughook('new', $ref, $data);
621 } elsif (m/^package\s+(\S.*\S)?\s*$/i) {
623 my @pkgs = split /\s+/, $1;
624 if (scalar(@pkgs) > 0) {
625 %limit_pkgs = map { ($_, 1) } @pkgs;
626 &transcript("Ignoring bugs not assigned to: " .
627 join(" ", keys(%limit_pkgs)) . "\n\n");
630 &transcript("Not ignoring any bugs.\n\n");
632 } elsif (m/^owner\s+\#?(-?\d+)\s+!$/i ? ($newowner = $replyto, 1) :
633 m/^owner\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($newowner = $2, 1) : 0) {
637 if (length $data->{owner}) {
638 $action = "Owner changed from $data->{owner} to $newowner.";
640 $action = "Owner recorded as $newowner.";
642 if (length $data->{done}) {
643 $extramessage = "(By the way, this $gBug is currently " .
644 "marked as done.)\n";
647 &addmaintainers($data);
648 $data->{owner} = $newowner;
649 } while (&getnextbug);
651 } elsif (m/^noowner\s+\#?(-?\d+)$/i) {
655 if (length $data->{owner}) {
656 $action = "Removed annotation that $gBug was owned by " .
659 &addmaintainers($data);
661 } while (&getnextbug);
663 &transcript("$gBug is not marked as having an owner.\n\n");
668 &transcript("Unknown command or malformed arguments to command.\n\n");
669 if (++$unknowns >= 5) {
670 &transcript("Too many unknown commands, stopping here.\n\n");
675 if ($procline>$#bodylines) {
676 &transcript(">\nEnd of message, stopping processing here.\n\n");
678 if (!$ok && !quickabort) {
679 &transcript("No commands successfully parsed; sending the help text(s).\n");
684 &transcript("MC\n") if $dl>1;
686 for $maint (keys %maintccreasons) {
687 &transcript("MM|$maint|\n") if $dl>1;
688 next if $maint eq $replyto;
690 $reasonsref= $maintccreasons{$maint};
691 &transcript("MY|$maint|\n") if $dl>2;
692 for $p (sort keys %$reasonsref) {
693 &transcript("MP|$p|\n") if $dl>2;
694 $reasonstring.= ', ' if length($reasonstring);
695 $reasonstring.= $p.' ' if length($p);
696 $reasonstring.= join(' ',map("#$_",sort keys %{$$reasonsref{$p}}));
698 if (length($reasonstring) > 40) {
699 (substr $reasonstring, 37) = "...";
701 $reasonstring = "" if (!defined($reasonstring));
702 push(@maintccs,"$maint ($reasonstring)");
703 push(@maintccaddrs,"$maint");
708 &transcript("MC|@maintccs|\n") if $dl>2;
709 $maintccs .= "Cc: " . join(",\n ",@maintccs) . "\n";
712 if (!defined $header{'subject'} || $header{'subject'} eq "") {
713 $header{'subject'} = "your mail";
717 From: $gMaintainerEmail ($gProject $gBug Tracking System)
719 ${maintccs}Subject: Processed: $header{'subject'}
720 In-Reply-To: $header{'message-id'}
721 References: $header{'message-id'}
722 Message-ID: <handler.s.$nn.transcript\@$gEmailDomain>
724 X-$gProject-PR-Message: transcript
726 ${transcript}Please contact me if you need assistance.
729 (administrator, $gProject $gBugs database)
733 $repliedshow= join(', ',$replyto,@maintccaddrs);
734 &filelock("lock/-1");
735 open(AP,">>db-h/-1.log") || &quit("open db-h/-1.log: $!");
737 "\2\n$repliedshow\n\5\n$reply\n\3\n".
739 "<strong>Request received</strong> from <code>".
740 &sani($header{'from'})."</code>\n".
741 "to <code>".&sani($controlrequestaddr)."</code>\n".
743 "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/-1.log: $!");
744 close(AP) || &quit("open db-h/-1.log: $!");
746 utime(time,time,"db-h");
748 &sendmailmessage($reply,$replyto,@maintccaddrs,@bcc);
750 unlink("incoming/P$nn") || &quit("unlinking incoming/P$nn: $!");
752 sub sendmailmessage {
753 local ($message,@recips) = @_;
754 $message = "X-Loop: $gMaintainerEmail\n" . $message;
755 print "mailing to >@recips<\n" if $debug;
757 defined($c) || &quit("mailing forking for sendmail: $!");
758 if (!$c) { # ie, we are the child process
759 exec '/usr/lib/sendmail','-f'."$gMaintainerEmail",'-odb','-oem','-oi',get_addresses(@recips);
762 print(D $message) || &quit("writing to sendmail process: $!");
763 $!=0; close(D); $? && &quit("sendmail gave exit status $? ($!)");
768 &sendtxthelpraw("bug-log-mailserver.txt","instructions for request\@$gEmailDomain");
769 &sendtxthelpraw("bug-maint-mailcontrol.txt","instructions for control\@$gEmailDomain")
774 # &transcript("Sorry, command $_[0] not yet implemented.\n\n");
778 local ($string,$mvarname,$svarvalue) = @_;
781 eval "\$mvarvalue= \$$mvarname";
782 &transcript("D| checkmatch \`$string' /$mvarname/$mvarvalue/$svarvalue/\n")
785 "Values for \`$string' don't match:\n".
786 " #$newmergelist[0] has \`$mvarvalue';\n".
787 " #$ref has \`$svarvalue'\n"
788 if $mvarvalue ne $svarvalue;
790 &transcript("D| setupmatch \`$string' /$mvarname/$svarvalue/\n")
792 eval "\$$mvarname= \$svarvalue";
796 # High-level bug manipulation calls
797 # Do announcements themselves
799 # Possible calling sequences:
803 # &transcript(something)
807 # $action= (something)
809 # (modify s_* variables)
810 # } while (getnextbug);
813 &dlen("nochangebug");
814 $state eq 'single' || $state eq 'multiple' || die "$state ?";
816 &endmerge if $manybugs;
818 &dlex("nochangebug");
822 &dlen("setbug $ref");
823 if ($ref =~ m/^-\d+/) {
824 if (!defined $clonebugs{$ref}) {
826 &dlex("setbug => noclone");
829 $ref = $clonebugs{$ref};
831 $state eq 'idle' || die "$state ?";
834 &dlex("setbug => 0s");
838 if (keys(%limit_pkgs) && not defined $limit_pkgs{$data->{package}}) {
839 &transcript("$gBug number $ref belongs to package $data->{package}, skipping.\n\n");
844 @thisbugmergelist= split(/ /,$data->{mergedwith});
845 if (!@thisbugmergelist) {
850 &dlex("setbug => 1s");
859 &dlex("setbug => 0mc");
863 $state= 'multiple'; $sref=$ref;
864 &dlex("setbug => 1m");
870 $state eq 'single' || $state eq 'multiple' || die "$state ?";
872 if (!$manybugs || !@thisbugmergelist) {
873 length($action) || die;
874 &transcript("$action\n$extramessage\n");
875 &endmerge if $manybugs;
877 &dlex("getnextbug => 0");
880 $ref= shift(@thisbugmergelist);
881 &getbug || die "bug $ref disappeared";
883 &dlex("getnextbug => 1");
887 # Low-level bug-manipulation calls
888 # Do no announcements
896 # $action= (something)
901 # [getbug (returns 0)]
902 # &transcript("$action\n\n")
905 sub notfoundbug { &transcript("$gBug number $ref not found.\n\n"); }
906 sub foundbug { &transcript("$gBug#$ref: $data->{subject}\n"); }
910 $mergelowstate eq 'idle' || die "$mergelowstate ?";
911 &filelock('lock/merge');
912 $mergelowstate='locked';
918 $mergelowstate eq 'locked' || die "$mergelowstate ?";
920 $mergelowstate='idle';
925 &dlen("getbug $ref");
926 $lowstate eq 'idle' || die "$state ?";
927 if (($data = &lockreadbug($ref))) {
930 &dlex("getbug => 1");
935 &dlex("getbug => 0");
941 $lowstate eq 'open' || die "$state ?";
948 &dlen("savebug $ref");
949 $lowstate eq 'open' || die "$lowstate ?";
950 length($action) || die;
951 $ref == $sref || die "read $sref but saving $ref ?";
952 my $hash = get_hashname($ref);
953 open(L,">>db-h/$hash/$ref.log") || &quit("opening db-h/$hash/$ref.log: $!");
956 "<strong>".&sani($action)."</strong>\n".
957 "Request was from <code>".&sani($header{'from'})."</code>\n".
958 "to <code>".&sani($controlrequestaddr)."</code>. \n".
960 "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/$hash/$ref.log: $!");
961 close(L) || &quit("closing db-h/$hash/$ref.log: $!");
962 unlockwritebug($ref, $data);
969 &transcript("C> @_ ($state $lowstate $mergelowstate)\n");
974 &transcript("R> @_ ($state $lowstate $mergelowstate)\n");
978 print $_[0] if $debug;
986 my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
987 $url =~ s/([<>&"])/\&$saniarray{$1};/g;
1003 sub sendtxthelpraw {
1004 local ($relpath,$description) = @_;
1006 open(D,"$gDocDir/$relpath") || &quit("open doc file $relpath: $!");
1007 while(<D>) { $doc.=$_; }
1009 &transcript("Sending $description in separate message.\n");
1010 &sendmailmessage(<<END.$doc,$replyto);
1011 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1013 Subject: $gProject $gBug help: $description
1014 References: $header{'message-id'}
1015 In-Reply-To: $header{'message-id'}
1016 Message-ID: <handler.s.$nn.help.$midix\@$gEmailDomain>
1018 X-$gProject-PR-Message: doc-text $relpath
1024 sub sendlynxdocraw {
1025 local ($relpath,$description) = @_;
1027 open(L,"lynx -nolist -dump http://$gCGIDomain/\Q$relpath\E 2>&1 |") || &quit("fork for lynx: $!");
1028 while(<L>) { $doc.=$_; }
1030 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1031 &transcript("Information ($description) is not available -\n".
1032 "perhaps the $gBug does not exist or is not on the WWW yet.\n");
1035 &transcript("Error getting $description (code $? $!):\n$doc\n");
1037 &transcript("Sending $description.\n");
1038 &sendmailmessage(<<END.$doc,$replyto);
1039 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1041 Subject: $gProject $gBugs information: $description
1042 References: $header{'message-id'}
1043 In-Reply-To: $header{'message-id'}
1044 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1046 X-$gProject-PR-Message: doc-html $relpath
1055 $maintccreasons{$cca}{''}{$ref}= 1;
1058 sub addmaintainers {
1059 # Data structure is:
1060 # maintainer email address &c -> assoc of packages -> assoc of bug#'s
1063 &ensuremaintainersloaded;
1064 $anymaintfound=0; $anymaintnotfound=0;
1065 for $p (split(m/[ \t?,():]+/, $data->{package})) {
1067 $p =~ /([a-z0-9.+-]+)/;
1069 next unless defined $p;
1070 if (defined $gSubscriptionDomain) {
1071 if (defined($pkgsrc{$p})) {
1072 addbcc("$pkgsrc{$p}\@$gSubscriptionDomain");
1074 addbcc("$p\@$gSubscriptionDomain");
1077 if (defined $data->{severity} and defined $gStrongList and
1078 isstrongseverity($data->{severity})) {
1079 addbcc("$gStrongList\@$gListDomain");
1081 if (defined($maintainerof{$p})) {
1082 $addmaint= $maintainerof{$p};
1083 &transcript("MR|$addmaint|$p|$ref|\n") if $dl>2;
1084 $maintccreasons{$addmaint}{$p}{$ref}= 1;
1085 print "maintainer add >$p|$addmaint<\n" if $debug;
1087 print "maintainer none >$p<\n" if $debug;
1088 &transcript("Warning: Unknown package '$p'\n");
1089 &transcript("MR|unknown-package|$p|$ref|\n") if $dl>2;
1090 $maintccreasons{$gUnknownMaintainerEmail}{$p}{$ref}= 1;
1094 if (length $data->{owner}) {
1095 $addmaint = $data->{owner};
1096 &transcript("MO|$addmaint|$data->{package}|$ref|\n") if $dl>2;
1097 $maintccreasons{$addmaint}{$data->{package}}{$ref} = 1;
1098 print "owner add >$data->{package}|$addmaint<\n" if $debug;
1102 sub ensuremaintainersloaded {
1104 return if $maintainersloaded++;
1105 open(MAINT,"$gMaintainerFile") || die &quit("maintainers open: $!");
1109 m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers bogus \`$_'");
1110 $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
1111 $maintainerof{$1}= $2;
1114 open(MAINT,"$gMaintainerFileOverride") || die &quit("maintainers.override open: $!");
1118 m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers.override bogus \`$_'");
1119 $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
1120 $maintainerof{$1}= $2;
1123 open(SOURCES, "$gPackageSource") || &quit("pkgsrc open: $!");
1125 next unless m/^(\S+)\s+\S+\s+(\S.*\S)\s*$/;
1126 my ($a, $b) = ($1, $2);
1127 $pkgsrc{lc($a)} = $b;
1133 local ($wherefrom,$path,$description) = @_;
1134 if ($wherefrom eq "ftp.d.o") {
1135 $doc = `lynx -nolist -dump http://ftp.debian.org/debian/indices/$path.gz 2>&1 | gunzip -cf` or &quit("fork for lynx/gunzip: $!");
1137 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1138 &transcript("$description is not available.\n");
1141 &transcript("Error getting $description (code $? $!):\n$doc\n");
1144 } elsif ($wherefrom eq "local") {
1146 $doc = do { local $/; <P> };
1149 &transcript("internal errror: info files location unknown.\n");
1152 &transcript("Sending $description.\n");
1153 &sendmailmessage(<<END.$doc,$replyto);
1154 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1156 Subject: $gProject $gBugs information: $description
1157 References: $header{'message-id'}
1158 In-Reply-To: $header{'message-id'}
1159 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1161 X-$gProject-PR-Message: getinfo
1163 $description follows: