]> git.donarmstrong.com Git - debbugs.git/blob - scripts/service.in
[project @ 2005-07-29 17:16:56 by cjwatson]
[debbugs.git] / scripts / service.in
1 #!/usr/bin/perl
2 # $Id: service.in,v 1.109 2005/07/29 17:16:56 cjwatson Exp $
3 #
4 # Usage: service <code>.nn
5 # Temps:  incoming/P<code>.nn
6
7 use File::Copy;
8 use MIME::Parser;
9 use Debbugs::MIME qw(decode_rfc1522);
10
11 $config_path = '/etc/debbugs';
12 $lib_path = '/usr/lib/debbugs';
13
14 require "$config_path/config";
15 require "$lib_path/errorlib";
16 $ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
17
18 chdir("$gSpoolDir") || die "chdir spool: $!\n";
19
20 # open(DEBUG,">&4");
21 open DEBUG, ">/dev/null";
22 $debug = 0;
23 umask(002);
24
25 $_=shift;
26 m/^[RC]\.\d+$/ || &quit("bad argument");
27 $control= m/C/;
28 $nn= $_;
29 if (!rename("incoming/G$nn","incoming/P$nn")) {
30     $_=$!.'';  m/no such file or directory/i && exit 0;
31     &quit("renaming to lock: $!");
32 }    
33
34 open(M,"incoming/P$nn");
35 @log=<M>;
36 @msg=@log;
37 close(M);
38
39 chomp @msg;
40
41 print "###\n",join("##\n",@msg),"\n###\n" if $debug;
42
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)) };
47
48 # header and decoded body respectively
49 my (@headerlines, @bodylines);
50 # Bug numbers to send e-mail to, hash so that we don't send to the
51 # same bug twice.
52 my (%bug_affected);
53
54 if ($entity and $entity->head->tags) {
55     @headerlines = @{$entity->head->header};
56     chomp @headerlines;
57
58     my $entity_body = getmailbody($entity);
59     @bodylines = $entity_body ? $entity_body->as_lines() : ();
60     chomp @bodylines;
61 } else {
62     # Legacy pre-MIME code, kept around in case MIME::Parser fails.
63     my $i;
64     for ($i = 0; $i <= $#msg; $i++) {
65         $_ = $msg[$i];
66         last unless length($_);
67         while ($msg[$i+1] =~ m/^\s/) {
68             $i++;
69             $_ .= "\n".$msg[$i];
70         }
71         push @headerlines, $_;
72     }
73
74     @bodylines = @msg[$i..$#msg];
75 }
76
77 for (@headerlines) {
78     s/\n\s/ /g;
79     print ">$_<\n" if $debug;
80     if (s/^(\S+):\s*//) {
81         my $v = lc $1;
82         print ">$v=$_<\n" if $debug;
83         $header{$v} = decode_rfc1522($_);
84     } else {
85         print "!>$_<\n" if $debug;
86     }
87 }
88
89 # Strip off RFC2440-style PGP clearsigning.
90 if (@bodylines and $bodylines[0] =~ /^-----BEGIN PGP SIGNED/) {
91     shift @bodylines while @bodylines and length $bodylines[0];
92     shift @bodylines while @bodylines and $bodylines[0] !~ /\S/;
93     for my $findsig (0 .. $#bodylines) {
94         if ($bodylines[$findsig] =~ /^-----BEGIN PGP SIGNATURE/) {
95             $#bodylines = $findsig - 1;
96             last;
97         }
98     }
99     map { s/^- // } @bodylines;
100 }
101
102 grep(s/\s+$//,@bodylines);
103
104 print "***\n",join("\n",@bodylines),"\n***\n" if $debug;
105
106 if (defined $header{'resent-from'} && !defined $header{'from'}) {
107     $header{'from'} = $header{'resent-from'};
108 }
109
110 defined($header{'from'}) || &quit("no From header");
111
112 delete $header{'reply-to'} 
113         if ( defined($header{'reply-to'}) && $header{'reply-to'} =~ m/^\s*$/ );
114
115 if ( defined($header{'reply-to'}) && $header{'reply-to'} ne "" ) {
116     $replyto = $header{'reply-to'};
117 } else {
118     $replyto = $header{'from'};
119 }
120
121 $controlrequestaddr= $control ? "control\@$gEmailDomain" : "request\@$gEmailDomain";
122 $transcript='';
123 &transcript("Processing commands for $controlrequestaddr:\n\n");
124
125 $dl= 0;
126 $state= 'idle';
127 $lowstate= 'idle';
128 $mergelowstate= 'idle';
129 $midix=0;    
130 $extras="";
131
132 my $quickabort = 0;
133
134 my $fuckheads = "(" . join("|", @gFuckheads) . ")";
135 if (@gFuckheads and $replyto =~ m/$fuckheads/) {
136         &transcript("This service is unavailable.\n\n");
137         $quickabort = 1;
138 }
139
140 my %limit_pkgs = ();
141 my %clonebugs = ();
142 my @bcc = ();
143
144 sub addbcc {
145     push @bcc, $_[0] unless grep { $_ eq $_[0] } @bcc;
146 }
147
148 for ($procline=0; $procline<=$#bodylines; $procline++) {
149     $state eq 'idle' || print "$state ?\n";
150     $lowstate eq 'idle' || print "$lowstate ?\n";
151     $mergelowstate eq 'idle' || print "$mergelowstate ?\n";
152     if ($quickabort) {
153          &transcript("Stopping processing here.\n\n");
154          last;
155     }
156     $_= $bodylines[$procline]; s/\s+$//;
157     next unless m/\S/;
158     &transcript("> $_\n");
159     next if m/^\s*\#/;
160     $action= '';
161     if (m/^stop/i || m/^quit/i || m/^--/ || m/^thank/i) {
162         &transcript("Stopping processing here.\n\n");
163         last;
164     } elsif (m/^debug\s+(\d+)$/i && $1 >= 0 && $1 <= 1000) {
165         $dl= $1+0;
166         &transcript("Debug level $dl.\n\n");
167     } elsif (m/^(send|get)\s+\#?(\d{2,})$/i) {
168         $ref= $2+0;
169         &sendlynxdoc("bugreport.cgi?bug=$ref","logs for $gBug#$ref");
170     } elsif (m/^send-detail\s+\#?(\d{2,})$/i) {
171         $ref= $1+0;
172         &sendlynxdoc("bugreport.cgi?bug=$ref&boring=yes",
173                      "detailed logs for $gBug#$ref");
174     } elsif (m/^index(\s+full)?$/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-package$/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-summary(\s+by-number)?$/i) {
181         &transcript("This BTS function is currently disabled, sorry.\n\n");
182         $ok++; # well, it's not really ok, but it fixes #81224 :)
183     } elsif (m/^index(\s+|-)pack(age)?s?$/i) {
184         &sendlynxdoc("pkgindex.cgi?indexon=pkg",'index of packages');
185     } elsif (m/^index(\s+|-)maints?$/i) {
186         &sendlynxdoc("pkgindex.cgi?indexon=maint",'index of maintainers');
187     } elsif (m/^index(\s+|-)maint\s+(\S+)$/i) {
188         $maint = $2;
189         &sendlynxdoc("pkgreport.cgi?maint=" . urlsanit($maint),
190                      "$gBug list for maintainer \`$maint'");
191         $ok++;
192     } elsif (m/^index(\s+|-)pack(age)?s?\s+(\S.*\S)$/i) {
193         $package = $+;
194         &sendlynxdoc("pkgreport.cgi?pkg=" . urlsanit($package),
195                      "$gBug list for package $package");
196         $ok++;
197     } elsif (m/^send-unmatched(\s+this|\s+-?0)?$/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+(last|-1)$/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/^send-unmatched\s+(old|-2)$/i) {
204         &transcript("This BTS function is currently disabled, sorry.\n\n");
205         $ok++; # well, it's not really ok, but it fixes #81224 :)
206     } elsif (m/^getinfo\s+([\w-.]+)$/i) {
207         # the following is basically a Debian-specific kludge, but who cares
208         $req = $1;
209         if ($req =~ /^maintainers$/i && -f "$gConfigDir/Maintainers") {
210             &sendinfo("local", "$gConfigDir/Maintainers", "Maintainers file");
211         } elsif ($req =~ /^override\.(\w+)\.([\w-.]+)$/i) {
212             $req =~ s/.gz$//;
213             &sendinfo("ftp.d.o", "$req", "override file for $2 part of $1 distribution");
214         } elsif ($req =~ /^pseudo-packages\.(description|maintainers)$/i && -f "$gConfigDir/$req") {
215             &sendinfo("local", "$gConfigDir/$req", "$req file");
216         } else {
217             &transcript("Info file $req does not exist.\n\n");
218         }
219     } elsif (m/^help/i) {
220         &sendhelp;
221         &transcript("\n");
222         $ok++;
223     } elsif (m/^refcard/i) {
224         &sendtxthelp("bug-mailserver-refcard.txt","mail servers' reference card");
225     } elsif (m/^subscribe/i) {
226         &transcript(<<END);
227 There is no $gProject $gBug mailing list.  If you wish to review bug reports
228 please do so via http://$gWebDomain/ or ask this mail server
229 to send them to you.
230 soon: MAILINGLISTS_TEXT
231 END
232     } elsif (m/^unsubscribe/i) {
233         &transcript(<<END);
234 soon: UNSUBSCRIBE_TEXT
235 soon: MAILINGLISTS_TEXT
236 END
237     } elsif (!$control) {
238         &transcript(<<END);
239 Unknown command or malformed arguments to command.
240 (Use control\@$gEmailDomain to manipulate reports.)
241
242 END
243         if (++$unknowns >= 3) {
244             &transcript("Too many unknown commands, stopping here.\n\n");
245             last;
246         }
247 #### interesting ones start here
248     } elsif (m/^close\s+\#?(-?\d+)(?:\s+(\d.*))?$/i) {
249         $ok++;
250         $ref= $1;
251         $bug_affected{$ref}=1;
252         $version= $2;
253         if (&setbug) {
254             &transcript("'close' is deprecated; see http://$gWebDomain/Developer$gHTMLSuffix#closing.\n");
255             if (length($data->{done}) and not defined($version)) {
256                 &transcript("$gBug is already closed, cannot re-close.\n\n");
257                 &nochangebug;
258             } else {
259                 $action= "$gBug " .
260                     (defined($version) ?
261                         "marked as fixed in version $version" :
262                         "closed") .
263                     ", send any further explanations to $data->{originator}";
264                 do {
265                     &addmaintainers($data);
266                                         if ( length( $gDoneList ) > 0 && length( $gListDomain ) >
267                                         0 ) { &addccaddress("$gDoneList\@$gListDomain"); }
268                     $data->{done}= $replyto;
269                     my @keywords= split ' ', $data->{keywords};
270                     if (grep $_ eq 'pending', @keywords) {
271                         $extramessage= "Removed pending tag.\n";
272                         $data->{keywords}= join ' ', grep $_ ne 'pending',
273                                                 @keywords;
274                     }
275                     addfixedversions($data, $data->{package}, $version, 'binary');
276
277                     $message= <<END;
278 From: $gMaintainerEmail ($gProject $gBug Tracking System)
279 To: $data->{originator}
280 Subject: $gBug#$ref acknowledged by developer
281          ($header{'subject'})
282 References: $header{'message-id'} $data->{msgid}
283 In-Reply-To: $data->{msgid}
284 Message-ID: <handler.$ref.$nn.notifdonectrl.$midix\@$gEmailDomain>
285 Reply-To: $ref\@$gEmailDomain
286 X-$gProject-PR-Message: they-closed-control $ref
287
288 This is an automatic notification regarding your $gBug report
289 #$ref: $data->{subject},
290 which was filed against the $data->{package} package.
291
292 It has been marked as closed by one of the developers, namely
293 $replyto.
294
295 You should be hearing from them with a substantive response shortly,
296 in case you haven't already. If not, please contact them directly.
297
298 $gMaintainer
299 (administrator, $gProject $gBugs database)
300
301 END
302                     &sendmailmessage($message,$data->{originator});
303                 } while (&getnextbug);
304             }
305         }
306     } elsif (m/^reassign\s+\#?(-?\d+)\s+(\S+)(?:\s+(\d.*))?$/i) {
307         $ok++;
308         $ref= $1; $newpackage= $2;
309         $bug_affected{$ref}=1;
310         $version= $3;
311         $newpackage =~ y/A-Z/a-z/;
312         if (&setbug) {
313             if (length($data->{package})) {
314                 $action= "$gBug reassigned from package \`$data->{package}'".
315                          " to \`$newpackage'.";
316             } else {
317                 $action= "$gBug assigned to package \`$newpackage'.";
318             }
319             do {
320                 &addmaintainers($data);
321                 $data->{package}= $newpackage;
322                 $data->{found_versions}= [];
323                 $data->{fixed_versions}= [];
324                 # TODO: what if $newpackage is a source package?
325                 addfoundversions($data, $data->{package}, $version, 'binary');
326                 &addmaintainers($data);
327             } while (&getnextbug);
328         }
329     } elsif (m/^reopen\s+\#?(-?\d+)$/i ? ($noriginator='', 1) :
330              m/^reopen\s+\#?(-?\d+)\s+\=$/i ? ($noriginator='', 1) :
331              m/^reopen\s+\#?(-?\d+)\s+\!$/i ? ($noriginator=$replyto, 1) :
332              m/^reopen\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($noriginator=$2, 1) : 0) {
333         $ok++;
334         $ref= $1;
335         $bug_affected{$ref}=1;
336         if (&setbug) {
337             if (@{$data->{fixed_versions}}) {
338                 &transcript("'reopen' is deprecated when a bug has been closed with a version;\nuse 'found' or 'submitter' as appropriate instead.\n");
339             }
340             if (!length($data->{done})) {
341                 &transcript("$gBug is already open, cannot reopen.\n\n");
342                 &nochangebug;
343             } else {
344                 $action=
345                     $noriginator eq '' ? "$gBug reopened, originator not changed." :
346                         "$gBug reopened, originator set to $noriginator.";
347                 do {
348                     &addmaintainers($data);
349                     $data->{originator}= $noriginator eq '' ?  $data->{originator} : $noriginator;
350                     $data->{fixed_versions}= [];
351                     $data->{done}= '';
352                 } while (&getnextbug);
353             }
354         }
355     } elsif (m/^found\s+\#?(-?\d+)(?:\s+(\d.*))?$/i) {
356         $ok++;
357         $ref= $1;
358         $version= $2;
359         if (&setbug) {
360             if (!length($data->{done}) and not defined($version)) {
361                 &transcript("$gBug is already open, cannot reopen.\n\n");
362                 &nochangebug;
363             } else {
364                 $action=
365                     defined($version) ?
366                         "$gBug marked as found in version $version." :
367                         "$gBug reopened.";
368                 do {
369                     &addmaintainers($data);
370                     # The 'done' field gets a bit weird with version
371                     # tracking, because a bug may be closed by multiple
372                     # people in different branches. Until we have something
373                     # more flexible, we set it every time a bug is fixed,
374                     # and clear it precisely when a found command is
375                     # received for the rightmost fixed-in version, which
376                     # equates to the most recent fixing of the bug, or when
377                     # a versionless found command is received.
378                     if (defined $version) {
379                         my $lastfixed =
380                             (reverse @{$data->{fixed_versions}})[0];
381                         # TODO: what if $data->{package} is a source package?
382                         addfoundversions($data, $data->{package}, $version, 'binary');
383                         if (defined $lastfixed and not grep { $_ eq $lastfixed } @{$data->{fixed_versions}}) {
384                             $data->{done} = '';
385                         }
386                     } else {
387                         # Versionless found; assume old-style "not fixed at
388                         # all".
389                         $data->{fixed_versions} = [];
390                         $data->{done} = '';
391                     }
392                 } while (&getnextbug);
393             }
394         }
395     } elsif (m/^notfound\s+\#?(-?\d+)\s+(\d.*)$/i) {
396         $ok++;
397         $ref= $1;
398         $version= $2;
399         if (&setbug) {
400             $action= "$gBug marked as not found in version $version.";
401             if (length($data->{done})) {
402                 $extramessage= "(By the way, this $gBug is currently marked as done.)\n";
403             }
404             do {
405                 &addmaintainers($data);
406                 removefoundversions($data, $data->{package}, $version, 'binary');
407             } while (&getnextbug);
408         }
409     } elsif (m/^submitter\s+\#?(-?\d+)\s+\!$/i ? ($newsubmitter=$replyto, 1) :
410              m/^submitter\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($newsubmitter=$2, 1) : 0) {
411         $ok++;
412         $ref= $1;
413         $bug_affected{$ref}=1;
414         if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
415             $ref = $clonebugs{$ref};
416         }
417         if (&getbug) {
418             if (&checkpkglimit) {
419                 &foundbug;
420                 &addmaintainers($data);
421                 $oldsubmitter= $data->{originator};
422                 $data->{originator}= $newsubmitter;
423                 $action= "Changed $gBug submitter from $oldsubmitter to $newsubmitter.";
424                 &savebug;
425                 &transcript("$action\n");
426                 if (length($data->{done})) {
427                     &transcript("(By the way, that $gBug is currently marked as done.)\n");
428                 }
429                 &transcript("\n");
430                 $message= <<END;
431 From: $gMaintainerEmail ($gProject $gBug Tracking System)
432 To: $oldsubmitter
433 Subject: $gBug#$ref submitter address changed
434          ($header{'subject'})
435 References: $header{'message-id'} $data->{msgid}
436 In-Reply-To: $data->{msgid}
437 Message-ID: <handler.$ref.$nn.newsubmitter.$midix\@$gEmailDomain>
438 Reply-To: $ref\@$gEmailDomain
439 X-$gProject-PR-Message: submitter-changed $ref
440
441 The submitter address recorded for your $gBug report
442 #$ref: $data->{subject}
443 has been changed.
444
445 The new submitter address for this report is
446 $newsubmitter.
447
448 This change was made by
449 $replyto.
450 If it was incorrect, please contact them directly.
451
452 $gMaintainer
453 (administrator, $gProject $gBugs database)
454
455 END
456                 &sendmailmessage($message,$oldsubmitter);
457             } else {
458                 &cancelbug;
459             }
460         } else {
461             &notfoundbug;
462         }
463     } elsif (m/^forwarded\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
464         $ok++;
465         $ref= $1; $whereto= $2;
466         $bug_affected{$ref}=1;
467         if (&setbug) {
468             if (length($data->{forwarded})) {
469     $action= "Forwarded-to-address changed from $data->{forwarded} to $whereto.";
470             } else {
471     $action= "Noted your statement that $gBug has been forwarded to $whereto.";
472             }
473             if (length($data->{done})) {
474                 $extramessage= "(By the way, this $gBug is currently marked as done.)\n";
475             }
476             do {
477                 &addmaintainers($data);
478                 if (length($gForwardList)>0 && length($gListDomain)>0 ) {
479                      &addccaddress("$gForwardList\@$gListDomain"); 
480                 }
481                 $data->{forwarded}= $whereto;
482             } while (&getnextbug);
483         }
484     } elsif (m/^notforwarded\s+\#?(-?\d+)$/i) {
485         $ok++;
486         $ref= $1;
487         $bug_affected{$ref}=1;
488         if (&setbug) {
489             if (!length($data->{forwarded})) {
490                 &transcript("$gBug is not marked as having been forwarded.\n\n");
491                 &nochangebug;
492             } else {
493     $action= "Removed annotation that $gBug had been forwarded to $data->{forwarded}.";
494                 do {
495                     &addmaintainers($data);
496                     $data->{forwarded}= '';
497                 } while (&getnextbug);
498             }
499         }
500     } elsif (m/^severity\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i ||
501         m/^priority\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i) {
502         $ok++;
503         $ref= $1;
504         $bug_affected{$ref}=1;
505         $newseverity= $2;
506         if (!grep($_ eq $newseverity, @gSeverityList, "$gDefaultSeverity")) {
507             &transcript("Severity level \`$newseverity' is not known.\n".
508                         "Recognized are: $gShowSeverities.\n\n");
509         } elsif (exists $gObsoleteSeverities{$newseverity}) {
510             &transcript("Severity level \`$newseverity' is obsolete. " .
511                         "$gObsoleteSeverities{$newseverity}\n\n");
512         } elsif (&setbug) {
513             $printseverity= $data->{severity};
514             $printseverity= "$gDefaultSeverity" if $printseverity eq '';
515             $action= "Severity set to \`$newseverity' from \`$printseverity'";
516             do {
517                 &addmaintainers($data);
518                 if (defined $gStrongList and isstrongseverity($newseverity)) {
519                     addbcc("$gStrongList\@$gListDomain");
520                 }
521                 $data->{severity}= $newseverity;
522             } while (&getnextbug);
523         }
524     } elsif (m/^tags?\s+\#?(-?\d+)\s+(([=+-])\s*)?(\S.*)?$/i) {
525         $ok++;
526         $ref = $1; $addsubcode = $3; $tags = $4;
527         $bug_affected{$ref}=1;
528         $addsub = "add";
529         if (defined $addsubcode) {
530             $addsub = "sub" if ($addsubcode eq "-");
531             $addsub = "add" if ($addsubcode eq "+");
532             $addsub = "set" if ($addsubcode eq "=");
533         }
534         my @okaytags = ();
535         my @badtags = ();
536         foreach my $t (split /[\s,]+/, $tags) {
537             if (!grep($_ eq $t, @gTags)) {
538                 push @badtags, $t;
539             } else {
540                 push @okaytags, $t;
541             }
542         }
543         if (@badtags) {
544             &transcript("Unknown tag/s: ".join(', ', @badtags).".\n".
545                         "Recognized are: ".join(' ', @gTags).".\n\n");
546         }
547         if (&setbug) {
548             if ($data->{keywords} eq '') {
549                 &transcript("There were no tags set.\n");
550             } else {
551                 &transcript("Tags were: $data->{keywords}\n");
552             }
553             if ($addsub eq "set") {
554                 $action= "Tags set to: " . join(", ", @okaytags);
555             } elsif ($addsub eq "add") {
556                 $action= "Tags added: " . join(", ", @okaytags);
557             } elsif ($addsub eq "sub") {
558                 $action= "Tags removed: " . join(", ", @okaytags);
559             }
560             do {
561                 &addmaintainers($data);
562                 $data->{keywords} = '' if ($addsub eq "set");
563                 # Allow removing obsolete tags.
564                 if ($addsub eq "sub") {
565                     foreach my $t (@badtags) {
566                         $data->{keywords} = join ' ', grep $_ ne $t, 
567                             split ' ', $data->{keywords};
568                     }
569                 }
570                 # Now process all other additions and subtractions.
571                 foreach my $t (@okaytags) {
572                     $data->{keywords} = join ' ', grep $_ ne $t, 
573                         split ' ', $data->{keywords};
574                     $data->{keywords} = "$t $data->{keywords}" unless($addsub eq "sub");
575                 }
576                 $data->{keywords} =~ s/\s*$//;
577             } while (&getnextbug);
578         }
579     } elsif (m/^retitle\s+\#?(-?\d+)\s+(\S.*\S)\s*$/i) {
580         $ok++;
581         $ref= $1; $newtitle= $2;
582         $bug_affected{$ref}=1;
583         if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
584             $ref = $clonebugs{$ref};
585         }
586         if (&getbug) {
587             if (&checkpkglimit) {
588                 &foundbug;
589                 &addmaintainers($data);
590                 $data->{subject}= $newtitle;
591                 $action= "Changed $gBug title.";
592                 &savebug;
593                 &transcript("$action\n");
594                 if (length($data->{done})) {
595                     &transcript("(By the way, that $gBug is currently marked as done.)\n");
596                 }
597                 &transcript("\n");
598             } else {
599                 &cancelbug;
600             }
601         } else {
602             &notfoundbug;
603         }
604     } elsif (m/^unmerge\s+\#?(-?\d+)$/i) {
605         $ok++;
606         $ref= $1;
607         $bug_affected{$ref} = 1;
608         if (&setbug) {
609             if (!length($data->{mergedwith})) {
610                 &transcript("$gBug is not marked as being merged with any others.\n\n");
611                 &nochangebug;
612             } else {
613                 $mergelowstate eq 'locked' || die "$mergelowstate ?";
614                 $action= "Disconnected #$ref from all other report(s).";
615                 @newmergelist= split(/ /,$data->{mergedwith});
616                 $discref= $ref;
617                 @bug_affected{@newmergelist} = 1 x @newmergelist;
618                 do {
619                     &addmaintainers($data);
620                     $data->{mergedwith}= ($ref == $discref) ? ''
621                         : join(' ',grep($_ ne $ref,@newmergelist));
622                 } while (&getnextbug);
623             }
624         }
625     } elsif (m/^merge\s+#?(-?\d+(\s+#?-?\d+)+)\s*$/i) {
626         $ok++;
627         @tomerge= sort { $a <=> $b } split(/\s+#?/,$1);
628         @newmergelist= ();
629         my %tags = ();
630         my %found = ();
631         my %fixed = ();
632         &getmerge;
633         while (defined($ref= shift(@tomerge))) {
634             &transcript("D| checking merge $ref\n") if $dl;
635             $ref+= 0;
636             if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
637                 $ref = $clonebugs{$ref};
638             }
639             next if grep($_ eq $ref,@newmergelist);
640             if (!&getbug) { &notfoundbug; @newmergelist=(); last }
641             if (!&checkpkglimit) { &cancelbug; @newmergelist=(); last; }
642             &foundbug;
643             &transcript("D| adding $ref ($data->{mergedwith})\n") if $dl;
644             $mismatch= '';
645             &checkmatch('package','m_package',$data->{package});
646             &checkmatch('forwarded addr','m_forwarded',$data->{forwarded});
647             $data->{severity} = '$gDefaultSeverity' if $data->{severity} eq '';
648             &checkmatch('severity','m_severity',$data->{severity});
649             &checkmatch('done mark','m_done',length($data->{done}) ? 'done' : 'open');
650             &checkmatch('owner','m_owner',$data->{owner});
651             foreach my $t (split /\s+/, $data->{keywords}) { $tags{$t} = 1; }
652             foreach my $f (@{$data->{found_versions}}) { $found{$f} = 1; }
653             foreach my $f (@{$data->{fixed_versions}}) { $fixed{$f} = 1; }
654             if (length($mismatch)) {
655                 &transcript("Mismatch - only $gBugs in same state can be merged:\n".
656                             $mismatch."\n");
657                 &cancelbug; @newmergelist=(); last;
658             }
659             push(@newmergelist,$ref);
660             push(@tomerge,split(/ /,$data->{mergedwith}));
661             &cancelbug;
662         }
663         if (@newmergelist) {
664             @newmergelist= sort { $a <=> $b } @newmergelist;
665             $action= "Merged @newmergelist.";
666             delete @fixed{keys %found};
667             for $ref (@newmergelist) {
668                 &getbug || die "huh ?  $gBug $ref disappeared during merge";
669                 &addmaintainers($data);
670                 @bug_affected{@newmergelist} = 1 x @newmergelist;
671                 $data->{mergedwith}= join(' ',grep($_ ne $ref,@newmergelist));
672                 $data->{keywords}= join(' ', keys %tags);
673                 $data->{found_versions}= [sort keys %found];
674                 $data->{fixed_versions}= [sort keys %fixed];
675                 &savebug;
676             }
677             &transcript("$action\n\n");
678         }
679         &endmerge;
680     } elsif (m/^clone\s+#?(\d+)\s+((-\d+\s+)*-\d+)\s*$/i) {
681         $ok++;
682
683         $origref = $1;
684         @newclonedids = split /\s+/, $2;
685         $newbugsneeded = scalar(@newclonedids);
686
687         $ref = $origref;
688         $bug_affected{$ref} = 1;
689         if (&setbug) {
690             if (length($data->{mergedwith})) {
691                 &transcript("$gBug is marked as being merged with others.\n\n");
692                 &nochangebug;
693             } else {
694                 &filelock("nextnumber.lock");
695                 open(N,"nextnumber") || &quit("nextnumber: read: $!");
696                 $v=<N>; $v =~ s/\n$// || &quit("nextnumber bad format");
697                 $firstref= $v+0;  $v += $newbugsneeded;
698                 open(NN,">nextnumber"); print NN "$v\n"; close(NN);
699                 &unfilelock;
700
701                 $lastref = $firstref + $newbugsneeded - 1;
702
703                 if ($newbugsneeded == 1) {
704                     $action= "$gBug $origref cloned as bug $firstref.";
705                 } else {
706                     $action= "$gBug $origref cloned as bugs $firstref-$lastref.";
707                 }
708                 &getnextbug;
709                 my $ohash = get_hashname($origref);
710                 $ref = $firstref;
711                 @bug_affected{@newclonedids} = 1 x @newclonedids;
712                 for $newclonedid (@newclonedids) {
713                     $clonebugs{$newclonedid} = $ref;
714             
715                     my $hash = get_hashname($ref);
716                     copy("db-h/$ohash/$origref.log", "db-h/$hash/$ref.log");
717                     copy("db-h/$ohash/$origref.status", "db-h/$hash/$ref.status");
718                     copy("db-h/$ohash/$origref.summary", "db-h/$hash/$ref.summary");
719                     copy("db-h/$ohash/$origref.report", "db-h/$hash/$ref.report");
720                     &bughook('new', $ref, $data);
721
722                     $ref++;
723                 }
724             }
725         }
726     } elsif (m/^package\s+(\S.*\S)?\s*$/i) {
727         $ok++;
728         my @pkgs = split /\s+/, $1;
729         if (scalar(@pkgs) > 0) {
730                 %limit_pkgs = map { ($_, 1) } @pkgs;
731                 &transcript("Ignoring bugs not assigned to: " . 
732                         join(" ", keys(%limit_pkgs)) . "\n\n");
733         } else {
734                 %limit_pkgs = ();
735                 &transcript("Not ignoring any bugs.\n\n");
736         }
737     } elsif (m/^owner\s+\#?(-?\d+)\s+!$/i ? ($newowner = $replyto, 1) :
738              m/^owner\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($newowner = $2, 1) : 0) {
739         $ok++;
740         $ref = $1;
741         $bug_affected{$ref} = 1;
742         if (&setbug) {
743             if (length $data->{owner}) {
744                 $action = "Owner changed from $data->{owner} to $newowner.";
745             } else {
746                 $action = "Owner recorded as $newowner.";
747             }
748             if (length $data->{done}) {
749                 $extramessage = "(By the way, this $gBug is currently " .
750                                 "marked as done.)\n";
751             }
752             do {
753                 &addmaintainers($data);
754                 $data->{owner} = $newowner;
755             } while (&getnextbug);
756         }
757     } elsif (m/^noowner\s+\#?(-?\d+)$/i) {
758         $ok++;
759         $ref = $1;
760         $bug_affected{$ref} = 1;
761         if (&setbug) {
762             if (length $data->{owner}) {
763                 $action = "Removed annotation that $gBug was owned by " .
764                           "$data->{owner}.";
765                 do {
766                     &addmaintainers($data);
767                     $data->{owner} = '';
768                 } while (&getnextbug);
769             } else {
770                 &transcript("$gBug is not marked as having an owner.\n\n");
771                 &nochangebug;
772             }
773         }
774     } else {
775         &transcript("Unknown command or malformed arguments to command.\n\n");
776         if (++$unknowns >= 5) {
777             &transcript("Too many unknown commands, stopping here.\n\n");
778             last;
779         }
780     }
781 }
782 if ($procline>$#bodylines) {
783     &transcript(">\nEnd of message, stopping processing here.\n\n");
784 }
785 if (!$ok && !quickabort) {
786     &transcript("No commands successfully parsed; sending the help text(s).\n");
787     &sendhelp;
788     &transcript("\n");
789 }
790
791 &transcript("MC\n") if $dl>1;
792 @maintccs= ();
793 for $maint (keys %maintccreasons) {
794 &transcript("MM|$maint|\n") if $dl>1;
795     next if $maint eq $replyto;
796     $reasonstring= '';
797     $reasonsref= $maintccreasons{$maint};
798 &transcript("MY|$maint|\n") if $dl>2;
799     for $p (sort keys %$reasonsref) {
800 &transcript("MP|$p|\n") if $dl>2;
801         $reasonstring.= ', ' if length($reasonstring);
802         $reasonstring.= $p.' ' if length($p);
803         $reasonstring.= join(' ',map("#$_",sort keys %{$$reasonsref{$p}}));
804     }
805     if (length($reasonstring) > 40) {
806         (substr $reasonstring, 37) = "...";
807     }
808     $reasonstring = "" if (!defined($reasonstring));
809     push(@maintccs,"$maint ($reasonstring)");
810     push(@maintccaddrs,"$maint");
811 }
812
813 $maintccs = ""; 
814 if (@maintccs) {
815     &transcript("MC|@maintccs|\n") if $dl>2;
816     $maintccs .= "Cc: " . join(",\n    ",@maintccs) . "\n";
817 }
818
819 # Add Bcc's to subscribed bugs
820 push @bcc, map {"bugs=$_\@$gListDomain"} keys %bug_affected;
821
822 if (!defined $header{'subject'} || $header{'subject'} eq "") {
823   $header{'subject'} = "your mail";
824 }
825
826 $reply= <<END;
827 From: $gMaintainerEmail ($gProject $gBug Tracking System)
828 To: $replyto
829 ${maintccs}Subject: Processed: $header{'subject'}
830 In-Reply-To: $header{'message-id'}
831 References: $header{'message-id'}
832 Message-ID: <handler.s.$nn.transcript\@$gEmailDomain>
833 Precedence: bulk
834 X-$gProject-PR-Message: transcript
835
836 ${transcript}Please contact me if you need assistance.
837
838 $gMaintainer
839 (administrator, $gProject $gBugs database)
840 $extras
841 END
842
843 $repliedshow= join(', ',$replyto,@maintccaddrs);
844 &filelock("lock/-1");
845 open(AP,">>db-h/-1.log") || &quit("open db-h/-1.log: $!");
846 print(AP
847       "\2\n$repliedshow\n\5\n$reply\n\3\n".
848       "\6\n".
849       "<strong>Request received</strong> from <code>".
850       &sani($header{'from'})."</code>\n".
851       "to <code>".&sani($controlrequestaddr)."</code>\n".
852       "\3\n".
853       "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/-1.log: $!");
854 close(AP) || &quit("open db-h/-1.log: $!");
855 &unfilelock;
856 utime(time,time,"db-h");
857
858 &sendmailmessage($reply,$replyto,@maintccaddrs,@bcc);
859
860 unlink("incoming/P$nn") || &quit("unlinking incoming/P$nn: $!");
861
862 sub sendmailmessage {
863     local ($message,@recips) = @_;
864     $message = "X-Loop: $gMaintainerEmail\n" . $message;
865     print "mailing to >@recips<\n" if $debug;
866     $c= open(D,"|-");
867     defined($c) || &quit("mailing forking for sendmail: $!");
868     if (!$c) { # ie, we are the child process
869         exec '/usr/lib/sendmail','-f'."$gMaintainerEmail",'-odb','-oem','-oi',get_addresses(@recips);
870         die $!;
871     }
872     print(D $message) || &quit("writing to sendmail process: $!");
873     $!=0; close(D); $? && &quit("sendmail gave exit status $? ($!)");
874     $midix++;
875 }
876
877 sub sendhelp {
878         &sendtxthelpraw("bug-log-mailserver.txt","instructions for request\@$gEmailDomain");
879         &sendtxthelpraw("bug-maint-mailcontrol.txt","instructions for control\@$gEmailDomain")
880             if $control;
881 }
882
883 #sub unimplemented {
884 #    &transcript("Sorry, command $_[0] not yet implemented.\n\n");
885 #}
886
887 sub checkmatch {
888     local ($string,$mvarname,$svarvalue) = @_;
889     local ($mvarvalue);
890     if (@newmergelist) {
891         eval "\$mvarvalue= \$$mvarname";
892         &transcript("D| checkmatch \`$string' /$mvarname/$mvarvalue/$svarvalue/\n")
893             if $dl;
894         $mismatch .=
895             "Values for \`$string' don't match:\n".
896             " #$newmergelist[0] has \`$mvarvalue';\n".
897             " #$ref has \`$svarvalue'\n"
898             if $mvarvalue ne $svarvalue;
899     } else {
900         &transcript("D| setupmatch \`$string' /$mvarname/$svarvalue/\n")
901             if $dl;
902         eval "\$$mvarname= \$svarvalue";
903     }
904 }
905
906 sub checkpkglimit {
907     if (keys %limit_pkgs and not defined $limit_pkgs{$data->{package}}) {
908         &transcript("$gBug number $ref belongs to package $data->{package}, skipping.\n\n");
909         return 0;
910     }
911     return 1;
912 }
913
914 # High-level bug manipulation calls
915 # Do announcements themselves
916 #
917 # Possible calling sequences:
918 #    setbug (returns 0)
919 #    
920 #    setbug (returns 1)
921 #    &transcript(something)
922 #    nochangebug
923 #
924 #    setbug (returns 1)
925 #    $action= (something)
926 #    do {
927 #      (modify s_* variables)
928 #    } while (getnextbug);
929
930 sub nochangebug {
931     &dlen("nochangebug");
932     $state eq 'single' || $state eq 'multiple' || die "$state ?";
933     &cancelbug;
934     &endmerge if $manybugs;
935     $state= 'idle';
936     &dlex("nochangebug");
937 }
938
939 sub setbug {
940     &dlen("setbug $ref");
941     if ($ref =~ m/^-\d+/) {
942         if (!defined $clonebugs{$ref}) {
943             &notfoundbug;
944             &dlex("setbug => noclone");
945             return 0;
946         }
947         $ref = $clonebugs{$ref};
948     }
949     $state eq 'idle' || die "$state ?";
950     if (!&getbug) {
951         &notfoundbug;
952         &dlex("setbug => 0s");
953         return 0;
954     }
955
956     if (!&checkpkglimit) {
957         &cancelbug;
958         return 0;
959     }
960
961     @thisbugmergelist= split(/ /,$data->{mergedwith});
962     if (!@thisbugmergelist) {
963         &foundbug;
964         $manybugs= 0;
965         $state= 'single';
966         $sref=$ref;
967         &dlex("setbug => 1s");
968         return 1;
969     }
970     &cancelbug;
971     &getmerge;
972     $manybugs= 1;
973     if (!&getbug) {
974         &notfoundbug;
975         &endmerge;
976         &dlex("setbug => 0mc");
977         return 0;
978     }
979     &foundbug;
980     $state= 'multiple'; $sref=$ref;
981     &dlex("setbug => 1m");
982     return 1;
983 }
984
985 sub getnextbug {
986     &dlen("getnextbug");
987     $state eq 'single' || $state eq 'multiple' || die "$state ?";
988     &savebug;
989     if (!$manybugs || !@thisbugmergelist) {
990         length($action) || die;
991         &transcript("$action\n$extramessage\n");
992         &endmerge if $manybugs;
993         $state= 'idle';
994         &dlex("getnextbug => 0");
995         return 0;
996     }
997     $ref= shift(@thisbugmergelist);
998     &getbug || die "bug $ref disappeared";
999     &foundbug;
1000     &dlex("getnextbug => 1");
1001     return 1;
1002 }
1003
1004 # Low-level bug-manipulation calls
1005 # Do no announcements
1006 #
1007 #    getbug (returns 0)
1008 #
1009 #    getbug (returns 1)
1010 #    cancelbug
1011 #
1012 #    getmerge
1013 #    $action= (something)
1014 #    getbug (returns 1)
1015 #    savebug/cancelbug
1016 #    getbug (returns 1)
1017 #    savebug/cancelbug
1018 #    [getbug (returns 0)]
1019 #    &transcript("$action\n\n")
1020 #    endmerge
1021
1022 sub notfoundbug { &transcript("$gBug number $ref not found.\n\n"); }
1023 sub foundbug { &transcript("$gBug#$ref: $data->{subject}\n"); }
1024
1025 sub getmerge {
1026     &dlen("getmerge");
1027     $mergelowstate eq 'idle' || die "$mergelowstate ?";
1028     &filelock('lock/merge');
1029     $mergelowstate='locked';
1030     &dlex("getmerge");
1031 }
1032
1033 sub endmerge {
1034     &dlen("endmerge");
1035     $mergelowstate eq 'locked' || die "$mergelowstate ?";
1036     &unfilelock;
1037     $mergelowstate='idle';
1038     &dlex("endmerge");
1039 }
1040
1041 sub getbug {
1042     &dlen("getbug $ref");
1043     $lowstate eq 'idle' || die "$state ?";
1044     if (($data = &lockreadbug($ref))) {
1045         $sref= $ref;
1046         $lowstate= "open";
1047         &dlex("getbug => 1");
1048         $extramessage='';
1049         return 1;
1050     }
1051     $lowstate= 'idle';
1052     &dlex("getbug => 0");
1053     return 0;
1054 }
1055
1056 sub cancelbug {
1057     &dlen("cancelbug");
1058     $lowstate eq 'open' || die "$state ?";
1059     &unfilelock;
1060     $lowstate= 'idle';
1061     &dlex("cancelbug");
1062 }
1063
1064 sub savebug {
1065     &dlen("savebug $ref");
1066     $lowstate eq 'open' || die "$lowstate ?";
1067     length($action) || die;
1068     $ref == $sref || die "read $sref but saving $ref ?";
1069     my $hash = get_hashname($ref);
1070     open(L,">>db-h/$hash/$ref.log") || &quit("opening db-h/$hash/$ref.log: $!");
1071     print(L
1072           "\6\n".
1073           "<strong>".&sani($action)."</strong>\n".
1074           "Request was from <code>".&sani($header{'from'})."</code>\n".
1075           "to <code>".&sani($controlrequestaddr)."</code>. \n".
1076           "\3\n".
1077           "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/$hash/$ref.log: $!");
1078     close(L) || &quit("closing db-h/$hash/$ref.log: $!");
1079     unlockwritebug($ref, $data);
1080     $lowstate= "idle";
1081     &dlex("savebug");
1082 }
1083
1084 sub dlen {
1085     return if !$dl;
1086     &transcript("C> @_ ($state $lowstate $mergelowstate)\n");
1087 }
1088
1089 sub dlex {
1090     return if !$dl;
1091     &transcript("R> @_ ($state $lowstate $mergelowstate)\n");
1092 }
1093
1094 sub transcript {
1095     print $_[0] if $debug;
1096     $transcript.= $_[0];
1097 }
1098
1099 sub urlsanit {
1100     my $url = shift;
1101     $url =~ s/%/%25/g;
1102     $url =~ s/\+/%2b/g;
1103     my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
1104     $url =~ s/([<>&"])/\&$saniarray{$1};/g;
1105     return $url;
1106 }
1107
1108 sub sendlynxdoc {
1109     &sendlynxdocraw;
1110     &transcript("\n");
1111     $ok++;
1112 }
1113
1114 sub sendtxthelp {
1115     &sendtxthelpraw;
1116     &transcript("\n");
1117     $ok++;
1118 }
1119
1120 sub sendtxthelpraw {
1121     local ($relpath,$description) = @_;
1122     $doc='';
1123     open(D,"$gDocDir/$relpath") || &quit("open doc file $relpath: $!");
1124     while(<D>) { $doc.=$_; }
1125     close(D);
1126     &transcript("Sending $description in separate message.\n");
1127     &sendmailmessage(<<END.$doc,$replyto);
1128 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1129 To: $replyto
1130 Subject: $gProject $gBug help: $description
1131 References: $header{'message-id'}
1132 In-Reply-To: $header{'message-id'}
1133 Message-ID: <handler.s.$nn.help.$midix\@$gEmailDomain>
1134 Precedence: bulk
1135 X-$gProject-PR-Message: doc-text $relpath
1136
1137 END
1138     $ok++;
1139 }
1140
1141 sub sendlynxdocraw {
1142     local ($relpath,$description) = @_;
1143     $doc='';
1144     open(L,"lynx -nolist -dump http://$gCGIDomain/\Q$relpath\E 2>&1 |") || &quit("fork for lynx: $!");
1145     while(<L>) { $doc.=$_; }
1146     $!=0; close(L);
1147     if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1148         &transcript("Information ($description) is not available -\n".
1149                     "perhaps the $gBug does not exist or is not on the WWW yet.\n");
1150          $ok++;
1151     } elsif ($?) {
1152         &transcript("Error getting $description (code $? $!):\n$doc\n");
1153     } else {
1154         &transcript("Sending $description.\n");
1155         &sendmailmessage(<<END.$doc,$replyto);
1156 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1157 To: $replyto
1158 Subject: $gProject $gBugs information: $description
1159 References: $header{'message-id'}
1160 In-Reply-To: $header{'message-id'}
1161 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1162 Precedence: bulk
1163 X-$gProject-PR-Message: doc-html $relpath
1164
1165 END
1166          $ok++;
1167     }
1168 }
1169
1170 sub addccaddress {
1171     my ($cca) = @_;
1172     $maintccreasons{$cca}{''}{$ref}= 1;
1173 }
1174
1175 sub addmaintainers {
1176     # Data structure is:
1177     #   maintainer email address &c -> assoc of packages -> assoc of bug#'s
1178     my $data = shift;
1179     my ($p, $addmaint);
1180     &ensuremaintainersloaded;
1181     $anymaintfound=0; $anymaintnotfound=0;
1182     for $p (split(m/[ \t?,():]+/, $data->{package})) {
1183         $p =~ y/A-Z/a-z/;
1184         $p =~ /([a-z0-9.+-]+)/;
1185         $p = $1;
1186         next unless defined $p;
1187         if (defined $gSubscriptionDomain) {
1188             if (defined($pkgsrc{$p})) {
1189                 addbcc("$pkgsrc{$p}\@$gSubscriptionDomain");
1190             } else {
1191                 addbcc("$p\@$gSubscriptionDomain");
1192             }
1193         }
1194         if (defined $data->{severity} and defined $gStrongList and
1195                 isstrongseverity($data->{severity})) {
1196             addbcc("$gStrongList\@$gListDomain");
1197         }
1198         if (defined($maintainerof{$p})) {
1199             $addmaint= $maintainerof{$p};
1200             &transcript("MR|$addmaint|$p|$ref|\n") if $dl>2;
1201             $maintccreasons{$addmaint}{$p}{$ref}= 1;
1202             print "maintainer add >$p|$addmaint<\n" if $debug;
1203         } else { 
1204             print "maintainer none >$p<\n" if $debug; 
1205             &transcript("Warning: Unknown package '$p'\n");
1206             &transcript("MR|unknown-package|$p|$ref|\n") if $dl>2;
1207             $maintccreasons{$gUnknownMaintainerEmail}{$p}{$ref}= 1;
1208         }
1209     }
1210
1211     if (length $data->{owner}) {
1212         $addmaint = $data->{owner};
1213         &transcript("MO|$addmaint|$data->{package}|$ref|\n") if $dl>2;
1214         $maintccreasons{$addmaint}{$data->{package}}{$ref} = 1;
1215         print "owner add >$data->{package}|$addmaint<\n" if $debug;
1216     }
1217 }
1218
1219 sub ensuremaintainersloaded {
1220     my ($a,$b);
1221     return if $maintainersloaded++;
1222     open(MAINT,"$gMaintainerFile") || die &quit("maintainers open: $!");
1223     while (<MAINT>) {
1224         m/^\n$/ && next;
1225         m/^\s*$/ && next;
1226         m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers bogus \`$_'");
1227         $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
1228         $maintainerof{$1}= $2;
1229     }
1230     close(MAINT);
1231     open(MAINT,"$gMaintainerFileOverride") || die &quit("maintainers.override open: $!");
1232     while (<MAINT>) {
1233         m/^\n$/ && next;
1234         m/^\s*$/ && next;
1235         m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers.override bogus \`$_'");
1236         $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
1237         $maintainerof{$1}= $2;
1238     }
1239
1240     open(SOURCES, "$gPackageSource") || &quit("pkgsrc open: $!");
1241     while (<SOURCES>) {
1242         next unless m/^(\S+)\s+\S+\s+(\S.*\S)\s*$/;
1243         my ($a, $b) = ($1, $2);
1244         $pkgsrc{lc($a)} = $b;
1245     }
1246     close(SOURCES);
1247 }
1248
1249 sub sendinfo {
1250     local ($wherefrom,$path,$description) = @_;
1251     if ($wherefrom eq "ftp.d.o") {
1252       $doc = `lynx -nolist -dump http://ftp.debian.org/debian/indices/$path.gz 2>&1 | gunzip -cf` or &quit("fork for lynx/gunzip: $!");
1253       $! = 0;
1254       if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1255           &transcript("$description is not available.\n");
1256           $ok++; return;
1257       } elsif ($?) {
1258           &transcript("Error getting $description (code $? $!):\n$doc\n");
1259           return;
1260       }
1261     } elsif ($wherefrom eq "local") {
1262       open P, "$path";
1263       $doc = do { local $/; <P> };
1264       close P;
1265     } else {
1266       &transcript("internal errror: info files location unknown.\n");
1267       $ok++; return;
1268     }
1269     &transcript("Sending $description.\n");
1270     &sendmailmessage(<<END.$doc,$replyto);
1271 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1272 To: $replyto
1273 Subject: $gProject $gBugs information: $description
1274 References: $header{'message-id'}
1275 In-Reply-To: $header{'message-id'}
1276 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1277 Precedence: bulk
1278 X-$gProject-PR-Message: getinfo
1279
1280 $description follows:
1281
1282 END
1283     $ok++;
1284     &transcript("\n");
1285 }