2 # $Id: service.in,v 1.103 2005/07/18 02:22:49 cjwatson Exp $
4 # Usage: service <code>.nn
5 # Temps: incoming/P<code>.nn
9 use Debbugs::MIME qw(decode_rfc1522);
11 $config_path = '/etc/debbugs';
12 $lib_path = '/usr/lib/debbugs';
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");
41 print "###\n",join("##\n",@msg),"\n###\n" if $debug;
43 my $parser = new MIME::Parser;
44 mkdir "$gSpoolDir/mime.tmp", 0777;
45 $parser->output_under("$gSpoolDir/mime.tmp");
46 my $entity = eval { $parser->parse_data(join('',@log)) };
48 # header and decoded body respectively
49 my (@headerlines, @bodylines);
51 if ($entity and $entity->head->tags) {
52 @headerlines = @{$entity->head->header};
55 my $entity_body = getmailbody($entity);
56 @bodylines = $entity_body ? $entity_body->as_lines() : ();
59 # Legacy pre-MIME code, kept around in case MIME::Parser fails.
61 for ($i = 0; $i <= $#msg; $i++) {
63 last unless length($_);
64 while ($msg[$i+1] =~ m/^\s/) {
68 push @headerlines, $_;
71 @bodylines = @msg[$i..$#msg];
76 print ">$_<\n" if $debug;
79 print ">$v=$_<\n" if $debug;
80 $header{$v} = decode_rfc1522($_);
82 print "!>$_<\n" if $debug;
86 # Strip off RFC2440-style PGP clearsigning.
87 if (@bodylines and $bodylines[0] =~ /^-----BEGIN PGP SIGNED/) {
88 shift @bodylines while @bodylines and length $bodylines[0];
89 shift @bodylines while @bodylines and $bodylines[0] !~ /\S/;
90 for my $findsig (0 .. $#bodylines) {
91 if ($bodylines[$findsig] =~ /^-----BEGIN PGP SIGNATURE/) {
92 $#bodylines = $findsig - 1;
96 map { s/^- // } @bodylines;
99 grep(s/\s+$//,@bodylines);
101 print "***\n",join("\n",@bodylines),"\n***\n" if $debug;
103 if (defined $header{'resent-from'} && !defined $header{'from'}) {
104 $header{'from'} = $header{'resent-from'};
107 defined($header{'from'}) || &quit("no From header");
109 delete $header{'reply-to'}
110 if ( defined($header{'reply-to'}) && $header{'reply-to'} =~ m/^\s*$/ );
112 if ( defined($header{'reply-to'}) && $header{'reply-to'} ne "" ) {
113 $replyto = $header{'reply-to'};
115 $replyto = $header{'from'};
118 $controlrequestaddr= $control ? "control\@$gEmailDomain" : "request\@$gEmailDomain";
120 &transcript("Processing commands for $controlrequestaddr:\n\n");
125 $mergelowstate= 'idle';
131 my $fuckheads = "(" . join("|", @gFuckheads) . ")";
132 if (@gFuckheads and $replyto =~ m/$fuckheads/) {
133 &transcript("This service is unavailable.\n\n");
142 push @bcc, $_[0] unless grep { $_ eq $_[0] } @bcc;
145 for ($procline=0; $procline<=$#bodylines; $procline++) {
146 $state eq 'idle' || print "$state ?\n";
147 $lowstate eq 'idle' || print "$lowstate ?\n";
148 $mergelowstate eq 'idle' || print "$mergelowstate ?\n";
150 &transcript("Stopping processing here.\n\n");
153 $_= $bodylines[$procline]; s/\s+$//;
155 &transcript("> $_\n");
158 if (m/^stop/i || m/^quit/i || m/^--/ || m/^thank/i) {
159 &transcript("Stopping processing here.\n\n");
161 } elsif (m/^debug\s+(\d+)$/i && $1 >= 0 && $1 <= 1000) {
163 &transcript("Debug level $dl.\n\n");
164 } elsif (m/^(send|get)\s+\#?(\d{2,})$/i) {
166 &sendlynxdoc("bugreport.cgi?bug=$ref","logs for $gBug#$ref");
167 } elsif (m/^send-detail\s+\#?(\d{2,})$/i) {
169 &sendlynxdoc("bugreport.cgi?bug=$ref&boring=yes",
170 "detailed logs for $gBug#$ref");
171 } elsif (m/^index(\s+full)?$/i) {
172 &transcript("This BTS function is currently disabled, sorry.\n\n");
173 $ok++; # well, it's not really ok, but it fixes #81224 :)
174 } elsif (m/^index-summary\s+by-package$/i) {
175 &transcript("This BTS function is currently disabled, sorry.\n\n");
176 $ok++; # well, it's not really ok, but it fixes #81224 :)
177 } elsif (m/^index-summary(\s+by-number)?$/i) {
178 &transcript("This BTS function is currently disabled, sorry.\n\n");
179 $ok++; # well, it's not really ok, but it fixes #81224 :)
180 } elsif (m/^index(\s+|-)pack(age)?s?$/i) {
181 &sendlynxdoc("pkgindex.cgi?indexon=pkg",'index of packages');
182 } elsif (m/^index(\s+|-)maints?$/i) {
183 &sendlynxdoc("pkgindex.cgi?indexon=maint",'index of maintainers');
184 } elsif (m/^index(\s+|-)maint\s+(\S+)$/i) {
186 &sendlynxdoc("pkgreport.cgi?maint=" . urlsanit($maint),
187 "$gBug list for maintainer \`$maint'");
189 } elsif (m/^index(\s+|-)pack(age)?s?\s+(\S.*\S)$/i) {
191 &sendlynxdoc("pkgreport.cgi?pkg=" . urlsanit($package),
192 "$gBug list for package $package");
194 } elsif (m/^send-unmatched(\s+this|\s+-?0)?$/i) {
195 &transcript("This BTS function is currently disabled, sorry.\n\n");
196 $ok++; # well, it's not really ok, but it fixes #81224 :)
197 } elsif (m/^send-unmatched\s+(last|-1)$/i) {
198 &transcript("This BTS function is currently disabled, sorry.\n\n");
199 $ok++; # well, it's not really ok, but it fixes #81224 :)
200 } elsif (m/^send-unmatched\s+(old|-2)$/i) {
201 &transcript("This BTS function is currently disabled, sorry.\n\n");
202 $ok++; # well, it's not really ok, but it fixes #81224 :)
203 } elsif (m/^getinfo\s+([\w-.]+)$/i) {
204 # the following is basically a Debian-specific kludge, but who cares
206 if ($req =~ /^maintainers$/i && -f "$gConfigDir/Maintainers") {
207 &sendinfo("local", "$gConfigDir/Maintainers", "Maintainers file");
208 } elsif ($req =~ /^override\.(\w+)\.([\w-.]+)$/i) {
210 &sendinfo("ftp.d.o", "$req", "override file for $2 part of $1 distribution");
211 } elsif ($req =~ /^pseudo-packages\.(description|maintainers)$/i && -f "$gConfigDir/$req") {
212 &sendinfo("local", "$gConfigDir/$req", "$req file");
214 &transcript("Info file $req does not exist.\n\n");
216 } elsif (m/^help/i) {
220 } elsif (m/^refcard/i) {
221 &sendtxthelp("bug-mailserver-refcard.txt","mail servers' reference card");
222 } elsif (m/^subscribe/i) {
224 There is no $gProject $gBug mailing list. If you wish to review bug reports
225 please do so via http://$gWebDomain/ or ask this mail server
227 soon: MAILINGLISTS_TEXT
229 } elsif (m/^unsubscribe/i) {
231 soon: UNSUBSCRIBE_TEXT
232 soon: MAILINGLISTS_TEXT
234 } elsif (!$control) {
236 Unknown command or malformed arguments to command.
237 (Use control\@$gEmailDomain to manipulate reports.)
240 if (++$unknowns >= 3) {
241 &transcript("Too many unknown commands, stopping here.\n\n");
244 #### interesting ones start here
245 } elsif (m/^close\s+\#?(-?\d+)(?:\s+(\d.*))?$/i) {
250 &transcript("'close' is deprecated; see http://$gWebDomain/Developer$gHTMLSuffix#closing.\n");
251 if (length($data->{done}) and not defined($version)) {
252 &transcript("$gBug is already closed, cannot re-close.\n\n");
257 "marked as fixed in version $version" :
259 ", send any further explanations to $data->{originator}";
261 &addmaintainers($data);
262 if ( length( $gDoneList ) > 0 && length( $gListDomain ) >
263 0 ) { &addccaddress("$gDoneList\@$gListDomain"); }
264 $data->{done}= $replyto;
265 my @keywords= split ' ', $data->{keywords};
266 if (grep $_ eq 'pending', @keywords) {
267 $extramessage= "Removed pending tag.\n";
268 $data->{keywords}= join ' ', grep $_ ne 'pending',
271 addfixedversions($data, undef, $version);
274 From: $gMaintainerEmail ($gProject $gBug Tracking System)
275 To: $data->{originator}
276 Subject: $gBug#$ref acknowledged by developer
278 References: $header{'message-id'} $data->{msgid}
279 In-Reply-To: $data->{msgid}
280 Message-ID: <handler.$ref.$nn.notifdonectrl.$midix\@$gEmailDomain>
281 Reply-To: $ref\@$gEmailDomain
282 X-$gProject-PR-Message: they-closed-control $ref
284 This is an automatic notification regarding your $gBug report
285 #$ref: $data->{subject},
286 which was filed against the $data->{package} package.
288 It has been marked as closed by one of the developers, namely
291 You should be hearing from them with a substantive response shortly,
292 in case you haven't already. If not, please contact them directly.
295 (administrator, $gProject $gBugs database)
298 &sendmailmessage($message,$data->{originator});
299 } while (&getnextbug);
302 } elsif (m/^reassign\s+\#?(-?\d+)\s+(\S+)(?:\s+(\d.*))?$/i) {
304 $ref= $1; $newpackage= $2;
306 $newpackage =~ y/A-Z/a-z/;
308 if (length($data->{package})) {
309 $action= "$gBug reassigned from package \`$data->{package}'".
310 " to \`$newpackage'.";
312 $action= "$gBug assigned to package \`$newpackage'.";
315 &addmaintainers($data);
316 $data->{package}= $newpackage;
317 $data->{found_versions}= [];
318 $data->{fixed_versions}= [];
319 # TODO: what if $newpackage is a source package?
320 addfoundversions($data, undef, $version) if defined $version;
321 &addmaintainers($data);
322 } while (&getnextbug);
324 } elsif (m/^reopen\s+\#?(-?\d+)$/i ? ($noriginator='', 1) :
325 m/^reopen\s+\#?(-?\d+)\s+\=$/i ? ($noriginator='', 1) :
326 m/^reopen\s+\#?(-?\d+)\s+\!$/i ? ($noriginator=$replyto, 1) :
327 m/^reopen\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($noriginator=$2, 1) : 0) {
331 if (@{$data->{fixed_versions}}) {
332 &transcript("'reopen' is deprecated when a bug has been closed with a version;\nuse 'found' or 'submitter' as appropriate instead.\n");
334 if (!length($data->{done})) {
335 &transcript("$gBug is already open, cannot reopen.\n\n");
339 $noriginator eq '' ? "$gBug reopened, originator not changed." :
340 "$gBug reopened, originator set to $noriginator.";
342 &addmaintainers($data);
343 $data->{originator}= $noriginator eq '' ? $data->{originator} : $noriginator;
344 $data->{fixed_versions}= [];
346 } while (&getnextbug);
349 } elsif (m/^found\s+\#?(-?\d+)(?:\s+(\d.*))?$/i) {
354 if (!length($data->{done})) {
355 &transcript("$gBug is already open, cannot reopen.\n\n");
360 "$gBug marked as found in version $version." :
363 &addmaintainers($data);
364 # The 'done' field gets a bit weird with version
365 # tracking, because a bug may be closed by multiple
366 # people in different branches. Until we have something
367 # more flexible, we set it every time a bug is fixed,
368 # and clear it precisely when a found command is
369 # received for the rightmost fixed-in version, which
370 # equates to the most recent fixing of the bug, or when
371 # a versionless found command is received.
372 if (defined $version) {
374 (reverse @{$data->{fixed_versions}})[0];
375 # TODO: what if $data->{package} is a source package?
376 addfoundversions($data, undef, $version);
377 if (defined $lastfixed and $version eq $lastfixed) {
381 # Versionless found; assume old-style "not fixed at
383 $data->{fixed_versions} = [];
386 } while (&getnextbug);
389 } elsif (m/^submitter\s+\#?(-?\d+)\s+\!$/i ? ($newsubmitter=$replyto, 1) :
390 m/^submitter\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($newsubmitter=$2, 1) : 0) {
393 if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
394 $ref = $clonebugs{$ref};
397 if (&checkpkglimit) {
399 &addmaintainers($data);
400 $oldsubmitter= $data->{originator};
401 $data->{originator}= $newsubmitter;
402 $action= "Changed $gBug submitter from $oldsubmitter to $newsubmitter.";
404 &transcript("$action\n");
405 if (length($data->{done})) {
406 &transcript("(By the way, that $gBug is currently marked as done.)\n");
410 From: $gMaintainerEmail ($gProject $gBug Tracking System)
412 Subject: $gBug#$ref submitter address changed
414 References: $header{'message-id'} $data->{msgid}
415 In-Reply-To: $data->{msgid}
416 Message-ID: <handler.$ref.$nn.newsubmitter.$midix\@$gEmailDomain>
417 Reply-To: $ref\@$gEmailDomain
418 X-$gProject-PR-Message: submitter-changed $ref
420 The submitter address recorded for your $gBug report
421 #$ref: $data->{subject}
424 The new submitter address for this report is
427 This change was made by
429 If it was incorrect, please contact them directly.
432 (administrator, $gProject $gBugs database)
435 &sendmailmessage($message,$oldsubmitter);
442 } elsif (m/^forwarded\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
444 $ref= $1; $whereto= $2;
446 if (length($data->{forwarded})) {
447 $action= "Forwarded-to-address changed from $data->{forwarded} to $whereto.";
449 $action= "Noted your statement that $gBug has been forwarded to $whereto.";
451 if (length($data->{done})) {
452 $extramessage= "(By the way, this $gBug is currently marked as done.)\n";
455 &addmaintainers($data);
456 if (length($gForwardList)>0 && length($gListDomain)>0 ) {
457 &addccaddress("$gForwardList\@$gListDomain");
459 $data->{forwarded}= $whereto;
460 } while (&getnextbug);
462 } elsif (m/^notforwarded\s+\#?(-?\d+)$/i) {
466 if (!length($data->{forwarded})) {
467 &transcript("$gBug is not marked as having been forwarded.\n\n");
470 $action= "Removed annotation that $gBug had been forwarded to $data->{forwarded}.";
472 &addmaintainers($data);
473 $data->{forwarded}= '';
474 } while (&getnextbug);
477 } elsif (m/^severity\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i ||
478 m/^priority\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i) {
482 if (!grep($_ eq $newseverity, @gSeverityList, "$gDefaultSeverity")) {
483 &transcript("Severity level \`$newseverity' is not known.\n".
484 "Recognized are: $gShowSeverities.\n\n");
485 } elsif (exists $gObsoleteSeverities{$newseverity}) {
486 &transcript("Severity level \`$newseverity' is obsolete. " .
487 "$gObsoleteSeverities{$newseverity}\n\n");
489 $printseverity= $data->{severity};
490 $printseverity= "$gDefaultSeverity" if $printseverity eq '';
491 $action= "Severity set to \`$newseverity'.";
493 &addmaintainers($data);
494 if (defined $gStrongList and isstrongseverity($newseverity)) {
495 addbcc("$gStrongList\@$gListDomain");
497 $data->{severity}= $newseverity;
498 } while (&getnextbug);
500 } elsif (m/^tags?\s+\#?(-?\d+)\s+(([=+-])\s*)?(\S.*)?$/i) {
502 $ref = $1; $addsubcode = $3; $tags = $4;
504 if (defined $addsubcode) {
505 $addsub = "sub" if ($addsubcode eq "-");
506 $addsub = "add" if ($addsubcode eq "+");
507 $addsub = "set" if ($addsubcode eq "=");
511 foreach my $t (split /[\s,]+/, $tags) {
512 if (!grep($_ eq $t, @gTags)) {
519 &transcript("Unknown tag/s: ".join(', ', @badtags).".\n".
520 "Recognized are: ".join(' ', @gTags).".\n\n");
523 if ($data->{keywords} eq '') {
524 &transcript("There were no tags set.\n");
526 &transcript("Tags were: $data->{keywords}\n");
528 if ($addsub eq "set") {
529 $action= "Tags set to: " . join(", ", @okaytags);
530 } elsif ($addsub eq "add") {
531 $action= "Tags added: " . join(", ", @okaytags);
532 } elsif ($addsub eq "sub") {
533 $action= "Tags removed: " . join(", ", @okaytags);
536 &addmaintainers($data);
537 $data->{keywords} = '' if ($addsub eq "set");
538 # Allow removing obsolete tags.
539 if ($addsub eq "sub") {
540 foreach my $t (@badtags) {
541 $data->{keywords} = join ' ', grep $_ ne $t,
542 split ' ', $data->{keywords};
545 # Now process all other additions and subtractions.
546 foreach my $t (@okaytags) {
547 $data->{keywords} = join ' ', grep $_ ne $t,
548 split ' ', $data->{keywords};
549 $data->{keywords} = "$t $data->{keywords}" unless($addsub eq "sub");
551 $data->{keywords} =~ s/\s*$//;
552 } while (&getnextbug);
554 } elsif (m/^retitle\s+\#?(-?\d+)\s+(\S.*\S)\s*$/i) {
556 $ref= $1; $newtitle= $2;
557 if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
558 $ref = $clonebugs{$ref};
561 if (&checkpkglimit) {
563 &addmaintainers($data);
564 $data->{subject}= $newtitle;
565 $action= "Changed $gBug title.";
567 &transcript("$action\n");
568 if (length($data->{done})) {
569 &transcript("(By the way, that $gBug is currently marked as done.)\n");
578 } elsif (m/^unmerge\s+\#?(-?\d+)$/i) {
582 if (!length($data->{mergedwith})) {
583 &transcript("$gBug is not marked as being merged with any others.\n\n");
586 $mergelowstate eq 'locked' || die "$mergelowstate ?";
587 $action= "Disconnected #$ref from all other report(s).";
588 @newmergelist= split(/ /,$data->{mergedwith});
591 &addmaintainers($data);
592 $data->{mergedwith}= ($ref == $discref) ? ''
593 : join(' ',grep($_ ne $ref,@newmergelist));
594 } while (&getnextbug);
597 } elsif (m/^merge\s+#?(-?\d+(\s+#?-?\d+)+)\s*$/i) {
599 @tomerge= sort { $a <=> $b } split(/\s+#?/,$1);
605 while (defined($ref= shift(@tomerge))) {
606 &transcript("D| checking merge $ref\n") if $dl;
608 if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
609 $ref = $clonebugs{$ref};
611 next if grep($_ eq $ref,@newmergelist);
612 if (!&getbug) { ¬foundbug; @newmergelist=(); last }
613 if (!&checkpkglimit) { &cancelbug; @newmergelist=(); last; }
615 &transcript("D| adding $ref ($data->{mergedwith})\n") if $dl;
617 &checkmatch('package','m_package',$data->{package});
618 &checkmatch('forwarded addr','m_forwarded',$data->{forwarded});
619 $data->{severity} = '$gDefaultSeverity' if $data->{severity} eq '';
620 &checkmatch('severity','m_severity',$data->{severity});
621 &checkmatch('done mark','m_done',length($data->{done}) ? 'done' : 'open');
622 &checkmatch('owner','m_owner',$data->{owner});
623 foreach my $t (split /\s+/, $data->{keywords}) { $tags{$t} = 1; }
624 foreach my $f (@{$data->{found_versions}}) { $found{$f} = 1; }
625 foreach my $f (@{$data->{fixed_versions}}) { $fixed{$f} = 1; }
626 if (length($mismatch)) {
627 &transcript("Mismatch - only $gBugs in same state can be merged:\n".
629 &cancelbug; @newmergelist=(); last;
631 push(@newmergelist,$ref);
632 push(@tomerge,split(/ /,$data->{mergedwith}));
636 @newmergelist= sort { $a <=> $b } @newmergelist;
637 $action= "Merged @newmergelist.";
638 delete @fixed{keys %found};
639 for $ref (@newmergelist) {
640 &getbug || die "huh ? $gBug $ref disappeared during merge";
641 &addmaintainers($data);
642 $data->{mergedwith}= join(' ',grep($_ ne $ref,@newmergelist));
643 $data->{keywords}= join(' ', keys %tags);
644 $data->{found_versions}= [sort keys %found];
645 $data->{fixed_versions}= [sort keys %fixed];
648 &transcript("$action\n\n");
651 } elsif (m/^clone\s+#?(\d+)\s+((-\d+\s+)*-\d+)\s*$/i) {
655 @newclonedids = split /\s+/, $2;
656 $newbugsneeded = scalar(@newclonedids);
660 if (length($data->{mergedwith})) {
661 &transcript("$gBug is marked as being merged with others.\n\n");
664 &filelock("nextnumber.lock");
665 open(N,"nextnumber") || &quit("nextnumber: read: $!");
666 $v=<N>; $v =~ s/\n$// || &quit("nextnumber bad format");
667 $firstref= $v+0; $v += $newbugsneeded;
668 open(NN,">nextnumber"); print NN "$v\n"; close(NN);
671 $lastref = $firstref + $newbugsneeded - 1;
673 if ($newbugsneeded == 1) {
674 $action= "$gBug $origref cloned as bug $firstref.";
676 $action= "$gBug $origref cloned as bugs $firstref-$lastref.";
679 my $ohash = get_hashname($origref);
681 for $newclonedid (@newclonedids) {
682 $clonebugs{$newclonedid} = $ref;
684 my $hash = get_hashname($ref);
685 copy("db-h/$ohash/$origref.log", "db-h/$hash/$ref.log");
686 copy("db-h/$ohash/$origref.status", "db-h/$hash/$ref.status");
687 copy("db-h/$ohash/$origref.summary", "db-h/$hash/$ref.summary");
688 copy("db-h/$ohash/$origref.report", "db-h/$hash/$ref.report");
689 &bughook('new', $ref, $data);
695 } elsif (m/^package\s+(\S.*\S)?\s*$/i) {
697 my @pkgs = split /\s+/, $1;
698 if (scalar(@pkgs) > 0) {
699 %limit_pkgs = map { ($_, 1) } @pkgs;
700 &transcript("Ignoring bugs not assigned to: " .
701 join(" ", keys(%limit_pkgs)) . "\n\n");
704 &transcript("Not ignoring any bugs.\n\n");
706 } elsif (m/^owner\s+\#?(-?\d+)\s+!$/i ? ($newowner = $replyto, 1) :
707 m/^owner\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($newowner = $2, 1) : 0) {
711 if (length $data->{owner}) {
712 $action = "Owner changed from $data->{owner} to $newowner.";
714 $action = "Owner recorded as $newowner.";
716 if (length $data->{done}) {
717 $extramessage = "(By the way, this $gBug is currently " .
718 "marked as done.)\n";
721 &addmaintainers($data);
722 $data->{owner} = $newowner;
723 } while (&getnextbug);
725 } elsif (m/^noowner\s+\#?(-?\d+)$/i) {
729 if (length $data->{owner}) {
730 $action = "Removed annotation that $gBug was owned by " .
733 &addmaintainers($data);
735 } while (&getnextbug);
737 &transcript("$gBug is not marked as having an owner.\n\n");
742 &transcript("Unknown command or malformed arguments to command.\n\n");
743 if (++$unknowns >= 5) {
744 &transcript("Too many unknown commands, stopping here.\n\n");
749 if ($procline>$#bodylines) {
750 &transcript(">\nEnd of message, stopping processing here.\n\n");
752 if (!$ok && !quickabort) {
753 &transcript("No commands successfully parsed; sending the help text(s).\n");
758 &transcript("MC\n") if $dl>1;
760 for $maint (keys %maintccreasons) {
761 &transcript("MM|$maint|\n") if $dl>1;
762 next if $maint eq $replyto;
764 $reasonsref= $maintccreasons{$maint};
765 &transcript("MY|$maint|\n") if $dl>2;
766 for $p (sort keys %$reasonsref) {
767 &transcript("MP|$p|\n") if $dl>2;
768 $reasonstring.= ', ' if length($reasonstring);
769 $reasonstring.= $p.' ' if length($p);
770 $reasonstring.= join(' ',map("#$_",sort keys %{$$reasonsref{$p}}));
772 if (length($reasonstring) > 40) {
773 (substr $reasonstring, 37) = "...";
775 $reasonstring = "" if (!defined($reasonstring));
776 push(@maintccs,"$maint ($reasonstring)");
777 push(@maintccaddrs,"$maint");
782 &transcript("MC|@maintccs|\n") if $dl>2;
783 $maintccs .= "Cc: " . join(",\n ",@maintccs) . "\n";
786 if (!defined $header{'subject'} || $header{'subject'} eq "") {
787 $header{'subject'} = "your mail";
791 From: $gMaintainerEmail ($gProject $gBug Tracking System)
793 ${maintccs}Subject: Processed: $header{'subject'}
794 In-Reply-To: $header{'message-id'}
795 References: $header{'message-id'}
796 Message-ID: <handler.s.$nn.transcript\@$gEmailDomain>
798 X-$gProject-PR-Message: transcript
800 ${transcript}Please contact me if you need assistance.
803 (administrator, $gProject $gBugs database)
807 $repliedshow= join(', ',$replyto,@maintccaddrs);
808 &filelock("lock/-1");
809 open(AP,">>db-h/-1.log") || &quit("open db-h/-1.log: $!");
811 "\2\n$repliedshow\n\5\n$reply\n\3\n".
813 "<strong>Request received</strong> from <code>".
814 &sani($header{'from'})."</code>\n".
815 "to <code>".&sani($controlrequestaddr)."</code>\n".
817 "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/-1.log: $!");
818 close(AP) || &quit("open db-h/-1.log: $!");
820 utime(time,time,"db-h");
822 &sendmailmessage($reply,$replyto,@maintccaddrs,@bcc);
824 unlink("incoming/P$nn") || &quit("unlinking incoming/P$nn: $!");
826 sub sendmailmessage {
827 local ($message,@recips) = @_;
828 $message = "X-Loop: $gMaintainerEmail\n" . $message;
829 print "mailing to >@recips<\n" if $debug;
831 defined($c) || &quit("mailing forking for sendmail: $!");
832 if (!$c) { # ie, we are the child process
833 exec '/usr/lib/sendmail','-f'."$gMaintainerEmail",'-odb','-oem','-oi',get_addresses(@recips);
836 print(D $message) || &quit("writing to sendmail process: $!");
837 $!=0; close(D); $? && &quit("sendmail gave exit status $? ($!)");
842 &sendtxthelpraw("bug-log-mailserver.txt","instructions for request\@$gEmailDomain");
843 &sendtxthelpraw("bug-maint-mailcontrol.txt","instructions for control\@$gEmailDomain")
848 # &transcript("Sorry, command $_[0] not yet implemented.\n\n");
852 local ($string,$mvarname,$svarvalue) = @_;
855 eval "\$mvarvalue= \$$mvarname";
856 &transcript("D| checkmatch \`$string' /$mvarname/$mvarvalue/$svarvalue/\n")
859 "Values for \`$string' don't match:\n".
860 " #$newmergelist[0] has \`$mvarvalue';\n".
861 " #$ref has \`$svarvalue'\n"
862 if $mvarvalue ne $svarvalue;
864 &transcript("D| setupmatch \`$string' /$mvarname/$svarvalue/\n")
866 eval "\$$mvarname= \$svarvalue";
871 if (keys %limit_pkgs and not defined $limit_pkgs{$data->{package}}) {
872 &transcript("$gBug number $ref belongs to package $data->{package}, skipping.\n\n");
878 # High-level bug manipulation calls
879 # Do announcements themselves
881 # Possible calling sequences:
885 # &transcript(something)
889 # $action= (something)
891 # (modify s_* variables)
892 # } while (getnextbug);
895 &dlen("nochangebug");
896 $state eq 'single' || $state eq 'multiple' || die "$state ?";
898 &endmerge if $manybugs;
900 &dlex("nochangebug");
904 &dlen("setbug $ref");
905 if ($ref =~ m/^-\d+/) {
906 if (!defined $clonebugs{$ref}) {
908 &dlex("setbug => noclone");
911 $ref = $clonebugs{$ref};
913 $state eq 'idle' || die "$state ?";
916 &dlex("setbug => 0s");
920 if (!&checkpkglimit) {
925 @thisbugmergelist= split(/ /,$data->{mergedwith});
926 if (!@thisbugmergelist) {
931 &dlex("setbug => 1s");
940 &dlex("setbug => 0mc");
944 $state= 'multiple'; $sref=$ref;
945 &dlex("setbug => 1m");
951 $state eq 'single' || $state eq 'multiple' || die "$state ?";
953 if (!$manybugs || !@thisbugmergelist) {
954 length($action) || die;
955 &transcript("$action\n$extramessage\n");
956 &endmerge if $manybugs;
958 &dlex("getnextbug => 0");
961 $ref= shift(@thisbugmergelist);
962 &getbug || die "bug $ref disappeared";
964 &dlex("getnextbug => 1");
968 # Low-level bug-manipulation calls
969 # Do no announcements
977 # $action= (something)
982 # [getbug (returns 0)]
983 # &transcript("$action\n\n")
986 sub notfoundbug { &transcript("$gBug number $ref not found.\n\n"); }
987 sub foundbug { &transcript("$gBug#$ref: $data->{subject}\n"); }
991 $mergelowstate eq 'idle' || die "$mergelowstate ?";
992 &filelock('lock/merge');
993 $mergelowstate='locked';
999 $mergelowstate eq 'locked' || die "$mergelowstate ?";
1001 $mergelowstate='idle';
1006 &dlen("getbug $ref");
1007 $lowstate eq 'idle' || die "$state ?";
1008 if (($data = &lockreadbug($ref))) {
1011 &dlex("getbug => 1");
1016 &dlex("getbug => 0");
1022 $lowstate eq 'open' || die "$state ?";
1029 &dlen("savebug $ref");
1030 $lowstate eq 'open' || die "$lowstate ?";
1031 length($action) || die;
1032 $ref == $sref || die "read $sref but saving $ref ?";
1033 my $hash = get_hashname($ref);
1034 open(L,">>db-h/$hash/$ref.log") || &quit("opening db-h/$hash/$ref.log: $!");
1037 "<strong>".&sani($action)."</strong>\n".
1038 "Request was from <code>".&sani($header{'from'})."</code>\n".
1039 "to <code>".&sani($controlrequestaddr)."</code>. \n".
1041 "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/$hash/$ref.log: $!");
1042 close(L) || &quit("closing db-h/$hash/$ref.log: $!");
1043 unlockwritebug($ref, $data);
1050 &transcript("C> @_ ($state $lowstate $mergelowstate)\n");
1055 &transcript("R> @_ ($state $lowstate $mergelowstate)\n");
1059 print $_[0] if $debug;
1060 $transcript.= $_[0];
1067 my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
1068 $url =~ s/([<>&"])/\&$saniarray{$1};/g;
1084 sub sendtxthelpraw {
1085 local ($relpath,$description) = @_;
1087 open(D,"$gDocDir/$relpath") || &quit("open doc file $relpath: $!");
1088 while(<D>) { $doc.=$_; }
1090 &transcript("Sending $description in separate message.\n");
1091 &sendmailmessage(<<END.$doc,$replyto);
1092 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1094 Subject: $gProject $gBug help: $description
1095 References: $header{'message-id'}
1096 In-Reply-To: $header{'message-id'}
1097 Message-ID: <handler.s.$nn.help.$midix\@$gEmailDomain>
1099 X-$gProject-PR-Message: doc-text $relpath
1105 sub sendlynxdocraw {
1106 local ($relpath,$description) = @_;
1108 open(L,"lynx -nolist -dump http://$gCGIDomain/\Q$relpath\E 2>&1 |") || &quit("fork for lynx: $!");
1109 while(<L>) { $doc.=$_; }
1111 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1112 &transcript("Information ($description) is not available -\n".
1113 "perhaps the $gBug does not exist or is not on the WWW yet.\n");
1116 &transcript("Error getting $description (code $? $!):\n$doc\n");
1118 &transcript("Sending $description.\n");
1119 &sendmailmessage(<<END.$doc,$replyto);
1120 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1122 Subject: $gProject $gBugs information: $description
1123 References: $header{'message-id'}
1124 In-Reply-To: $header{'message-id'}
1125 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1127 X-$gProject-PR-Message: doc-html $relpath
1136 $maintccreasons{$cca}{''}{$ref}= 1;
1139 sub addmaintainers {
1140 # Data structure is:
1141 # maintainer email address &c -> assoc of packages -> assoc of bug#'s
1144 &ensuremaintainersloaded;
1145 $anymaintfound=0; $anymaintnotfound=0;
1146 for $p (split(m/[ \t?,():]+/, $data->{package})) {
1148 $p =~ /([a-z0-9.+-]+)/;
1150 next unless defined $p;
1151 if (defined $gSubscriptionDomain) {
1152 if (defined($pkgsrc{$p})) {
1153 addbcc("$pkgsrc{$p}\@$gSubscriptionDomain");
1155 addbcc("$p\@$gSubscriptionDomain");
1158 if (defined $data->{severity} and defined $gStrongList and
1159 isstrongseverity($data->{severity})) {
1160 addbcc("$gStrongList\@$gListDomain");
1162 if (defined($maintainerof{$p})) {
1163 $addmaint= $maintainerof{$p};
1164 &transcript("MR|$addmaint|$p|$ref|\n") if $dl>2;
1165 $maintccreasons{$addmaint}{$p}{$ref}= 1;
1166 print "maintainer add >$p|$addmaint<\n" if $debug;
1168 print "maintainer none >$p<\n" if $debug;
1169 &transcript("Warning: Unknown package '$p'\n");
1170 &transcript("MR|unknown-package|$p|$ref|\n") if $dl>2;
1171 $maintccreasons{$gUnknownMaintainerEmail}{$p}{$ref}= 1;
1175 if (length $data->{owner}) {
1176 $addmaint = $data->{owner};
1177 &transcript("MO|$addmaint|$data->{package}|$ref|\n") if $dl>2;
1178 $maintccreasons{$addmaint}{$data->{package}}{$ref} = 1;
1179 print "owner add >$data->{package}|$addmaint<\n" if $debug;
1183 sub ensuremaintainersloaded {
1185 return if $maintainersloaded++;
1186 open(MAINT,"$gMaintainerFile") || die &quit("maintainers open: $!");
1190 m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers bogus \`$_'");
1191 $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
1192 $maintainerof{$1}= $2;
1195 open(MAINT,"$gMaintainerFileOverride") || die &quit("maintainers.override open: $!");
1199 m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers.override bogus \`$_'");
1200 $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
1201 $maintainerof{$1}= $2;
1204 open(SOURCES, "$gPackageSource") || &quit("pkgsrc open: $!");
1206 next unless m/^(\S+)\s+\S+\s+(\S.*\S)\s*$/;
1207 my ($a, $b) = ($1, $2);
1208 $pkgsrc{lc($a)} = $b;
1214 local ($wherefrom,$path,$description) = @_;
1215 if ($wherefrom eq "ftp.d.o") {
1216 $doc = `lynx -nolist -dump http://ftp.debian.org/debian/indices/$path.gz 2>&1 | gunzip -cf` or &quit("fork for lynx/gunzip: $!");
1218 if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1219 &transcript("$description is not available.\n");
1222 &transcript("Error getting $description (code $? $!):\n$doc\n");
1225 } elsif ($wherefrom eq "local") {
1227 $doc = do { local $/; <P> };
1230 &transcript("internal errror: info files location unknown.\n");
1233 &transcript("Sending $description.\n");
1234 &sendmailmessage(<<END.$doc,$replyto);
1235 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1237 Subject: $gProject $gBugs information: $description
1238 References: $header{'message-id'}
1239 In-Reply-To: $header{'message-id'}
1240 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1242 X-$gProject-PR-Message: getinfo
1244 $description follows: