2 # $Id: service.in,v 1.50 2002/08/26 15:36:06 ajt Exp $
5 # Usage: service <code>.nn
6 # Temps: incoming/P<code>.nn
11 $config_path = '/org/bugs.debian.org/etc';
12 $lib_path = '/org/bugs.debian.org/scripts';
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");
39 grep((s/\n$//,s/\s+$//),@msg);
41 print "###\n",join("##\n",@msg),"\n###\n" if $debug;
43 chop($tdate= `date -u '+%a, %d %h %Y %T GMT'`);
45 Received: via spool for service; $tdate
48 for ($i=0; $i<=$#msg; $i++) {
50 last unless length($_);
52 while ($msg[$i+1] =~ m/^\s/) {
54 $fwd .= $msg[$i]."\n" if $ins; # Huh ? Where is ins set ?
57 print ">$_<\n" if $debug;
59 $v= $1; $v =~ y/A-Z/a-z/;
60 print ">$v=$_<\n" if $debug;
63 print "!>$_<\n" if $debug;
67 if (defined $header{'resent-from'} && !defined $header{'from'}) {
68 $header{'from'} = $header{'resent-from'};
71 defined($header{'from'}) || &quit("no From header");
73 delete $header{'reply-to'}
74 if ( defined($header{'reply-to'}) && $header{'reply-to'} =~ m/^\s*$/ );
76 if ( defined($header{'reply-to'}) && $header{'reply-to'} ne "" ) {
77 $replyto = $header{'reply-to'};
79 $replyto = $header{'from'};
82 $controlrequestaddr= $control ? "control\@$gEmailDomain" : "request\@$gEmailDomain";
84 &transcript("Processing commands for $controlrequestaddr:\n\n");
89 $mergelowstate= 'idle';
93 #strip blank line(s) after header
94 while ( $i <= $#msg && !length( $msg[$i] ) ) { $fwd .= "\n"; $i++; }
98 my $fuckheads = "(" . join("|", @gFuckheads) . ")";
99 if (@gFuckheads and $replyto =~ m/$fuckheads/) {
100 &transcript("This service is unavailable.\n\n");
104 #strip, if exists, mime header
105 if ( $msg[$i] =~ /^This is a multi-part message in MIME format./ ) {
106 while ( $i <= $#msg && length( $msg[$i] ) ) {
107 $fwd .= $msg[$i] . "\n"; $i++;
109 while ( $i <= $#msg && !length( $msg[$i] ) ) {
113 if ( $msg[$i] =~ /^--/ || $msg[$i] =~ /^\s*$/ ) {
114 while ( $i <= $#msg && length( $msg[$i] ) ) { $fwd .= $msg[$i]; $i++; }
115 while ( $i <= $#msg && !length( $msg[$i] ) ) { $fwd .= "\n"; $i++; }
121 for ($procline=$i; $procline<=$#msg; $procline++) {
122 $state eq 'idle' || print "$state ?\n";
123 $lowstate eq 'idle' || print "$lowstate ?\n";
124 $mergelowstate eq 'idle' || print "$mergelowstate ?\n";
126 &transcript("Stopping processing here.\n\n");
129 $_= $msg[$procline]; s/\s+$//;
130 next unless m/\S/; next if m/^\s*\#/;
131 &transcript("> $_\n");
133 if (m/^stop/i || m/^quit/i || m/^--/ || m/^thank/i) {
134 &transcript("Stopping processing here.\n\n");
136 } elsif (m/^debug\s+(\d+)$/i && $1 >= 0 && $1 <= 1000) {
138 &transcript("Debug level $dl.\n\n");
139 } elsif (m/^(send|get)\s+\#?(\d{2,})$/i) {
141 &sendlynxdoc("$ref","logs for $gBug#$ref");
142 } elsif (m/^send-detail\s+\#?(\d+)$/i) {
143 &transcript("This BTS function is currently disabled, sorry.\n\n");
144 $ok++; # well, it's not really ok, but it fixes #81224 :)
145 # $ref= $1+0; $reffile= $ref; $reffile =~ s,^..,$&/$&,;
146 # &sendlynxdoc("db/$reffile-b.html","additional logs for $gBug#$ref");
147 } elsif (m/^index(\s+full)?$/i) {
148 &transcript("This BTS function is currently disabled, sorry.\n\n");
149 $ok++; # well, it's not really ok, but it fixes #81224 :)
150 # &sendlynxdoc("db/ix/full.html",'full index');
151 } elsif (m/^index-summary\s+by-package$/i) {
152 &transcript("This BTS function is currently disabled, sorry.\n\n");
153 $ok++; # well, it's not really ok, but it fixes #81224 :)
154 # &sendlynxdoc("db/ix/psummary.html",'summary index sorted by package/title');
155 } elsif (m/^index-summary(\s+by-number)?$/i) {
156 &transcript("This BTS function is currently disabled, sorry.\n\n");
157 $ok++; # well, it's not really ok, but it fixes #81224 :)
158 # &sendlynxdoc("db/ix/summary.html",'summary index sorted by number/date');
159 } elsif (m/^index(\s+|-)pack(age)?s?$/i) {
160 &sendlynxdoc("cgi-bin/pkgindex.cgi?indexon=pkg",'index of packages');
161 } elsif (m/^index(\s+|-)maints?$/i) {
162 &sendlynxdoc("cgi-bin/pkgindex.cgi?indexon=maint",'index of maintainers');
163 } elsif (m/^index(\s+|-)maint\s+(\S+)$/i) {
165 # check for crap in $maint
166 if ($maint =~ m/^\./ || $maint !~ m/^[\d\w-+.@]+$/) {
167 &transcript("Invalid request $maint!\n");
170 &sendlynxdoc("$maint","$gBug list for maintainer \`$maint'");
172 $substrg= $2; $matches=0;
173 opendir(DBD,"$gWebDir/db/ma") || die $!;
174 while (defined($_=readdir(DBD))) {
175 next unless m/^l/ && m/\.html$/;
176 &transcript("F|$_\n") if $dl>1;
177 $filename= $_; s/^l//; s/\.html$//;
178 &transcript("P|$_\n") if $dl>2;
179 while (s/-(..)([^_])/-$1_-$2/) { }
180 &transcript("P|$_\n") if $dl>2;
181 s/^(.{0,2})_/$1-20_/g; while (s/([^-]..)_/$1-20_/) { };
182 &transcript("P|$_\n") if $dl>2;
183 s/^,(.*),(.*),([^,]+)$/$1-40_$2-20_-28_$3-29_/;
184 &transcript("P|$_\n") if $dl>2;
185 s/^([^,]+),(.*),(.*),$/$1-20_-3c_$2-40_$3-3e_/;
186 &transcript("P|$_\n") if $dl>2;
188 &transcript("P|$_\n") if $dl>2;
190 while (m/-(..)_/) { $out.= $`.sprintf("%c",hex($1)); $_=$'; }
192 &transcript("M|$out\n") if $dl>1;
193 next unless index(lc $out, lc $substrg)>=0;
194 &transcript("S|$filename\n") if $dl>0;
195 &transcript("S|$out\n") if $dl>0;
197 &sendlynxdocraw("db/ma/$filename","$gBug list for maintainer \`$out'");
200 &transcript("$gBug list(s) for $matches maintainer(s) sent.\n\n");
202 &transcript("No maintainers found containing \`$substrg'.\n".
203 "Use \`index-maint' to get list of maintainers.\n\n");
207 } elsif (m/^index(\s+|-)pack(age)?s?\s+(\S.*\S)$/i) {
209 # check for crap in $package
210 if ($package =~ m/^\./ || $package !~ m/^[\d\w-+.@]+$/) {
211 &transcript("Invalid request $package!\n");
214 &sendlynxdoc("$package","$gBug list for package $package sent.\n\n");
216 $substrg= $+; $matches=0;
217 opendir(DBD,"$gWebDir/db/pa") || die $!;
218 while (defined($_=readdir(DBD))) {
219 next unless m/^l/ && m/\.html$/;
220 &transcript("F|$_\n") if $dl>1;
221 $filename= $_; s/^l//; s/\.html$//;
222 next unless index(lc $_, lc $substrg)>=0;
223 &transcript("S|$filename\n") if $dl>0;
224 &transcript("S|$out\n") if $dl>0;
226 &sendlynxdocraw("db/pa/$filename","$gBug list for package \`$_'");
229 &transcript("$gBug list(s) for $matches package(s) sent.\n\n");
231 &transcript("No packages found containing \`$substrg'.\n".
232 "Use \`index-packages' to get list of packages.\n\n");
236 } elsif (m/^send-unmatched(\s+this|\s+-?0)?$/i) {
237 &transcript("This BTS function is currently disabled, sorry.\n\n");
238 $ok++; # well, it's not really ok, but it fixes #81224 :)
239 # &sendlynxdoc("db/ju/unmatched-1.html","junk (this week)");
240 } elsif (m/^send-unmatched\s+(last|-1)$/i) {
241 &transcript("This BTS function is currently disabled, sorry.\n\n");
242 $ok++; # well, it's not really ok, but it fixes #81224 :)
243 # &sendlynxdoc("db/ju/unmatched-2.html","junk (last week)");
244 } elsif (m/^send-unmatched\s+(old|-2)$/i) {
245 &transcript("This BTS function is currently disabled, sorry.\n\n");
246 $ok++; # well, it's not really ok, but it fixes #81224 :)
247 # &sendlynxdoc("db/ju/unmatched-3.html","junk (two weeks ago)");
248 } elsif (m/^getinfo\s+([\w-.]+)$/i) {
249 # the following is basically a Debian-specific kludge, but who cares
251 if ($req =~ /^maintainers$/i && -f "$gConfigDir/Maintainers") {
252 &sendinfo("local", "$gConfigDir/Maintainers", "Maintainers file");
253 } elsif ($req =~ /^override\.(\w+)\.([\w-.]+)$/i) {
255 &sendinfo("ftp.d.o", "$req", "override file for $2 part of $1 distribution");
256 } elsif ($req =~ /^pseudo-packages\.(description|maintainers)$/i && -f "$gConfigDir/$req") {
257 &sendinfo("local", "$gConfigDir/$req", "$req file");
259 &transcript("Info file $req does not exist.\n\n");
261 } elsif (m/^help/i) {
265 } elsif (m/^refcard/i) {
266 &sendtxthelp("bug-mailserver-refcard.txt","mail servers' reference card");
267 } elsif (m/^subscribe/i) {
269 There is no $gProject $gBug mailing list. If you wish to review bug reports
270 please do so via http://$gWebDomain/ or ask this mail server
272 soon: MAILINGLISTS_TEXT
274 } elsif (m/^unsubscribe/i) {
276 soon: UNSUBSCRIBE_TEXT
277 soon: MAILINGLISTS_TEXT
279 } elsif (!$control) {
281 Unknown command or malformed arguments to command.
282 (Use control\@$gEmailDomain to manipulate reports.)
285 if (++$unknowns >= 3) {
286 &transcript("Too many unknown commands, stopping here.\n\n");
289 #### interesting ones start here
290 } elsif (m/^close\s+\#?(-?\d+)$/i) {
294 if (length($s_done)) {
295 &transcript("$gBug is already closed, cannot re-close.\n\n");
298 $action= "$gBug closed, send any further explanations to $s_originator";
300 &addmaintainers($s_package);
301 if ( length( $gDoneList ) > 0 && length( $gListDomain ) >
302 0 ) { &addccaddress("$gDoneList\@$gListDomain"); }
305 From: $gMaintainerEmail ($gProject $gBug Tracking System)
307 Subject: $gBug#$ref acknowledged by developer
309 References: $header{'message-id'} $s_msgid
310 In-Reply-To: $s_msgid
311 Message-ID: <handler.$ref.$nn.notifdonectrl.$midix\@$gEmailDomain>
312 Reply-To: $ref\@$gEmailDomain
314 This is an automatic notification regarding your $gBug report
316 which was filed against the $s_package package.
318 It has been marked as closed by one of the developers, namely
321 You should be hearing from them with a substantive response shortly,
322 in case you haven't already. If not, please contact them directly.
325 (administrator, $gProject $gBugs database)
328 &sendmailmessage($message,$s_originator);
329 } while (&getnextbug);
332 } elsif (m/^reassign\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
334 $ref= $1; $newpackage= $2;
335 $newpackage =~ y/A-Z/a-z/;
337 if (length($s_package)) {
338 $action= "$gBug reassigned from package \`$s_package'".
339 " to \`$newpackage'.";
341 $action= "$gBug assigned to package \`$newpackage'.";
344 &addmaintainers($s_package);
345 &addmaintainers($newpackage);
346 $s_package= $newpackage;
347 } while (&getnextbug);
349 } elsif (m/^reopen\s+\#?(-?\d+)$/i ? ($noriginator='', 1) :
350 m/^reopen\s+\#?(-?\d+)\s+\=$/i ? ($noriginator='', 1) :
351 m/^reopen\s+\#?(-?\d+)\s+\!$/i ? ($noriginator=$replyto, 1) :
352 m/^reopen\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($noriginator=$2, 1) : 0) {
356 if (!length($s_done)) {
357 &transcript("$gBug is already open, cannot reopen.\n\n");
361 $noriginator eq '' ? "$gBug reopened, originator not changed." :
362 "$gBug reopened, originator set to $noriginator.";
364 &addmaintainers($s_package);
365 $s_originator= $noriginator eq '' ? $s_originator : $noriginator;
367 } while (&getnextbug);
370 } elsif (m/^forwarded\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
372 $ref= $1; $whereto= $2;
374 if (length($s_forwarded)) {
375 $action= "Forwarded-to-address changed from $s_forwarded to $whereto.";
377 $action= "Noted your statement that $gBug has been forwarded to $whereto.";
379 if (length($s_done)) {
380 $extramessage= "(By the way, this $gBug is currently marked as done.)\n";
383 &addmaintainers($s_package);
384 if (length($gFowardList)>0 && length($gListDomain)>0 ) {
385 &addccaddress("$gFowardList\@$gListDomain");
387 $s_forwarded= $whereto;
388 } while (&getnextbug);
390 } elsif (m/^notforwarded\s+\#?(-?\d+)$/i) {
394 if (!length($s_forwarded)) {
395 &transcript("$gBug is not marked as having been forwarded.\n\n");
398 $action= "Removed annotation that $gBug had been forwarded to $s_forwarded.";
400 &addmaintainers($s_package);
402 } while (&getnextbug);
405 } elsif (m/^severity\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i ||
406 m/^priority\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i) {
410 if (!grep($_ eq $newseverity, @gSeverityList, "$gDefaultSeverity")) {
411 &transcript("Severity level \`$newseverity' is not known.\n".
412 "Recognized are: $gShowSeverities.\n\n");
414 $printseverity= $s_severity;
415 $printseverity= "$gDefaultSeverity" if $printseverity eq '';
416 $action= "Severity set to \`$newseverity'.";
418 &addmaintainers($s_package);
419 $s_severity= $newseverity;
420 } while (&getnextbug);
422 } elsif (m/^tags?\s+\#?(-?\d+)\s+(([=+-])\s+)?(\S.*)?$/i) {
424 $ref = $1; $addsubcode = $3; $tags = $4;
426 if (defined $addsubcode) {
427 $addsub = "sub" if ($addsubcode eq "-");
428 $addsub = "add" if ($addsubcode eq "+");
429 $addsub = "set" if ($addsubcode eq "=");
433 foreach my $t (split /[\s,]+/, $tags) {
434 if (!grep($_ eq $t, @gTags)) {
441 &transcript("Unknown tag/s: ".join(', ', @badtags).".\n".
442 "Recognized are: ".join(' ', @gTags).".\n\n");
445 if ($addsub eq "set") {
446 $action= "Tags set to: " . join(", ", @okaytags);
447 } elsif ($addsub eq "add") {
448 $action= "Tags added: " . join(", ", @okaytags);
449 } elsif ($addsub eq "sub") {
450 $action= "Tags removed: " . join(", ", @okaytags);
453 &addmaintainers($s_package);
454 $s_keywords = '' if ($addsub eq "set");
455 if ($addsub eq "sub") {
456 foreach my $t (@badtags) {
457 $s_keywords = join ' ', grep $_ ne $t,
458 split ' ', $s_keywords;
461 foreach my $t (@okaytags) {
462 $s_keywords = join ' ', grep $_ ne $t,
463 split ' ', $s_keywords;
464 $s_keywords = "$t $s_keywords" unless($addsub eq "sub");
466 $s_keywords =~ s/\s*$//;
467 } while (&getnextbug);
469 } elsif (m/^retitle\s+\#?(-?\d+)\s+(\S.*\S)\s*$/i) {
471 $ref= $1; $newtitle= $2;
472 if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
473 $ref = $clonebugs{$ref};
477 &addmaintainers($s_package);
478 $s_subject= $newtitle;
479 $action= "Changed $gBug title.";
481 &transcript("$action\n");
482 if (length($s_done)) {
483 &transcript("(By the way, that $gBug is currently marked as done.)\n");
489 } elsif (m/^unmerge\s+\#?(-?\d+)$/i) {
493 if (!length($s_mergedwith)) {
494 &transcript("$gBug is not marked as being merged with any others.\n\n");
497 $mergelowstate eq 'locked' || die "$mergelowstate ?";
498 $action= "Disconnected #$ref from all other report(s).";
499 @newmergelist= split(/ /,$s_mergedwith);
502 &addmaintainers($s_package);
503 $s_mergedwith= ($ref == $discref) ? ''
504 : join(' ',grep($_ ne $ref,@newmergelist));
505 } while (&getnextbug);
508 } elsif (m/^merge\s+(\d+(\s+\d+)+)\s*$/i) {
510 @tomerge= sort { $a <=> $b } split(/\s+/,$1);
514 while (defined($ref= shift(@tomerge))) {
515 &transcript("D| checking merge $ref\n") if $dl;
517 next if grep($_ eq $ref,@newmergelist);
518 if (!&getbug) { ¬foundbug; @newmergelist=(); last }
520 &transcript("D| adding $ref ($s_mergedwith)\n") if $dl;
522 &checkmatch('package','m_package',$s_package);
523 &checkmatch('forwarded addr','m_forwarded',$s_forwarded);
524 $s_severity = '$gDefaultSeverity' if $s_severity eq '';
525 &checkmatch('severity','m_severity',$s_severity);
526 &checkmatch('done mark','m_done',length($s_done) ? 'done' : 'open');
527 foreach my $t (split /\s+/, $s_keywords) { $tags{$t} = 1; }
528 if (length($mismatch)) {
529 &transcript("Mismatch - only $gBugs in same state can be merged:\n".
531 &cancelbug; @newmergelist=(); last;
533 push(@newmergelist,$ref);
534 push(@tomerge,split(/ /,$s_mergedwith));
538 @newmergelist= sort { $a <=> $b } @newmergelist;
539 $action= "Merged @newmergelist.";
540 for $ref (@newmergelist) {
541 &getbug || die "huh ? $gBug $ref disappeared during merge";
542 &addmaintainers($s_package);
543 $s_mergedwith= join(' ',grep($_ ne $ref,@newmergelist));
544 $s_keywords= join(' ', keys %tags);
547 &transcript("$action\n\n");
550 } elsif (m/^clone\s+#?(\d+)\s+((-\d+\s+)*-\d+)\s*$/i) {
554 @newclonedids = split /\s+/, $2;
555 $newbugsneeded = scalar(@newclonedids);
559 if (length($s_mergedwith)) {
560 &transcript("$gBug is marked as being merged with others.\n\n");
563 &filelock("nextnumber.lock");
564 open(N,"nextnumber") || &quit("nextnumber: read: $!");
565 $v=<N>; $v =~ s/\n$// || &quit("nextnumber bad format");
566 $firstref= $v+0; $v += $newbugsneeded;
567 open(NN,">nextnumber"); print NN "$v\n"; close(NN);
570 $lastref = $firstref + $newbugsneeded - 1;
572 if ($newbugsneeded == 1) {
573 $action= "$gBug $origref cloned as bug $firstref.";
575 $action= "$gBug $origref cloned as bugs $firstref-$lastref.";
578 my $ohash = get_hashname($origref);
580 for $newclonedid (@newclonedids) {
581 $clonebugs{$newclonedid} = $ref;
583 my $hash = get_hashname($ref);
584 copy("db-h/$ohash/$origref.log", "db-h/$hash/$ref.log");
585 copy("db-h/$ohash/$origref.status", "db-h/$hash/$ref.status");
586 copy("db-h/$ohash/$origref.report", "db-h/$hash/$ref.report");
587 &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");
588 link("db-h/$hash/$ref.log", "db/$ref.log");
589 link("db-h/$hash/$ref.status", "db/$ref.status");
590 link("db-h/$hash/$ref.report", "db/$ref.report");
597 &transcript("Unknown command or malformed arguments to command.\n\n");
598 if (++$unknowns >= 5) {
599 &transcript("Too many unknown commands, stopping here.\n\n");
604 if ($procline>$#msg) {
605 &transcript(">\nEnd of message, stopping processing here.\n\n");
607 if (!$ok && !quickabort) {
608 &transcript("No commands successfully parsed; sending the help text(s).\n");
613 &transcript("MC\n") if $dl>1;
615 for $maint (keys %maintccreasons) {
616 &transcript("MM|$maint|\n") if $dl>1;
617 next if $maint eq $replyto;
619 $reasonsref= $maintccreasons{$maint};
620 &transcript("MY|$maint|\n") if $dl>2;
621 for $p (sort keys %$reasonsref) {
622 &transcript("MP|$p|\n") if $dl>2;
623 $reasonstring.= ', ' if length($reasonstring);
624 $reasonstring.= $p.' ' if length($p);
625 $reasonstring.= join(' ',map("#$_",sort keys %{$$reasonsref{$p}}));
627 if (length($reasonstring) > 40) {
628 (substr $reasonstring, 37) = "...";
630 $reasonstring = "" if (!defined($reasonstring));
631 push(@maintccs,"$maint ($reasonstring)");
632 push(@maintccaddrs,"$maint");
637 &transcript("MC|@maintccs|\n") if $dl>2;
638 $maintccs .= "Cc: " . join(",\n ",@maintccs) . "\n";
641 &transcript("BCC|@bcc|\n") if $dl>2;
642 $maintccs .= "Bcc: " . join(,\n ", @bcc) . "\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",@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);
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 print "mailing to >@recips<\n" if $debug;
693 defined($c) || &quit("mailing forking for sendmail: $!");
694 if (!$c) { # ie, we are the child process
695 exec '/usr/lib/sendmail','-f'."$gMaintainerEmail",'-odb','-oem','-oi',get_addresses(@recips);
698 print(D $message) || &quit("writing to sendmail process: $!");
699 $!=0; close(D); $? && &quit("sendmail gave exit status $? ($!)");
704 &sendtxthelpraw("bug-log-mailserver.txt","instructions for request\@$gEmailDomain");
705 &sendtxthelpraw("bug-maint-mailcontrol.txt","instructions for control\@$gEmailDomain")
710 # &transcript("Sorry, command $_[0] not yet implemented.\n\n");
714 local ($string,$mvarname,$svarvalue) = @_;
717 eval "\$mvarvalue= \$$mvarname";
718 &transcript("D| checkmatch \`$string' /$mvarname/$mvarvalue/$svarvalue/\n")
721 "Values for \`$string' don't match:\n".
722 " #$newmergelist[0] has \`$mvarvalue';\n".
723 " #$ref has \`$svarvalue'\n"
724 if $mvarvalue ne $svarvalue;
726 &transcript("D| setupmatch \`$string' /$mvarname/$svarvalue/\n")
728 eval "\$$mvarname= \$svarvalue";
732 # High-level bug manipulation calls
733 # Do announcements themselves
735 # Possible calling sequences:
739 # &transcript(something)
743 # $action= (something)
745 # (modify s_* variables)
746 # } while (getnextbug);
749 &dlen("nochangebug");
750 $state eq 'single' || $state eq 'multiple' || die "$state ?";
752 &endmerge if $manybugs;
754 &dlex("nochangebug");
758 &dlen("setbug $ref");
759 if ($ref =~ m/^-\d+/) {
760 if (!defined $clonebugs{$ref}) {
762 &dlex("setbug => noclone");
765 $ref = $clonebugs{$ref};
767 $state eq 'idle' || die "$state ?";
770 &dlex("setbug => 0s");
773 @thisbugmergelist= split(/ /,$s_mergedwith);
774 if (!@thisbugmergelist) {
779 &dlex("setbug => 1s");
788 &dlex("setbug => 0mc");
792 $state= 'multiple'; $sref=$ref;
793 &dlex("setbug => 1m");
799 $state eq 'single' || $state eq 'multiple' || die "$state ?";
801 if (!$manybugs || !@thisbugmergelist) {
802 length($action) || die;
803 &transcript("$action\n$extramessage\n");
804 &endmerge if $manybugs;
806 &dlex("getnextbug => 0");
809 $ref= shift(@thisbugmergelist);
810 &getbug || die "bug $ref disappeared";
812 &dlex("getnextbug => 1");
816 # Low-level bug-manipulation calls
817 # Do no announcements
825 # $action= (something)
830 # [getbug (returns 0)]
831 # &transcript("$action\n\n")
834 sub notfoundbug { &transcript("$gBug number $ref not found.\n\n"); }
835 sub foundbug { &transcript("$gBug#$ref: $s_subject\n"); }
839 $mergelowstate eq 'idle' || die "$mergelowstate ?";
840 &filelock('lock/merge');
841 $mergelowstate='locked';
847 $mergelowstate eq 'locked' || die "$mergelowstate ?";
849 $mergelowstate='idle';
854 &dlen("getbug $ref");
855 $lowstate eq 'idle' || die "$state ?";
856 if (&lockreadbug($ref)) {
859 &dlex("getbug => 1");
864 &dlex("getbug => 0");
870 $lowstate eq 'open' || die "$state ?";
877 &dlen("savebug $ref");
878 $lowstate eq 'open' || die "$lowstate ?";
879 length($action) || die;
880 $ref == $sref || die "read $sref but saving $ref ?";
881 my $hash = get_hashname($ref);
882 open(L,">>db-h/$hash/$ref.log") || &quit("opening db-h/$hash/$ref.log: $!");
885 "<strong>".&sani($action)."</strong>\n".
886 "Request was from <code>".&sani($header{'from'})."</code>\n".
887 "to <code>".&sani($controlrequestaddr)."</code>. \n".
889 "\7\n",@log,"\n\3\n") || &quit("writing db-h/$hash/$ref.log: $!");
890 close(L) || &quit("closing db-h/$hash/$ref.log: $!");
891 open(S,">db-h/$hash/$ref.status.new") || &quit("opening db-h/$hash/$ref.status.new: $!");
902 "$s_severity\n") || &quit("writing db-h/$hash/$ref.status.new: $!");
903 close(S) || &quit("closing db-h/$hash/$ref.status.new: $!");
904 rename("db-h/$hash/$ref.status.new","db-h/$hash/$ref.status") ||
905 &quit("installing new db-h/$hash/$ref.status: $!");
906 &bughook('change',$ref,
924 &transcript("C> @_ ($state $lowstate $mergelowstate)\n");
929 &transcript("R> @_ ($state $lowstate $mergelowstate)\n");
933 print $_[0] if $debug;
950 local ($relpath,$description) = @_;
952 open(D,"$gDocDir/$relpath") || &quit("open doc file $relpath: $!");
953 while(<D>) { $doc.=$_; }
955 &transcript("Sending $description in separate message.\n");
956 &sendmailmessage(<<END.$doc,$replyto);
957 From: $gMaintainerEmail ($gProject $gBug Tracking System)
959 Subject: $gProject $gBug help: $description
960 References: $header{'message-id'}
961 In-Reply-To: $header{'message-id'}
962 Message-ID: <handler.s.$nn.help.$midix\@$gEmailDomain>
969 local ($relpath,$description) = @_;
971 # the below oughta use $gWebDomain but it can't
972 open(L,"lynx -nolist -dump http://bugs.debian.org/$relpath 2>&1 |") || &quit("fork for lynx: $!");
973 while(<L>) { $doc.=$_; }
975 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
976 &transcript("Information ($description) is not available -\n".
977 "perhaps the $gBug does not exist or is not on the WWW yet.\n");
980 &transcript("Error getting $description (code $? $!):\n$doc\n");
982 &transcript("Sending $description.\n");
983 &sendmailmessage(<<END.$doc,$replyto);
984 From: $gMaintainerEmail ($gProject $gBug Tracking System)
986 Subject: $gProject $gBugs information: $description
987 References: $header{'message-id'}
988 In-Reply-To: $header{'message-id'}
989 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
998 $maintccreasons{$cca}{''}{$ref}= 1;
1001 sub addmaintainers {
1002 # Data structure is:
1003 # maintainer email address &c -> assoc of packages -> assoc of bug#'s
1004 my ($p, $addmaint, $pshow);
1005 &ensuremaintainersloaded;
1006 $anymaintfound=0; $anymaintnotfound=0;
1007 for $p (split(m/[ \t?,()]+/,$_[0])) {
1009 $pshow= ($p =~ m/[-+.a-z0-9]+/ ? $& : '');
1010 if (defined($pkgsrc{$p})) {
1011 push @bcc, "$pkgsrc{$p}\@packages.qa.debian.org";
1013 push @bcc, "$p\@packages.qa.debian.org";
1015 if (defined($maintainerof{$p})) {
1016 $addmaint= $maintainerof{$p};
1017 &transcript("MR|$addmaint|$p|$ref|\n") if $dl>2;
1018 $maintccreasons{$addmaint}{$p}{$ref}= 1;
1019 print "maintainer add >$p|$addmaint<\n" if $debug;
1021 print "maintainer none >$p<\n" if $debug;
1022 &transcript("MR|unknown-package|$p|$ref|\n") if $dl>2;
1023 $maintccreasons{$gUnknownMaintainerEmail}{$p}{$ref}= 1;
1028 sub ensuremaintainersloaded {
1030 return if $maintainersloaded++;
1031 open(MAINT,"$gMaintainerFile") || die &quit("maintainers open: $!");
1035 m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers bogus \`$_'");
1036 $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
1037 $maintainerof{$1}= $2;
1040 open(MAINT,"$gMaintainerFileOverride") || die &quit("maintainers.override open: $!");
1044 m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers.override bogus \`$_'");
1045 $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
1046 $maintainerof{$1}= $2;
1049 open(SOURCES, "$gPackageSource") || &quit("pkgsrc open: $!");
1051 next unless m/^(\S+)\s+(\S.*\S)\s*$/;
1052 my ($a, $b) = ($1, $2);
1053 $pkgsrc{lc($a)} = $b;
1059 local ($wherefrom,$path,$description) = @_;
1060 if ($wherefrom eq "ftp.d.o") {
1061 $doc = `lynx -nolist -dump http://ftp.debian.org/debian/indices/$path.gz 2>&1 | gunzip -cf` or &quit("fork for lynx/gunzip: $!");
1063 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1064 &transcript("$description is not available.\n");
1067 &transcript("Error getting $description (code $? $!):\n$doc\n");
1070 } elsif ($wherefrom eq "local") {
1072 $doc = do { local $/; <P> };
1075 &transcript("internal errror: info files location unknown.\n");
1078 &transcript("Sending $description.\n");
1079 &sendmailmessage(<<END.$doc,$replyto);
1080 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1082 Subject: $gProject $gBugs information: $description
1083 References: $header{'message-id'}
1084 In-Reply-To: $header{'message-id'}
1085 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1087 $description follows: