3 # Usage: service <code>.nn
4 # Temps: incoming/P<code>.nn
7 require('/etc/debbugs/config');
8 require('/usr/lib/debbugs/errorlib');
9 $ENV{'PATH'}= '/usr/lib/debbugs'.$ENV{'PATH'};;
10 chdir("$gSpoolDir") || die "chdir spool: $!\n";
16 # defined($intdate= time) || &quit("failed to get time: $!");
19 m/^[RC]\.\d+$/ || &quit("bad argument");
22 if (!rename("incoming/G$nn","incoming/P$nn")) {
23 $_=$!.''; m/no such file or directory/i && exit 0;
24 &quit("renaming to lock: $!");
27 open(M,"incoming/P$nn");
32 grep((s/\n$//,s/\s+$//),@msg);
34 print DEBUG "###\n",join("##\n",@msg),"\n###\n";
36 chop($tdate= `date -u '+%a, %d %h 19%y %T GMT'`);
38 Received: via spool for service; $tdate
41 for ($i=0; $i<=$#msg; $i++) {
43 last unless length($_);
45 while ($msg[$i+1] =~ m/^\s/) {
47 $fwd .= $msg[$i]."\n" if $ins; # Huh ? Where is ins set ?
50 # print DEBUG ">$_<\n";
52 $v= $1; $v =~ y/A-Z/a-z/;
53 print DEBUG ">$v=$_<\n";
56 print DEBUG "!>$_<\n";
60 defined($header{'from'}) || &quit("no From header");
61 $replyto= defined($header{'reply-to'}) ? $header{'reply-to'} : $header{'from'};
63 $controlrequestaddr= $control ? "control\@$gEmailDomain" : "request\@$gEmailDomain";
65 &transcript("Processing commands for $controlrequestaddr:\n\n");
70 $mergelowstate= 'idle';
73 for ($procline=$i; $procline<=$#msg; $procline++) {
74 $state eq 'idle' || "$state ?";
75 $lowstate eq 'idle' || "$lowstate ?";
76 $mergelowstate eq 'idle' || "$mergelowstate ?";
77 $_= $msg[$procline]; s/\s+$//;
78 next unless m/\S/; next if m/^\s*\#/;
79 &transcript("> $_\n");
81 if (m/^stop$/ || m/^quit$/ || m/^--/ || m/^thank/) {
82 &transcript("Stopping processing here.\n\n");
84 } elsif (m/^debug\s+(\d+)$/ && $1 >= 0 && $1 <= 1000) {
86 &transcript("Debug level $dl.\n\n");
87 } elsif (m/^(send|get)\s+\#?(\d{3,})$/) {
88 $ref= $2+0; $reffile= $ref; $reffile =~ s,^..,$&/$&,;
89 &sendlynxdoc("db/$reffile.html","logs for $gBug#$ref");
90 } elsif (m/^send-detail\s+\#?(\d+)$/) {
91 $ref= $1+0; $reffile= $ref; $reffile =~ s,^..,$&/$&,;
92 &sendlynxdoc("db/$reffile-b.html","additional logs for $gBug#$ref");
93 } elsif (m/^index(\s+full)?$/) {
94 &sendlynxdoc("db/ix/full.html",'full index');
95 } elsif (m/^index-summary\s+by-package$/) {
96 &sendlynxdoc("db/ix/psummary.html",'summary index sorted by package/title');
97 } elsif (m/^index-summary(\s+by-number)?$/) {
98 &sendlynxdoc("db/ix/summary.html",'summary index sorted by number/date');
99 } elsif (m/^index(\s+|-)pack(age)?s?$/) {
100 &sendlynxdoc("db/ix/packages.html",'index of packages');
101 } elsif (m/^index(\s+|-)maints?$/) {
102 &sendlynxdoc("db/ix/maintainers.html",'index of maintainers');
103 } elsif (m/^index(\s+|-)maint\s+(\S.*\S)$/) {
104 $substrg= $2; $matches=0;
105 opendir(DBD,"$gWebDir/db/ma") || die $!;
106 while (defined($_=readdir(DBD))) {
107 next unless m/^l/ && m/\.html$/;
108 &transcript("F|$_\n") if $dl>1;
109 $filename= $_; s/^l//; s/\.html$//;
110 &transcript("P|$_\n") if $dl>2;
111 while (s/-(..)([^_])/-$1_-$2/) { }
112 &transcript("P|$_\n") if $dl>2;
113 s/^(.{0,2})_/$1-20_/g; while (s/([^-]..)_/$1-20_/) { };
114 &transcript("P|$_\n") if $dl>2;
115 s/^,(.*),(.*),([^,]+)$/$1-40_$2-20_-28_$3-29_/;
116 &transcript("P|$_\n") if $dl>2;
117 s/^([^,]+),(.*),(.*),$/$1-20_-3c_$2-40_$3-3e_/;
118 &transcript("P|$_\n") if $dl>2;
120 &transcript("P|$_\n") if $dl>2;
122 while (m/-(..)_/) { $out.= $`.sprintf("%c",hex($1)); $_=$'; }
124 &transcript("M|$out\n") if $dl>1;
125 next unless index(lc $out, lc $substrg)>=0;
126 &transcript("S|$filename\n") if $dl>0;
127 &transcript("S|$out\n") if $dl>0;
129 &sendlynxdocraw("db/ma/$filename","$gBug list for maintainer \`$out'");
132 &transcript("$gBug list(s) for $matches maintainer(s) sent.\n\n");
134 &transcript("No maintainers found containing \`$substrg'.\n".
135 "Use \`index-maint' to get list of maintainers.\n\n");
138 } elsif (m/^index(\s+|-)pack(age)?s?\s+(\S.*\S)$/) {
139 $substrg= $+; $matches=0;
140 opendir(DBD,"$gWebDir/db/pa") || die $!;
141 while (defined($_=readdir(DBD))) {
142 next unless m/^l/ && m/\.html$/;
143 &transcript("F|$_\n") if $dl>1;
144 $filename= $_; s/^l//; s/\.html$//;
145 next unless index(lc $_, lc $substrg)>=0;
146 &transcript("S|$filename\n") if $dl>0;
147 &transcript("S|$out\n") if $dl>0;
149 &sendlynxdocraw("db/pa/$filename","$gBug list for package \`$_'");
152 &transcript("$gBug list(s) for $matches package(s) sent.\n\n");
154 &transcript("No packages found containing \`$substrg'.\n".
155 "Use \`index-packages' to get list of packages.\n\n");
158 } elsif (m/^send-unmatched(\s+this|\s+-?0)?$/) {
159 &sendlynxdoc("db/ju/unmatched-1.html","junk (this week)");
160 } elsif (m/^send-unmatched\s+(last|-1)$/) {
161 &sendlynxdoc("db/ju/unmatched-2.html","junk (last week)");
162 } elsif (m/^send-unmatched\s+(old|-2)$/) {
163 &sendlynxdoc("db/ju/unmatched-3.html","junk (two weeks ago)");
164 } elsif (m/^getinfo\s+(\S+)$/) {
166 if ($file =~ m/^\./ || $file !~ m/^[-.0-9a-z]+$/ || $file =~ m/\.gz$/) {
167 &transcript("Filename $file is badly formatted.\n\n");
168 } elsif (open(P,"$gDocDir/$file")) {
170 &transcript("Info file $file appears below.\n\n");
171 $extras.= "\n---------- Info file $file follows:\n\n";
172 while(<P>) { $extras.= $_; }
175 &transcript("Info file $file does not exist.\n\n");
177 } elsif (m/^help$/) {
181 } elsif (m/^refcard$/) {
182 &sendtxthelp("bug-mailserver-refcard.txt","mailservers' reference card");
183 } elsif (m/^subscribe/) {
185 There is no $gProject $gBug mailing list. If you wish to review bug reports
186 please do so via http://$gWebUrl/ or ask this mailserver
188 soon: MAILINGLISTS_TEXT
190 } elsif (m/^unsubscribe/) {
192 soon: UNSUBSCRIBE_TEXT
193 soon: MAILINGLISTS_TEXT
195 } elsif (!$control) {
197 Unknown command or malformed arguments to command.
198 (Use control\@$gEmailDomain to manipulate reports.)
201 if (++$unknowns >= 3) {
202 &transcript("Too many unknown commands, stopping here.\n\n");
205 } elsif (m/^close\s+\#?(\d+)$/) {
209 if (length($s_done)) {
210 &transcript("$gBug is already closed, cannot re-close.\n\n");
213 $action= "$gBug closed, ack sent to submitter - they'd better know why !";
215 &addmaintainers($s_package);
216 if ( length( $gDoneList ) > 0 && length( $gListDomain ) >
217 0 ) { &addccaddress("$gDoneList\@$gListDomain"); }
220 From: $gMaintainerEmail ($gMaintainer)
222 Subject: $gBug#$ref acknowledged by developer
224 References: $header{'message-id'} $s_msgid
225 In-Reply-To: $s_msgid
226 Message-ID: <handler.$ref.$nn.notifdonectrl.$midix\@$gEmailDomain>
228 This is an automatic notification regarding your $gBug report.
230 It has been marked as closed by one of the developers, namely
233 You should be hearing from them with a substantive response shortly,
234 if you have not already done so. If not, please contact them
235 directly, or email DB_SUBMIT_ADDRPQ or myself.
238 (administrator, $gProject $gBugs database)
240 &sendmailmessage($message,$s_originator);
241 } while (&getnextbug);
244 } elsif (m/^reassign\s+\#?(\d+)\s+(\S.*\S)$/) {
246 $ref= $1; $newpackage= $2;
248 if (length($s_package)) {
249 $action= "$gBug reassigned from package \`$s_package'".
250 " to \`$newpackage'.";
252 $action= "$gBug assigned to package \`$newpackage'.";
255 &addmaintainers($s_package);
256 &addmaintainers($newpackage);
257 $s_package= $newpackage;
258 } while (&getnextbug);
260 } elsif (m/^reopen\s+\#?(\d+)$/ ? ($noriginator='', 1) :
261 m/^reopen\s+\#?(\d+)\s+\=$/ ? ($noriginator='', 1) :
262 m/^reopen\s+\#?(\d+)\s+\!$/ ? ($noriginator=$replyto, 1) :
263 m/^reopen\s+\#?(\d+)\s+(\S.*\S)$/ ? ($noriginator=$2, 1) : 0) {
267 if (!length($s_done)) {
268 &transcript("$gByg is already open, cannot reopen.\n\n");
272 $noriginator eq '' ? "$gBug reopened, originator not changed." :
273 "$gBug reopened, originator set to $noriginator.";
275 &addmaintainers($s_package);
276 $s_originator= $noriginator eq '' ? $s_originator : $noriginator;
278 } while (&getnextbug);
281 } elsif (m/^forwarded\s+\#?(\d+)\s+(\S.*\S)$/) {
283 $ref= $1; $whereto= $2;
285 if (length($s_forwarded)) {
286 $action= "Forwarded-to-address changed from $s_forwarded to $whereto.";
288 $action= "Noted your statement that $gBug has been forwarded to $whereto.";
290 if (length($s_done)) {
291 $extramessage= "(By the way, this $gBug is currently marked as done.)\n";
294 &addmaintainers($s_package);
295 if (length($gFowardList)>0 && length($gListDomain)>0 )
296 { &addccaddress("$gFowardList\@$gListDomain"); }
297 $s_forwarded= $whereto;
298 } while (&getnextbug);
300 } elsif (m/^notforwarded\s+\#?(\d+)$/) {
304 if (!length($s_forwarded)) {
305 &transcript("$gBug is not marked as having been forwarded.\n\n");
308 $action= "Removed annotation that $gBug had been forwarded to $s_forwarded.";
310 &addmaintainers($s_package);
312 } while (&getnextbug);
315 } elsif (m/^severity\s+\#?(\d+)\s+([-0-9a-z]+)$/) {
319 if (!grep($_ eq $newseverity, @severities, "$gDefaultSeverity")) {
320 &transcript("Severity level \`$newseverity' is not known.\n".
321 "Recognised are: ".join(' ',@showseverities).".\n\n");
323 $printseverity= $s_severity;
324 $printseverity= "$gDefaultSeverity" if $printseverity eq '';
325 $action= "Severity set to \`$newseverity'.";
327 &addmaintainers($s_package);
328 $s_severity= $newseverity;
329 } while (&getnextbug);
331 } elsif (m/^retitle\s+\#?(\d+)\s+(\S.*\S)\s*$/) {
333 $ref= $1; $newtitle= $2;
336 &addmaintainers($s_package);
337 $s_subject= $newtitle;
338 $action= "Changed $gBug title.";
340 &transcript("$action\n");
341 if (length($s_done)) {
342 &transcript("(By the way, that $gBug is currently marked as done.)\n");
348 } elsif (m/^unmerge\s+\#?(\d+)$/) {
352 if (!length($s_mergedwith)) {
353 &transcript("$gBug is not marked as being merged with any others.\n\n");
356 $mergelowstate eq 'locked' || die "$mergelowstate ?";
357 $action= "Disconnected #$ref from all other report(s).";
358 @newmergelist= split(/ /,$s_mergedwith);
361 &addmaintainers($s_package);
362 $s_mergedwith= ($ref == $discref) ? ''
363 : join(' ',grep($_ ne $ref,@newmergelist));
364 } while (&getnextbug);
367 } elsif (m/^merge\s(\d+(\s+\d+)+)\s*$/) {
369 @tomerge= sort { $a <=> $b } split(/\s+/,$1);
372 while (defined($ref= shift(@tomerge))) {
373 &transcript("D| checking merge $ref\n") if $dl;
375 next if grep($_ eq $ref,@newmergelist);
376 if (!&getbug) { ¬foundbug; @newmergelist=(); last }
378 &transcript("D| adding $ref ($s_mergewith)\n") if $dl;
380 &checkmatch('package','m_package',$s_package);
381 &checkmatch('forwarded addr','m_forwarded',$s_forwarded);
382 &checkmatch('severity','m_severity',$s_severity);
383 &checkmatch('done mark','m_done',length($s_done) ? 'done' : 'open');
384 if (length($mismatch)) {
385 &transcript("Mismatch - only $Bugs in same state can be merged:\n".
387 &cancelbug; @newmergelist=(); last;
389 push(@newmergelist,$ref);
390 push(@tomerge,split(/ /,$s_mergedwith));
394 @newmergelist= sort { $a <=> $b } @newmergelist;
395 $action= "Merged @newmergelist.";
396 for $ref (@newmergelist) {
397 &getbug || die "huh ? $gBug $ref disappeared during merge";
398 &addmaintainers($s_package);
399 $s_mergedwith= join(' ',grep($_ ne $ref,@newmergelist));
402 &transcript("$action\n\n");
406 &transcript("Unknown command or malformed arguments to command.\n\n");
407 if (++$unknowns >= 5) {
408 &transcript("Too many unknown commands, stopping here.\n\n");
413 if ($procline>$#msg) {
414 &transcript(">\nEnd of message, stopping processing here.\n\n");
417 &transcript("No commands successfully parsed; sending the help text(s).\n");
422 &transcript("MC\n") if $dl>1;
424 for $maint (keys %maintccreasons) {
425 &transcript("MM|$maint|\n") if $dl>1;
426 next if $maint eq $replyto;
428 $reasonsref= $maintccreasons{$maint};
429 &transcript("MY|$maint|\n") if $dl>2;
430 for $p (sort keys %$reasonsref) {
431 &transcript("MP|$p|\n") if $dl>2;
432 $reasonstring.= ', ' if length($reasonstring);
433 $reasonstring.= $p.' ' if length($p);
434 $reasonstring.= join(' ',map("#$_",sort keys %{$$reasonsref{$p}}));
436 push(@maintccs,"$maint ($reasonstring)");
437 push(@maintccaddrs,"$maint");
440 &transcript("MC|@maintccs|\n") if $dl>2;
441 $maintccs= "Cc: ".join(",\n ",@maintccs)."\n";
445 From: $gMaintainerEmail ($gMaintainer)
447 ${maintccs}Subject: Processed: $header{'subject'}
448 In-Reply-To: $header{'message-id'}
449 References: $header{'message-id'}
450 Message-ID: <handler.s.$nn.transcript\@$gEmailDomain>
452 ${transcript}Please contact me if you need assistance.
455 (administrator, $gProject $gBugs database)
459 $repliedshow= join(', ',$replyto,@maintccaddrs);
460 &filelock("lock/-1");
461 open(AP,">>db/-1.log") || &quit("open db/-1.log: $!");
463 "\2\n$repliedshow\n\5\n$reply\n\3\n".
465 "<strong>Request received</strong> from <code>".
466 &sani($header{'from'})."</code>\n".
467 "to <code>".&sani($controlrequestaddr)."</code>\n".
469 "\7\n",@log,"\n\3\n") || &quit("writing db/-1.log: $!");
470 close(AP) || &quit("open db/-1.log: $!");
472 utime(time,time,"db");
474 &sendmailmessage($reply,$replyto,@maintccaddrs);
476 unlink("incoming/P$nn") || &quit("unlinking incoming/P$nn: $!");
480 map { $_->address() }
481 map { Mail::Address->parse($_) } @_;
484 sub sendmailmessage {
485 local ($message,@recips) = @_;
486 print DEBUG "mailing to >@recips<\n";
488 defined($c) || &quit("mailing forking for sendmail: $!");
489 if (!$c) { # ie, we are the child process
490 exec '/usr/lib/sendmail','-f'."$gMaintainerEmail",'-odi','-oem','-oi',get_addresses(@recips);
493 print(D $message) || &quit("writing to sendmail process: $!");
494 $!=0; close(D); $? && &quit("sendmail gave exit status $? ($!)");
499 &sendtxthelpraw("bug-log-mailserver.txt","instructions for request\@$gEmailDomain");
500 &sendtxthelpraw("bug-maint-mailcontrol.txt","instructions for control\@$gEmailDomain")
505 # &transcript("Sorry, command $_[0] not yet implemented.\n\n");
509 local ($string,$mvarname,$svarvalue) = @_;
512 eval "\$mvarvalue= \$$mvarname";
513 &transcript("D| checkmatch \`$string' /$mvarname/$mvarvalue/$svarvalue/\n")
516 "Values for \`$string' don't match:\n".
517 " #$newmergelist[0] has \`$mvarvalue';\n".
518 " #$ref has \`$svarvalue'\n"
519 if $mvarvalue ne $svarvalue;
521 &transcript("D| setupmatch \`$string' /$mvarname/$svarvalue/\n")
523 eval "\$$mvarname= \$svarvalue";
527 # High-level bug manipulation calls
528 # Do announcements themselves
530 # Possible calling sequences:
534 # &transcript(something)
538 # $action= (something)
540 # (modify s_* variables)
541 # } while (getnextbug);
544 &dlen("nochangebug");
545 $state eq 'single' || $state eq 'multiple' || die "$state ?";
547 &endmerge if $manybugs;
549 &dlex("nochangebug");
553 &dlen("setbug $ref");
554 $state eq 'idle' || die "$state ?";
557 &dlex("setbug => 0s");
560 @thisbugmergelist= split(/ /,$s_mergedwith);
561 if (!@thisbugmergelist) {
566 &dlex("setbug => 1s");
575 &dlex("setbug => 0mc");
579 $state= 'multiple'; $sref=$ref;
580 &dlex("setbug => 1m");
586 $state eq 'single' || $state eq 'multiple' || die "$state ?";
588 if (!$manybugs || !@thisbugmergelist) {
589 length($action) || die;
590 &transcript("$action\n$extramessage\n");
591 &endmerge if $manybugs;
593 &dlex("getnextbug => 0");
596 $ref= shift(@thisbugmergelist);
597 &getbug || die "bug $ref disappeared";
599 &dlex("getnextbug => 1");
603 # Low-level bug-manipulation calls
604 # Do no announcements
612 # $action= (something)
617 # [getbug (returns 0)]
618 # &transcript("$action\n\n")
621 sub notfoundbug { &transcript("$gBug number $ref not found.\n\n"); }
622 sub foundbug { &transcript("$gBug#$ref: $s_subject\n"); }
626 $mergelowstate eq 'idle' || die "$mergelowstate ?";
627 &filelock('lock/merge');
628 $mergelowstate='locked';
634 $mergelowstate eq 'locked' || die "$mergelowstate ?";
636 $mergelowstate='idle';
641 &dlen("getbug $ref");
642 $lowstate eq 'idle' || die "$state ?";
643 if (&lockreadbug($ref)) {
646 &dlex("getbug => 1");
651 &dlex("getbug => 0");
657 $lowstate eq 'open' || die "$state ?";
664 &dlen("savebug $ref");
665 $lowstate eq 'open' || die "$lowstate ?";
666 length($action) || die;
667 $ref == $sref || die "read $sref but saving $ref ?";
668 open(L,">>db/$ref.log") || &quit("opening db/$ref.log: $!");
671 "<strong>".&sani($action)."</strong>\n".
672 "Request was from <code>".&sani($header{'from'})."</code>\n".
673 "to <code>".&sani($controlrequestaddr)."</code>. \n".
675 "\7\n",@log,"\n\3\n") || &quit("writing db/$ref.log: $!");
676 close(L) || &quit("closing db/$ref.log: $!");
677 open(S,">db/$ref.status.new") || &quit("opening db/$ref.status.new: $!");
688 "$s_severity\n") || &quit("writing db/$ref.status.new: $!");
689 close(S) || &quit("closing db/$ref.status.new: $!");
690 rename("db/$ref.status.new","db/$ref.status") ||
691 &quit("installing new db/$ref.status: $!");
699 &transcript("C> @_ ($state $lowstate $mergelowstate)\n");
704 &transcript("R> @_ ($state $lowstate $mergelowstate)\n");
725 local ($relpath,$description) = @_;
727 open(D,"$gDocDir/$relpath") || &quit("open doc file $relpath: $!");
728 while(<D>) { $doc.=$_; }
730 &transcript("Sending $description in separate message.\n");
731 &sendmailmessage(<<END.$doc,$replyto);
732 From: $gMaintainerEmail ($gMaintainer)
734 Subject: $gProject $gBug help: $description
735 References: $header{'message-id'}
736 In-Reply-To: $header{'message-id'}
737 Message-ID: <handler.s.$nn.help.$midix\@$gEmailDomain>
744 local ($relpath,$description) = @_;
746 open(L,"lynx -nolist -dump $wwwbase/$relpath 2>&1 |") || &quit("fork for lynx: $!");
747 while(<L>) { $doc.=$_; }
749 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
750 &transcript("Information ($description) is not available -\n".
751 "perhaps the $gBug does not exist or is not on the WWW yet.\n");
754 &transcript("Error getting $description (code $? $!):\n$doc\n");
756 &transcript("Sending $description.\n");
757 &sendmailmessage(<<END.$doc,$replyto);
758 From: $gMaintainerEmail ($gMaintainer)
760 Subject: $gProject $gBugs information: $description
761 References: $header{'message-id'}
762 In-Reply-To: $header{'message-id'}
763 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
772 $maintccreasons{$cca}{''}{$ref}= 1;
777 # maintainer email address &c -> assoc of packages -> assoc of bug#'s
778 my $p, $addmaint, $pshow;
779 &ensuremaintainersloaded;
780 $anymaintfound=0; $anymaintnotfound=0;
781 for $p (split(m/[ \t?,()]+/,$_[0])) {
783 $pshow= ($p =~ m/[-+.a-z0-9]+/ ? $& : '');
784 if (defined($maintainerof{$p})) {
785 $addmaint= $maintainerof{$p};
786 &transcript("MR|$addmaint|$p|$ref|\n") if $dl>2;
787 $maintccreasons{$addmaint}{$p}{$ref}= 1;
788 print DEBUG "maintainer add >$p|$addmaint<\n";
790 print DEBUG "maintainer none >$p<\n";
795 sub ensuremaintainersloaded {
797 return if $maintainersloaded++;
798 open(MAINT,"$gMaintainerFile") || die &quit("maintainers open: $!");
800 m/^(\S+)\s+(\S.*\S)\n$/ || &quit("maintainers bogus \`$_'");
801 $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
802 $maintainerof{$1}= $2;