2 # $Id: service.in,v 1.2 1999/09/02 22:27:29 gecko Exp $
4 # Usage: service <code>.nn
5 # Temps: incoming/P<code>.nn
8 require('/etc/debbugs/config');
9 require('/usr/lib/debbugs/errorlib');
10 $ENV{'PATH'}= '/usr/lib/debbugs'.$ENV{'PATH'};;
11 chdir("$gSpoolDir") || die "chdir spool: $!\n";
17 # defined($intdate= time) || &quit("failed to get time: $!");
20 m/^[RC]\.\d+$/ || &quit("bad argument");
23 if (!rename("incoming/G$nn","incoming/P$nn")) {
24 $_=$!.''; m/no such file or directory/i && exit 0;
25 &quit("renaming to lock: $!");
28 open(M,"incoming/P$nn");
33 grep((s/\n$//,s/\s+$//),@msg);
35 print DEBUG "###\n",join("##\n",@msg),"\n###\n";
37 chop($tdate= `date -u '+%a, %d %h 19%y %T GMT'`);
39 Received: via spool for service; $tdate
42 for ($i=0; $i<=$#msg; $i++) {
44 last unless length($_);
46 while ($msg[$i+1] =~ m/^\s/) {
48 $fwd .= $msg[$i]."\n" if $ins; # Huh ? Where is ins set ?
51 # print DEBUG ">$_<\n";
53 $v= $1; $v =~ y/A-Z/a-z/;
54 print DEBUG ">$v=$_<\n";
57 print DEBUG "!>$_<\n";
61 defined($header{'from'}) || &quit("no From header");
62 $replyto= defined($header{'reply-to'}) ? $header{'reply-to'} : $header{'from'};
64 $controlrequestaddr= $control ? "control\@$gEmailDomain" : "request\@$gEmailDomain";
66 &transcript("Processing commands for $controlrequestaddr:\n\n");
71 $mergelowstate= 'idle';
74 for ($procline=$i; $procline<=$#msg; $procline++) {
75 $state eq 'idle' || "$state ?";
76 $lowstate eq 'idle' || "$lowstate ?";
77 $mergelowstate eq 'idle' || "$mergelowstate ?";
78 $_= $msg[$procline]; s/\s+$//;
79 next unless m/\S/; next if m/^\s*\#/;
80 &transcript("> $_\n");
82 if (m/^stop$/ || m/^quit$/ || m/^--/ || m/^thank/) {
83 &transcript("Stopping processing here.\n\n");
85 } elsif (m/^debug\s+(\d+)$/ && $1 >= 0 && $1 <= 1000) {
87 &transcript("Debug level $dl.\n\n");
88 } elsif (m/^(send|get)\s+\#?(\d{3,})$/) {
89 $ref= $2+0; $reffile= $ref; $reffile =~ s,^..,$&/$&,;
90 &sendlynxdoc("db/$reffile.html","logs for $gBug#$ref");
91 } elsif (m/^send-detail\s+\#?(\d+)$/) {
92 $ref= $1+0; $reffile= $ref; $reffile =~ s,^..,$&/$&,;
93 &sendlynxdoc("db/$reffile-b.html","additional logs for $gBug#$ref");
94 } elsif (m/^index(\s+full)?$/) {
95 &sendlynxdoc("db/ix/full.html",'full index');
96 } elsif (m/^index-summary\s+by-package$/) {
97 &sendlynxdoc("db/ix/psummary.html",'summary index sorted by package/title');
98 } elsif (m/^index-summary(\s+by-number)?$/) {
99 &sendlynxdoc("db/ix/summary.html",'summary index sorted by number/date');
100 } elsif (m/^index(\s+|-)pack(age)?s?$/) {
101 &sendlynxdoc("db/ix/packages.html",'index of packages');
102 } elsif (m/^index(\s+|-)maints?$/) {
103 &sendlynxdoc("db/ix/maintainers.html",'index of maintainers');
104 } elsif (m/^index(\s+|-)maint\s+(\S.*\S)$/) {
105 $substrg= $2; $matches=0;
106 opendir(DBD,"$gWebDir/db/ma") || die $!;
107 while (defined($_=readdir(DBD))) {
108 next unless m/^l/ && m/\.html$/;
109 &transcript("F|$_\n") if $dl>1;
110 $filename= $_; s/^l//; s/\.html$//;
111 &transcript("P|$_\n") if $dl>2;
112 while (s/-(..)([^_])/-$1_-$2/) { }
113 &transcript("P|$_\n") if $dl>2;
114 s/^(.{0,2})_/$1-20_/g; while (s/([^-]..)_/$1-20_/) { };
115 &transcript("P|$_\n") if $dl>2;
116 s/^,(.*),(.*),([^,]+)$/$1-40_$2-20_-28_$3-29_/;
117 &transcript("P|$_\n") if $dl>2;
118 s/^([^,]+),(.*),(.*),$/$1-20_-3c_$2-40_$3-3e_/;
119 &transcript("P|$_\n") if $dl>2;
121 &transcript("P|$_\n") if $dl>2;
123 while (m/-(..)_/) { $out.= $`.sprintf("%c",hex($1)); $_=$'; }
125 &transcript("M|$out\n") if $dl>1;
126 next unless index(lc $out, lc $substrg)>=0;
127 &transcript("S|$filename\n") if $dl>0;
128 &transcript("S|$out\n") if $dl>0;
130 &sendlynxdocraw("db/ma/$filename","$gBug list for maintainer \`$out'");
133 &transcript("$gBug list(s) for $matches maintainer(s) sent.\n\n");
135 &transcript("No maintainers found containing \`$substrg'.\n".
136 "Use \`index-maint' to get list of maintainers.\n\n");
139 } elsif (m/^index(\s+|-)pack(age)?s?\s+(\S.*\S)$/) {
140 $substrg= $+; $matches=0;
141 opendir(DBD,"$gWebDir/db/pa") || die $!;
142 while (defined($_=readdir(DBD))) {
143 next unless m/^l/ && m/\.html$/;
144 &transcript("F|$_\n") if $dl>1;
145 $filename= $_; s/^l//; s/\.html$//;
146 next unless index(lc $_, lc $substrg)>=0;
147 &transcript("S|$filename\n") if $dl>0;
148 &transcript("S|$out\n") if $dl>0;
150 &sendlynxdocraw("db/pa/$filename","$gBug list for package \`$_'");
153 &transcript("$gBug list(s) for $matches package(s) sent.\n\n");
155 &transcript("No packages found containing \`$substrg'.\n".
156 "Use \`index-packages' to get list of packages.\n\n");
159 } elsif (m/^send-unmatched(\s+this|\s+-?0)?$/) {
160 &sendlynxdoc("db/ju/unmatched-1.html","junk (this week)");
161 } elsif (m/^send-unmatched\s+(last|-1)$/) {
162 &sendlynxdoc("db/ju/unmatched-2.html","junk (last week)");
163 } elsif (m/^send-unmatched\s+(old|-2)$/) {
164 &sendlynxdoc("db/ju/unmatched-3.html","junk (two weeks ago)");
165 } elsif (m/^getinfo\s+(\S+)$/) {
167 if ($file =~ m/^\./ || $file !~ m/^[-.0-9a-z]+$/ || $file =~ m/\.gz$/) {
168 &transcript("Filename $file is badly formatted.\n\n");
169 } elsif (open(P,"$gDocDir/$file")) {
171 &transcript("Info file $file appears below.\n\n");
172 $extras.= "\n---------- Info file $file follows:\n\n";
173 while(<P>) { $extras.= $_; }
176 &transcript("Info file $file does not exist.\n\n");
178 } elsif (m/^help$/) {
182 } elsif (m/^refcard$/) {
183 &sendtxthelp("bug-mailserver-refcard.txt","mailservers' reference card");
184 } elsif (m/^subscribe/) {
186 There is no $gProject $gBug mailing list. If you wish to review bug reports
187 please do so via http://$gWebUrl/ or ask this mailserver
189 soon: MAILINGLISTS_TEXT
191 } elsif (m/^unsubscribe/) {
193 soon: UNSUBSCRIBE_TEXT
194 soon: MAILINGLISTS_TEXT
196 } elsif (!$control) {
198 Unknown command or malformed arguments to command.
199 (Use control\@$gEmailDomain to manipulate reports.)
202 if (++$unknowns >= 3) {
203 &transcript("Too many unknown commands, stopping here.\n\n");
206 } elsif (m/^close\s+\#?(\d+)$/) {
210 if (length($s_done)) {
211 &transcript("$gBug is already closed, cannot re-close.\n\n");
214 $action= "$gBug closed, ack sent to submitter - they'd better know why !";
216 &addmaintainers($s_package);
217 if ( length( $gDoneList ) > 0 && length( $gListDomain ) >
218 0 ) { &addccaddress("$gDoneList\@$gListDomain"); }
221 From: $gMaintainerEmail ($gMaintainer)
223 Subject: $gBug#$ref acknowledged by developer
225 References: $header{'message-id'} $s_msgid
226 In-Reply-To: $s_msgid
227 Message-ID: <handler.$ref.$nn.notifdonectrl.$midix\@$gEmailDomain>
229 This is an automatic notification regarding your $gBug report.
231 It has been marked as closed by one of the developers, namely
234 You should be hearing from them with a substantive response shortly,
235 if you have not already done so. If not, please contact them
236 directly, or email DB_SUBMIT_ADDRPQ or myself.
239 (administrator, $gProject $gBugs database)
241 &sendmailmessage($message,$s_originator);
242 } while (&getnextbug);
245 } elsif (m/^reassign\s+\#?(\d+)\s+(\S.*\S)$/) {
247 $ref= $1; $newpackage= $2;
249 if (length($s_package)) {
250 $action= "$gBug reassigned from package \`$s_package'".
251 " to \`$newpackage'.";
253 $action= "$gBug assigned to package \`$newpackage'.";
256 &addmaintainers($s_package);
257 &addmaintainers($newpackage);
258 $s_package= $newpackage;
259 } while (&getnextbug);
261 } elsif (m/^reopen\s+\#?(\d+)$/ ? ($noriginator='', 1) :
262 m/^reopen\s+\#?(\d+)\s+\=$/ ? ($noriginator='', 1) :
263 m/^reopen\s+\#?(\d+)\s+\!$/ ? ($noriginator=$replyto, 1) :
264 m/^reopen\s+\#?(\d+)\s+(\S.*\S)$/ ? ($noriginator=$2, 1) : 0) {
268 if (!length($s_done)) {
269 &transcript("$gByg is already open, cannot reopen.\n\n");
273 $noriginator eq '' ? "$gBug reopened, originator not changed." :
274 "$gBug reopened, originator set to $noriginator.";
276 &addmaintainers($s_package);
277 $s_originator= $noriginator eq '' ? $s_originator : $noriginator;
279 } while (&getnextbug);
282 } elsif (m/^forwarded\s+\#?(\d+)\s+(\S.*\S)$/) {
284 $ref= $1; $whereto= $2;
286 if (length($s_forwarded)) {
287 $action= "Forwarded-to-address changed from $s_forwarded to $whereto.";
289 $action= "Noted your statement that $gBug has been forwarded to $whereto.";
291 if (length($s_done)) {
292 $extramessage= "(By the way, this $gBug is currently marked as done.)\n";
295 &addmaintainers($s_package);
296 if (length($gFowardList)>0 && length($gListDomain)>0 )
297 { &addccaddress("$gFowardList\@$gListDomain"); }
298 $s_forwarded= $whereto;
299 } while (&getnextbug);
301 } elsif (m/^notforwarded\s+\#?(\d+)$/) {
305 if (!length($s_forwarded)) {
306 &transcript("$gBug is not marked as having been forwarded.\n\n");
309 $action= "Removed annotation that $gBug had been forwarded to $s_forwarded.";
311 &addmaintainers($s_package);
313 } while (&getnextbug);
316 } elsif (m/^severity\s+\#?(\d+)\s+([-0-9a-z]+)$/) {
320 if (!grep($_ eq $newseverity, @severities, "$gDefaultSeverity")) {
321 &transcript("Severity level \`$newseverity' is not known.\n".
322 "Recognised are: ".join(' ',@showseverities).".\n\n");
324 $printseverity= $s_severity;
325 $printseverity= "$gDefaultSeverity" if $printseverity eq '';
326 $action= "Severity set to \`$newseverity'.";
328 &addmaintainers($s_package);
329 $s_severity= $newseverity;
330 } while (&getnextbug);
332 } elsif (m/^retitle\s+\#?(\d+)\s+(\S.*\S)\s*$/) {
334 $ref= $1; $newtitle= $2;
337 &addmaintainers($s_package);
338 $s_subject= $newtitle;
339 $action= "Changed $gBug title.";
341 &transcript("$action\n");
342 if (length($s_done)) {
343 &transcript("(By the way, that $gBug is currently marked as done.)\n");
349 } elsif (m/^unmerge\s+\#?(\d+)$/) {
353 if (!length($s_mergedwith)) {
354 &transcript("$gBug is not marked as being merged with any others.\n\n");
357 $mergelowstate eq 'locked' || die "$mergelowstate ?";
358 $action= "Disconnected #$ref from all other report(s).";
359 @newmergelist= split(/ /,$s_mergedwith);
362 &addmaintainers($s_package);
363 $s_mergedwith= ($ref == $discref) ? ''
364 : join(' ',grep($_ ne $ref,@newmergelist));
365 } while (&getnextbug);
368 } elsif (m/^merge\s(\d+(\s+\d+)+)\s*$/) {
370 @tomerge= sort { $a <=> $b } split(/\s+/,$1);
373 while (defined($ref= shift(@tomerge))) {
374 &transcript("D| checking merge $ref\n") if $dl;
376 next if grep($_ eq $ref,@newmergelist);
377 if (!&getbug) { ¬foundbug; @newmergelist=(); last }
379 &transcript("D| adding $ref ($s_mergewith)\n") if $dl;
381 &checkmatch('package','m_package',$s_package);
382 &checkmatch('forwarded addr','m_forwarded',$s_forwarded);
383 &checkmatch('severity','m_severity',$s_severity);
384 &checkmatch('done mark','m_done',length($s_done) ? 'done' : 'open');
385 if (length($mismatch)) {
386 &transcript("Mismatch - only $Bugs in same state can be merged:\n".
388 &cancelbug; @newmergelist=(); last;
390 push(@newmergelist,$ref);
391 push(@tomerge,split(/ /,$s_mergedwith));
395 @newmergelist= sort { $a <=> $b } @newmergelist;
396 $action= "Merged @newmergelist.";
397 for $ref (@newmergelist) {
398 &getbug || die "huh ? $gBug $ref disappeared during merge";
399 &addmaintainers($s_package);
400 $s_mergedwith= join(' ',grep($_ ne $ref,@newmergelist));
403 &transcript("$action\n\n");
407 &transcript("Unknown command or malformed arguments to command.\n\n");
408 if (++$unknowns >= 5) {
409 &transcript("Too many unknown commands, stopping here.\n\n");
414 if ($procline>$#msg) {
415 &transcript(">\nEnd of message, stopping processing here.\n\n");
418 &transcript("No commands successfully parsed; sending the help text(s).\n");
423 &transcript("MC\n") if $dl>1;
425 for $maint (keys %maintccreasons) {
426 &transcript("MM|$maint|\n") if $dl>1;
427 next if $maint eq $replyto;
429 $reasonsref= $maintccreasons{$maint};
430 &transcript("MY|$maint|\n") if $dl>2;
431 for $p (sort keys %$reasonsref) {
432 &transcript("MP|$p|\n") if $dl>2;
433 $reasonstring.= ', ' if length($reasonstring);
434 $reasonstring.= $p.' ' if length($p);
435 $reasonstring.= join(' ',map("#$_",sort keys %{$$reasonsref{$p}}));
437 push(@maintccs,"$maint ($reasonstring)");
438 push(@maintccaddrs,"$maint");
441 &transcript("MC|@maintccs|\n") if $dl>2;
442 $maintccs= "Cc: ".join(",\n ",@maintccs)."\n";
446 From: $gMaintainerEmail ($gMaintainer)
448 ${maintccs}Subject: Processed: $header{'subject'}
449 In-Reply-To: $header{'message-id'}
450 References: $header{'message-id'}
451 Message-ID: <handler.s.$nn.transcript\@$gEmailDomain>
453 ${transcript}Please contact me if you need assistance.
456 (administrator, $gProject $gBugs database)
460 $repliedshow= join(', ',$replyto,@maintccaddrs);
461 &filelock("lock/-1");
462 open(AP,">>db/-1.log") || &quit("open db/-1.log: $!");
464 "\2\n$repliedshow\n\5\n$reply\n\3\n".
466 "<strong>Request received</strong> from <code>".
467 &sani($header{'from'})."</code>\n".
468 "to <code>".&sani($controlrequestaddr)."</code>\n".
470 "\7\n",@log,"\n\3\n") || &quit("writing db/-1.log: $!");
471 close(AP) || &quit("open db/-1.log: $!");
473 utime(time,time,"db");
475 &sendmailmessage($reply,$replyto,@maintccaddrs);
477 unlink("incoming/P$nn") || &quit("unlinking incoming/P$nn: $!");
481 map { $_->address() }
482 map { Mail::Address->parse($_) } @_;
485 sub sendmailmessage {
486 local ($message,@recips) = @_;
487 print DEBUG "mailing to >@recips<\n";
489 defined($c) || &quit("mailing forking for sendmail: $!");
490 if (!$c) { # ie, we are the child process
491 exec '/usr/lib/sendmail','-f'."$gMaintainerEmail",'-odi','-oem','-oi',get_addresses(@recips);
494 print(D $message) || &quit("writing to sendmail process: $!");
495 $!=0; close(D); $? && &quit("sendmail gave exit status $? ($!)");
500 &sendtxthelpraw("bug-log-mailserver.txt","instructions for request\@$gEmailDomain");
501 &sendtxthelpraw("bug-maint-mailcontrol.txt","instructions for control\@$gEmailDomain")
506 # &transcript("Sorry, command $_[0] not yet implemented.\n\n");
510 local ($string,$mvarname,$svarvalue) = @_;
513 eval "\$mvarvalue= \$$mvarname";
514 &transcript("D| checkmatch \`$string' /$mvarname/$mvarvalue/$svarvalue/\n")
517 "Values for \`$string' don't match:\n".
518 " #$newmergelist[0] has \`$mvarvalue';\n".
519 " #$ref has \`$svarvalue'\n"
520 if $mvarvalue ne $svarvalue;
522 &transcript("D| setupmatch \`$string' /$mvarname/$svarvalue/\n")
524 eval "\$$mvarname= \$svarvalue";
528 # High-level bug manipulation calls
529 # Do announcements themselves
531 # Possible calling sequences:
535 # &transcript(something)
539 # $action= (something)
541 # (modify s_* variables)
542 # } while (getnextbug);
545 &dlen("nochangebug");
546 $state eq 'single' || $state eq 'multiple' || die "$state ?";
548 &endmerge if $manybugs;
550 &dlex("nochangebug");
554 &dlen("setbug $ref");
555 $state eq 'idle' || die "$state ?";
558 &dlex("setbug => 0s");
561 @thisbugmergelist= split(/ /,$s_mergedwith);
562 if (!@thisbugmergelist) {
567 &dlex("setbug => 1s");
576 &dlex("setbug => 0mc");
580 $state= 'multiple'; $sref=$ref;
581 &dlex("setbug => 1m");
587 $state eq 'single' || $state eq 'multiple' || die "$state ?";
589 if (!$manybugs || !@thisbugmergelist) {
590 length($action) || die;
591 &transcript("$action\n$extramessage\n");
592 &endmerge if $manybugs;
594 &dlex("getnextbug => 0");
597 $ref= shift(@thisbugmergelist);
598 &getbug || die "bug $ref disappeared";
600 &dlex("getnextbug => 1");
604 # Low-level bug-manipulation calls
605 # Do no announcements
613 # $action= (something)
618 # [getbug (returns 0)]
619 # &transcript("$action\n\n")
622 sub notfoundbug { &transcript("$gBug number $ref not found.\n\n"); }
623 sub foundbug { &transcript("$gBug#$ref: $s_subject\n"); }
627 $mergelowstate eq 'idle' || die "$mergelowstate ?";
628 &filelock('lock/merge');
629 $mergelowstate='locked';
635 $mergelowstate eq 'locked' || die "$mergelowstate ?";
637 $mergelowstate='idle';
642 &dlen("getbug $ref");
643 $lowstate eq 'idle' || die "$state ?";
644 if (&lockreadbug($ref)) {
647 &dlex("getbug => 1");
652 &dlex("getbug => 0");
658 $lowstate eq 'open' || die "$state ?";
665 &dlen("savebug $ref");
666 $lowstate eq 'open' || die "$lowstate ?";
667 length($action) || die;
668 $ref == $sref || die "read $sref but saving $ref ?";
669 open(L,">>db/$ref.log") || &quit("opening db/$ref.log: $!");
672 "<strong>".&sani($action)."</strong>\n".
673 "Request was from <code>".&sani($header{'from'})."</code>\n".
674 "to <code>".&sani($controlrequestaddr)."</code>. \n".
676 "\7\n",@log,"\n\3\n") || &quit("writing db/$ref.log: $!");
677 close(L) || &quit("closing db/$ref.log: $!");
678 open(S,">db/$ref.status.new") || &quit("opening db/$ref.status.new: $!");
689 "$s_severity\n") || &quit("writing db/$ref.status.new: $!");
690 close(S) || &quit("closing db/$ref.status.new: $!");
691 rename("db/$ref.status.new","db/$ref.status") ||
692 &quit("installing new db/$ref.status: $!");
700 &transcript("C> @_ ($state $lowstate $mergelowstate)\n");
705 &transcript("R> @_ ($state $lowstate $mergelowstate)\n");
726 local ($relpath,$description) = @_;
728 open(D,"$gDocDir/$relpath") || &quit("open doc file $relpath: $!");
729 while(<D>) { $doc.=$_; }
731 &transcript("Sending $description in separate message.\n");
732 &sendmailmessage(<<END.$doc,$replyto);
733 From: $gMaintainerEmail ($gMaintainer)
735 Subject: $gProject $gBug help: $description
736 References: $header{'message-id'}
737 In-Reply-To: $header{'message-id'}
738 Message-ID: <handler.s.$nn.help.$midix\@$gEmailDomain>
745 local ($relpath,$description) = @_;
747 open(L,"lynx -nolist -dump $wwwbase/$relpath 2>&1 |") || &quit("fork for lynx: $!");
748 while(<L>) { $doc.=$_; }
750 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
751 &transcript("Information ($description) is not available -\n".
752 "perhaps the $gBug does not exist or is not on the WWW yet.\n");
755 &transcript("Error getting $description (code $? $!):\n$doc\n");
757 &transcript("Sending $description.\n");
758 &sendmailmessage(<<END.$doc,$replyto);
759 From: $gMaintainerEmail ($gMaintainer)
761 Subject: $gProject $gBugs information: $description
762 References: $header{'message-id'}
763 In-Reply-To: $header{'message-id'}
764 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
773 $maintccreasons{$cca}{''}{$ref}= 1;
778 # maintainer email address &c -> assoc of packages -> assoc of bug#'s
779 my $p, $addmaint, $pshow;
780 &ensuremaintainersloaded;
781 $anymaintfound=0; $anymaintnotfound=0;
782 for $p (split(m/[ \t?,()]+/,$_[0])) {
784 $pshow= ($p =~ m/[-+.a-z0-9]+/ ? $& : '');
785 if (defined($maintainerof{$p})) {
786 $addmaint= $maintainerof{$p};
787 &transcript("MR|$addmaint|$p|$ref|\n") if $dl>2;
788 $maintccreasons{$addmaint}{$p}{$ref}= 1;
789 print DEBUG "maintainer add >$p|$addmaint<\n";
791 print DEBUG "maintainer none >$p<\n";
796 sub ensuremaintainersloaded {
798 return if $maintainersloaded++;
799 open(MAINT,"$gMaintainerFile") || die &quit("maintainers open: $!");
801 m/^(\S+)\s+(\S.*\S)\n$/ || &quit("maintainers bogus \`$_'");
802 $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
803 $maintainerof{$1}= $2;