]> git.donarmstrong.com Git - debbugs.git/blob - scripts/service.in
af361b0a23e528ebea358b75b2df2b96875395a4
[debbugs.git] / scripts / service.in
1 #!/usr/bin/perl
2 # $Id: service.in,v 1.108 2005/07/29 04:34:11 don 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/^submitter\s+\#?(-?\d+)\s+\!$/i ? ($newsubmitter=$replyto, 1) :
396              m/^submitter\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($newsubmitter=$2, 1) : 0) {
397         $ok++;
398         $ref= $1;
399         $bug_affected{$ref}=1;
400         if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
401             $ref = $clonebugs{$ref};
402         }
403         if (&getbug) {
404             if (&checkpkglimit) {
405                 &foundbug;
406                 &addmaintainers($data);
407                 $oldsubmitter= $data->{originator};
408                 $data->{originator}= $newsubmitter;
409                 $action= "Changed $gBug submitter from $oldsubmitter to $newsubmitter.";
410                 &savebug;
411                 &transcript("$action\n");
412                 if (length($data->{done})) {
413                     &transcript("(By the way, that $gBug is currently marked as done.)\n");
414                 }
415                 &transcript("\n");
416                 $message= <<END;
417 From: $gMaintainerEmail ($gProject $gBug Tracking System)
418 To: $oldsubmitter
419 Subject: $gBug#$ref submitter address changed
420          ($header{'subject'})
421 References: $header{'message-id'} $data->{msgid}
422 In-Reply-To: $data->{msgid}
423 Message-ID: <handler.$ref.$nn.newsubmitter.$midix\@$gEmailDomain>
424 Reply-To: $ref\@$gEmailDomain
425 X-$gProject-PR-Message: submitter-changed $ref
426
427 The submitter address recorded for your $gBug report
428 #$ref: $data->{subject}
429 has been changed.
430
431 The new submitter address for this report is
432 $newsubmitter.
433
434 This change was made by
435 $replyto.
436 If it was incorrect, please contact them directly.
437
438 $gMaintainer
439 (administrator, $gProject $gBugs database)
440
441 END
442                 &sendmailmessage($message,$oldsubmitter);
443             } else {
444                 &cancelbug;
445             }
446         } else {
447             &notfoundbug;
448         }
449     } elsif (m/^forwarded\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
450         $ok++;
451         $ref= $1; $whereto= $2;
452         $bug_affected{$ref}=1;
453         if (&setbug) {
454             if (length($data->{forwarded})) {
455     $action= "Forwarded-to-address changed from $data->{forwarded} to $whereto.";
456             } else {
457     $action= "Noted your statement that $gBug has been forwarded to $whereto.";
458             }
459             if (length($data->{done})) {
460                 $extramessage= "(By the way, this $gBug is currently marked as done.)\n";
461             }
462             do {
463                 &addmaintainers($data);
464                 if (length($gForwardList)>0 && length($gListDomain)>0 ) {
465                      &addccaddress("$gForwardList\@$gListDomain"); 
466                 }
467                 $data->{forwarded}= $whereto;
468             } while (&getnextbug);
469         }
470     } elsif (m/^notforwarded\s+\#?(-?\d+)$/i) {
471         $ok++;
472         $ref= $1;
473         $bug_affected{$ref}=1;
474         if (&setbug) {
475             if (!length($data->{forwarded})) {
476                 &transcript("$gBug is not marked as having been forwarded.\n\n");
477                 &nochangebug;
478             } else {
479     $action= "Removed annotation that $gBug had been forwarded to $data->{forwarded}.";
480                 do {
481                     &addmaintainers($data);
482                     $data->{forwarded}= '';
483                 } while (&getnextbug);
484             }
485         }
486     } elsif (m/^severity\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i ||
487         m/^priority\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i) {
488         $ok++;
489         $ref= $1;
490         $bug_affected{$ref}=1;
491         $newseverity= $2;
492         if (!grep($_ eq $newseverity, @gSeverityList, "$gDefaultSeverity")) {
493             &transcript("Severity level \`$newseverity' is not known.\n".
494                         "Recognized are: $gShowSeverities.\n\n");
495         } elsif (exists $gObsoleteSeverities{$newseverity}) {
496             &transcript("Severity level \`$newseverity' is obsolete. " .
497                         "$gObsoleteSeverities{$newseverity}\n\n");
498         } elsif (&setbug) {
499             $printseverity= $data->{severity};
500             $printseverity= "$gDefaultSeverity" if $printseverity eq '';
501             $action= "Severity set to \`$newseverity' from \`$printseverity'";
502             do {
503                 &addmaintainers($data);
504                 if (defined $gStrongList and isstrongseverity($newseverity)) {
505                     addbcc("$gStrongList\@$gListDomain");
506                 }
507                 $data->{severity}= $newseverity;
508             } while (&getnextbug);
509         }
510     } elsif (m/^tags?\s+\#?(-?\d+)\s+(([=+-])\s*)?(\S.*)?$/i) {
511         $ok++;
512         $ref = $1; $addsubcode = $3; $tags = $4;
513         $bug_affected{$ref}=1;
514         $addsub = "add";
515         if (defined $addsubcode) {
516             $addsub = "sub" if ($addsubcode eq "-");
517             $addsub = "add" if ($addsubcode eq "+");
518             $addsub = "set" if ($addsubcode eq "=");
519         }
520         my @okaytags = ();
521         my @badtags = ();
522         foreach my $t (split /[\s,]+/, $tags) {
523             if (!grep($_ eq $t, @gTags)) {
524                 push @badtags, $t;
525             } else {
526                 push @okaytags, $t;
527             }
528         }
529         if (@badtags) {
530             &transcript("Unknown tag/s: ".join(', ', @badtags).".\n".
531                         "Recognized are: ".join(' ', @gTags).".\n\n");
532         }
533         if (&setbug) {
534             if ($data->{keywords} eq '') {
535                 &transcript("There were no tags set.\n");
536             } else {
537                 &transcript("Tags were: $data->{keywords}\n");
538             }
539             if ($addsub eq "set") {
540                 $action= "Tags set to: " . join(", ", @okaytags);
541             } elsif ($addsub eq "add") {
542                 $action= "Tags added: " . join(", ", @okaytags);
543             } elsif ($addsub eq "sub") {
544                 $action= "Tags removed: " . join(", ", @okaytags);
545             }
546             do {
547                 &addmaintainers($data);
548                 $data->{keywords} = '' if ($addsub eq "set");
549                 # Allow removing obsolete tags.
550                 if ($addsub eq "sub") {
551                     foreach my $t (@badtags) {
552                         $data->{keywords} = join ' ', grep $_ ne $t, 
553                             split ' ', $data->{keywords};
554                     }
555                 }
556                 # Now process all other additions and subtractions.
557                 foreach my $t (@okaytags) {
558                     $data->{keywords} = join ' ', grep $_ ne $t, 
559                         split ' ', $data->{keywords};
560                     $data->{keywords} = "$t $data->{keywords}" unless($addsub eq "sub");
561                 }
562                 $data->{keywords} =~ s/\s*$//;
563             } while (&getnextbug);
564         }
565     } elsif (m/^retitle\s+\#?(-?\d+)\s+(\S.*\S)\s*$/i) {
566         $ok++;
567         $ref= $1; $newtitle= $2;
568         $bug_affected{$ref}=1;
569         if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
570             $ref = $clonebugs{$ref};
571         }
572         if (&getbug) {
573             if (&checkpkglimit) {
574                 &foundbug;
575                 &addmaintainers($data);
576                 $data->{subject}= $newtitle;
577                 $action= "Changed $gBug title.";
578                 &savebug;
579                 &transcript("$action\n");
580                 if (length($data->{done})) {
581                     &transcript("(By the way, that $gBug is currently marked as done.)\n");
582                 }
583                 &transcript("\n");
584             } else {
585                 &cancelbug;
586             }
587         } else {
588             &notfoundbug;
589         }
590     } elsif (m/^unmerge\s+\#?(-?\d+)$/i) {
591         $ok++;
592         $ref= $1;
593         $bug_affected{$ref} = 1;
594         if (&setbug) {
595             if (!length($data->{mergedwith})) {
596                 &transcript("$gBug is not marked as being merged with any others.\n\n");
597                 &nochangebug;
598             } else {
599                 $mergelowstate eq 'locked' || die "$mergelowstate ?";
600                 $action= "Disconnected #$ref from all other report(s).";
601                 @newmergelist= split(/ /,$data->{mergedwith});
602                 $discref= $ref;
603                 @bug_affected{@newmergelist} = 1 x @newmergelist;
604                 do {
605                     &addmaintainers($data);
606                     $data->{mergedwith}= ($ref == $discref) ? ''
607                         : join(' ',grep($_ ne $ref,@newmergelist));
608                 } while (&getnextbug);
609             }
610         }
611     } elsif (m/^merge\s+#?(-?\d+(\s+#?-?\d+)+)\s*$/i) {
612         $ok++;
613         @tomerge= sort { $a <=> $b } split(/\s+#?/,$1);
614         @newmergelist= ();
615         my %tags = ();
616         my %found = ();
617         my %fixed = ();
618         &getmerge;
619         while (defined($ref= shift(@tomerge))) {
620             &transcript("D| checking merge $ref\n") if $dl;
621             $ref+= 0;
622             if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
623                 $ref = $clonebugs{$ref};
624             }
625             next if grep($_ eq $ref,@newmergelist);
626             if (!&getbug) { &notfoundbug; @newmergelist=(); last }
627             if (!&checkpkglimit) { &cancelbug; @newmergelist=(); last; }
628             &foundbug;
629             &transcript("D| adding $ref ($data->{mergedwith})\n") if $dl;
630             $mismatch= '';
631             &checkmatch('package','m_package',$data->{package});
632             &checkmatch('forwarded addr','m_forwarded',$data->{forwarded});
633             $data->{severity} = '$gDefaultSeverity' if $data->{severity} eq '';
634             &checkmatch('severity','m_severity',$data->{severity});
635             &checkmatch('done mark','m_done',length($data->{done}) ? 'done' : 'open');
636             &checkmatch('owner','m_owner',$data->{owner});
637             foreach my $t (split /\s+/, $data->{keywords}) { $tags{$t} = 1; }
638             foreach my $f (@{$data->{found_versions}}) { $found{$f} = 1; }
639             foreach my $f (@{$data->{fixed_versions}}) { $fixed{$f} = 1; }
640             if (length($mismatch)) {
641                 &transcript("Mismatch - only $gBugs in same state can be merged:\n".
642                             $mismatch."\n");
643                 &cancelbug; @newmergelist=(); last;
644             }
645             push(@newmergelist,$ref);
646             push(@tomerge,split(/ /,$data->{mergedwith}));
647             &cancelbug;
648         }
649         if (@newmergelist) {
650             @newmergelist= sort { $a <=> $b } @newmergelist;
651             $action= "Merged @newmergelist.";
652             delete @fixed{keys %found};
653             for $ref (@newmergelist) {
654                 &getbug || die "huh ?  $gBug $ref disappeared during merge";
655                 &addmaintainers($data);
656                 @bug_affected{@newmergelist} = 1 x @newmergelist;
657                 $data->{mergedwith}= join(' ',grep($_ ne $ref,@newmergelist));
658                 $data->{keywords}= join(' ', keys %tags);
659                 $data->{found_versions}= [sort keys %found];
660                 $data->{fixed_versions}= [sort keys %fixed];
661                 &savebug;
662             }
663             &transcript("$action\n\n");
664         }
665         &endmerge;
666     } elsif (m/^clone\s+#?(\d+)\s+((-\d+\s+)*-\d+)\s*$/i) {
667         $ok++;
668
669         $origref = $1;
670         @newclonedids = split /\s+/, $2;
671         $newbugsneeded = scalar(@newclonedids);
672
673         $ref = $origref;
674         $bug_affected{$ref} = 1;
675         if (&setbug) {
676             if (length($data->{mergedwith})) {
677                 &transcript("$gBug is marked as being merged with others.\n\n");
678                 &nochangebug;
679             } else {
680                 &filelock("nextnumber.lock");
681                 open(N,"nextnumber") || &quit("nextnumber: read: $!");
682                 $v=<N>; $v =~ s/\n$// || &quit("nextnumber bad format");
683                 $firstref= $v+0;  $v += $newbugsneeded;
684                 open(NN,">nextnumber"); print NN "$v\n"; close(NN);
685                 &unfilelock;
686
687                 $lastref = $firstref + $newbugsneeded - 1;
688
689                 if ($newbugsneeded == 1) {
690                     $action= "$gBug $origref cloned as bug $firstref.";
691                 } else {
692                     $action= "$gBug $origref cloned as bugs $firstref-$lastref.";
693                 }
694                 &getnextbug;
695                 my $ohash = get_hashname($origref);
696                 $ref = $firstref;
697                 @bug_affected{@newclonedids} = 1 x @newclonedids;
698                 for $newclonedid (@newclonedids) {
699                     $clonebugs{$newclonedid} = $ref;
700             
701                     my $hash = get_hashname($ref);
702                     copy("db-h/$ohash/$origref.log", "db-h/$hash/$ref.log");
703                     copy("db-h/$ohash/$origref.status", "db-h/$hash/$ref.status");
704                     copy("db-h/$ohash/$origref.summary", "db-h/$hash/$ref.summary");
705                     copy("db-h/$ohash/$origref.report", "db-h/$hash/$ref.report");
706                     &bughook('new', $ref, $data);
707
708                     $ref++;
709                 }
710             }
711         }
712     } elsif (m/^package\s+(\S.*\S)?\s*$/i) {
713         $ok++;
714         my @pkgs = split /\s+/, $1;
715         if (scalar(@pkgs) > 0) {
716                 %limit_pkgs = map { ($_, 1) } @pkgs;
717                 &transcript("Ignoring bugs not assigned to: " . 
718                         join(" ", keys(%limit_pkgs)) . "\n\n");
719         } else {
720                 %limit_pkgs = ();
721                 &transcript("Not ignoring any bugs.\n\n");
722         }
723     } elsif (m/^owner\s+\#?(-?\d+)\s+!$/i ? ($newowner = $replyto, 1) :
724              m/^owner\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($newowner = $2, 1) : 0) {
725         $ok++;
726         $ref = $1;
727         $bug_affected{$ref} = 1;
728         if (&setbug) {
729             if (length $data->{owner}) {
730                 $action = "Owner changed from $data->{owner} to $newowner.";
731             } else {
732                 $action = "Owner recorded as $newowner.";
733             }
734             if (length $data->{done}) {
735                 $extramessage = "(By the way, this $gBug is currently " .
736                                 "marked as done.)\n";
737             }
738             do {
739                 &addmaintainers($data);
740                 $data->{owner} = $newowner;
741             } while (&getnextbug);
742         }
743     } elsif (m/^noowner\s+\#?(-?\d+)$/i) {
744         $ok++;
745         $ref = $1;
746         $bug_affected{$ref} = 1;
747         if (&setbug) {
748             if (length $data->{owner}) {
749                 $action = "Removed annotation that $gBug was owned by " .
750                           "$data->{owner}.";
751                 do {
752                     &addmaintainers($data);
753                     $data->{owner} = '';
754                 } while (&getnextbug);
755             } else {
756                 &transcript("$gBug is not marked as having an owner.\n\n");
757                 &nochangebug;
758             }
759         }
760     } else {
761         &transcript("Unknown command or malformed arguments to command.\n\n");
762         if (++$unknowns >= 5) {
763             &transcript("Too many unknown commands, stopping here.\n\n");
764             last;
765         }
766     }
767 }
768 if ($procline>$#bodylines) {
769     &transcript(">\nEnd of message, stopping processing here.\n\n");
770 }
771 if (!$ok && !quickabort) {
772     &transcript("No commands successfully parsed; sending the help text(s).\n");
773     &sendhelp;
774     &transcript("\n");
775 }
776
777 &transcript("MC\n") if $dl>1;
778 @maintccs= ();
779 for $maint (keys %maintccreasons) {
780 &transcript("MM|$maint|\n") if $dl>1;
781     next if $maint eq $replyto;
782     $reasonstring= '';
783     $reasonsref= $maintccreasons{$maint};
784 &transcript("MY|$maint|\n") if $dl>2;
785     for $p (sort keys %$reasonsref) {
786 &transcript("MP|$p|\n") if $dl>2;
787         $reasonstring.= ', ' if length($reasonstring);
788         $reasonstring.= $p.' ' if length($p);
789         $reasonstring.= join(' ',map("#$_",sort keys %{$$reasonsref{$p}}));
790     }
791     if (length($reasonstring) > 40) {
792         (substr $reasonstring, 37) = "...";
793     }
794     $reasonstring = "" if (!defined($reasonstring));
795     push(@maintccs,"$maint ($reasonstring)");
796     push(@maintccaddrs,"$maint");
797 }
798
799 $maintccs = ""; 
800 if (@maintccs) {
801     &transcript("MC|@maintccs|\n") if $dl>2;
802     $maintccs .= "Cc: " . join(",\n    ",@maintccs) . "\n";
803 }
804
805 # Add Bcc's to subscribed bugs
806 push @bcc, map {"bugs=$_\@$gListDomain"} keys %bug_affected;
807
808 if (!defined $header{'subject'} || $header{'subject'} eq "") {
809   $header{'subject'} = "your mail";
810 }
811
812 $reply= <<END;
813 From: $gMaintainerEmail ($gProject $gBug Tracking System)
814 To: $replyto
815 ${maintccs}Subject: Processed: $header{'subject'}
816 In-Reply-To: $header{'message-id'}
817 References: $header{'message-id'}
818 Message-ID: <handler.s.$nn.transcript\@$gEmailDomain>
819 Precedence: bulk
820 X-$gProject-PR-Message: transcript
821
822 ${transcript}Please contact me if you need assistance.
823
824 $gMaintainer
825 (administrator, $gProject $gBugs database)
826 $extras
827 END
828
829 $repliedshow= join(', ',$replyto,@maintccaddrs);
830 &filelock("lock/-1");
831 open(AP,">>db-h/-1.log") || &quit("open db-h/-1.log: $!");
832 print(AP
833       "\2\n$repliedshow\n\5\n$reply\n\3\n".
834       "\6\n".
835       "<strong>Request received</strong> from <code>".
836       &sani($header{'from'})."</code>\n".
837       "to <code>".&sani($controlrequestaddr)."</code>\n".
838       "\3\n".
839       "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/-1.log: $!");
840 close(AP) || &quit("open db-h/-1.log: $!");
841 &unfilelock;
842 utime(time,time,"db-h");
843
844 &sendmailmessage($reply,$replyto,@maintccaddrs,@bcc);
845
846 unlink("incoming/P$nn") || &quit("unlinking incoming/P$nn: $!");
847
848 sub sendmailmessage {
849     local ($message,@recips) = @_;
850     $message = "X-Loop: $gMaintainerEmail\n" . $message;
851     print "mailing to >@recips<\n" if $debug;
852     $c= open(D,"|-");
853     defined($c) || &quit("mailing forking for sendmail: $!");
854     if (!$c) { # ie, we are the child process
855         exec '/usr/lib/sendmail','-f'."$gMaintainerEmail",'-odb','-oem','-oi',get_addresses(@recips);
856         die $!;
857     }
858     print(D $message) || &quit("writing to sendmail process: $!");
859     $!=0; close(D); $? && &quit("sendmail gave exit status $? ($!)");
860     $midix++;
861 }
862
863 sub sendhelp {
864         &sendtxthelpraw("bug-log-mailserver.txt","instructions for request\@$gEmailDomain");
865         &sendtxthelpraw("bug-maint-mailcontrol.txt","instructions for control\@$gEmailDomain")
866             if $control;
867 }
868
869 #sub unimplemented {
870 #    &transcript("Sorry, command $_[0] not yet implemented.\n\n");
871 #}
872
873 sub checkmatch {
874     local ($string,$mvarname,$svarvalue) = @_;
875     local ($mvarvalue);
876     if (@newmergelist) {
877         eval "\$mvarvalue= \$$mvarname";
878         &transcript("D| checkmatch \`$string' /$mvarname/$mvarvalue/$svarvalue/\n")
879             if $dl;
880         $mismatch .=
881             "Values for \`$string' don't match:\n".
882             " #$newmergelist[0] has \`$mvarvalue';\n".
883             " #$ref has \`$svarvalue'\n"
884             if $mvarvalue ne $svarvalue;
885     } else {
886         &transcript("D| setupmatch \`$string' /$mvarname/$svarvalue/\n")
887             if $dl;
888         eval "\$$mvarname= \$svarvalue";
889     }
890 }
891
892 sub checkpkglimit {
893     if (keys %limit_pkgs and not defined $limit_pkgs{$data->{package}}) {
894         &transcript("$gBug number $ref belongs to package $data->{package}, skipping.\n\n");
895         return 0;
896     }
897     return 1;
898 }
899
900 # High-level bug manipulation calls
901 # Do announcements themselves
902 #
903 # Possible calling sequences:
904 #    setbug (returns 0)
905 #    
906 #    setbug (returns 1)
907 #    &transcript(something)
908 #    nochangebug
909 #
910 #    setbug (returns 1)
911 #    $action= (something)
912 #    do {
913 #      (modify s_* variables)
914 #    } while (getnextbug);
915
916 sub nochangebug {
917     &dlen("nochangebug");
918     $state eq 'single' || $state eq 'multiple' || die "$state ?";
919     &cancelbug;
920     &endmerge if $manybugs;
921     $state= 'idle';
922     &dlex("nochangebug");
923 }
924
925 sub setbug {
926     &dlen("setbug $ref");
927     if ($ref =~ m/^-\d+/) {
928         if (!defined $clonebugs{$ref}) {
929             &notfoundbug;
930             &dlex("setbug => noclone");
931             return 0;
932         }
933         $ref = $clonebugs{$ref};
934     }
935     $state eq 'idle' || die "$state ?";
936     if (!&getbug) {
937         &notfoundbug;
938         &dlex("setbug => 0s");
939         return 0;
940     }
941
942     if (!&checkpkglimit) {
943         &cancelbug;
944         return 0;
945     }
946
947     @thisbugmergelist= split(/ /,$data->{mergedwith});
948     if (!@thisbugmergelist) {
949         &foundbug;
950         $manybugs= 0;
951         $state= 'single';
952         $sref=$ref;
953         &dlex("setbug => 1s");
954         return 1;
955     }
956     &cancelbug;
957     &getmerge;
958     $manybugs= 1;
959     if (!&getbug) {
960         &notfoundbug;
961         &endmerge;
962         &dlex("setbug => 0mc");
963         return 0;
964     }
965     &foundbug;
966     $state= 'multiple'; $sref=$ref;
967     &dlex("setbug => 1m");
968     return 1;
969 }
970
971 sub getnextbug {
972     &dlen("getnextbug");
973     $state eq 'single' || $state eq 'multiple' || die "$state ?";
974     &savebug;
975     if (!$manybugs || !@thisbugmergelist) {
976         length($action) || die;
977         &transcript("$action\n$extramessage\n");
978         &endmerge if $manybugs;
979         $state= 'idle';
980         &dlex("getnextbug => 0");
981         return 0;
982     }
983     $ref= shift(@thisbugmergelist);
984     &getbug || die "bug $ref disappeared";
985     &foundbug;
986     &dlex("getnextbug => 1");
987     return 1;
988 }
989
990 # Low-level bug-manipulation calls
991 # Do no announcements
992 #
993 #    getbug (returns 0)
994 #
995 #    getbug (returns 1)
996 #    cancelbug
997 #
998 #    getmerge
999 #    $action= (something)
1000 #    getbug (returns 1)
1001 #    savebug/cancelbug
1002 #    getbug (returns 1)
1003 #    savebug/cancelbug
1004 #    [getbug (returns 0)]
1005 #    &transcript("$action\n\n")
1006 #    endmerge
1007
1008 sub notfoundbug { &transcript("$gBug number $ref not found.\n\n"); }
1009 sub foundbug { &transcript("$gBug#$ref: $data->{subject}\n"); }
1010
1011 sub getmerge {
1012     &dlen("getmerge");
1013     $mergelowstate eq 'idle' || die "$mergelowstate ?";
1014     &filelock('lock/merge');
1015     $mergelowstate='locked';
1016     &dlex("getmerge");
1017 }
1018
1019 sub endmerge {
1020     &dlen("endmerge");
1021     $mergelowstate eq 'locked' || die "$mergelowstate ?";
1022     &unfilelock;
1023     $mergelowstate='idle';
1024     &dlex("endmerge");
1025 }
1026
1027 sub getbug {
1028     &dlen("getbug $ref");
1029     $lowstate eq 'idle' || die "$state ?";
1030     if (($data = &lockreadbug($ref))) {
1031         $sref= $ref;
1032         $lowstate= "open";
1033         &dlex("getbug => 1");
1034         $extramessage='';
1035         return 1;
1036     }
1037     $lowstate= 'idle';
1038     &dlex("getbug => 0");
1039     return 0;
1040 }
1041
1042 sub cancelbug {
1043     &dlen("cancelbug");
1044     $lowstate eq 'open' || die "$state ?";
1045     &unfilelock;
1046     $lowstate= 'idle';
1047     &dlex("cancelbug");
1048 }
1049
1050 sub savebug {
1051     &dlen("savebug $ref");
1052     $lowstate eq 'open' || die "$lowstate ?";
1053     length($action) || die;
1054     $ref == $sref || die "read $sref but saving $ref ?";
1055     my $hash = get_hashname($ref);
1056     open(L,">>db-h/$hash/$ref.log") || &quit("opening db-h/$hash/$ref.log: $!");
1057     print(L
1058           "\6\n".
1059           "<strong>".&sani($action)."</strong>\n".
1060           "Request was from <code>".&sani($header{'from'})."</code>\n".
1061           "to <code>".&sani($controlrequestaddr)."</code>. \n".
1062           "\3\n".
1063           "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/$hash/$ref.log: $!");
1064     close(L) || &quit("closing db-h/$hash/$ref.log: $!");
1065     unlockwritebug($ref, $data);
1066     $lowstate= "idle";
1067     &dlex("savebug");
1068 }
1069
1070 sub dlen {
1071     return if !$dl;
1072     &transcript("C> @_ ($state $lowstate $mergelowstate)\n");
1073 }
1074
1075 sub dlex {
1076     return if !$dl;
1077     &transcript("R> @_ ($state $lowstate $mergelowstate)\n");
1078 }
1079
1080 sub transcript {
1081     print $_[0] if $debug;
1082     $transcript.= $_[0];
1083 }
1084
1085 sub urlsanit {
1086     my $url = shift;
1087     $url =~ s/%/%25/g;
1088     $url =~ s/\+/%2b/g;
1089     my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
1090     $url =~ s/([<>&"])/\&$saniarray{$1};/g;
1091     return $url;
1092 }
1093
1094 sub sendlynxdoc {
1095     &sendlynxdocraw;
1096     &transcript("\n");
1097     $ok++;
1098 }
1099
1100 sub sendtxthelp {
1101     &sendtxthelpraw;
1102     &transcript("\n");
1103     $ok++;
1104 }
1105
1106 sub sendtxthelpraw {
1107     local ($relpath,$description) = @_;
1108     $doc='';
1109     open(D,"$gDocDir/$relpath") || &quit("open doc file $relpath: $!");
1110     while(<D>) { $doc.=$_; }
1111     close(D);
1112     &transcript("Sending $description in separate message.\n");
1113     &sendmailmessage(<<END.$doc,$replyto);
1114 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1115 To: $replyto
1116 Subject: $gProject $gBug help: $description
1117 References: $header{'message-id'}
1118 In-Reply-To: $header{'message-id'}
1119 Message-ID: <handler.s.$nn.help.$midix\@$gEmailDomain>
1120 Precedence: bulk
1121 X-$gProject-PR-Message: doc-text $relpath
1122
1123 END
1124     $ok++;
1125 }
1126
1127 sub sendlynxdocraw {
1128     local ($relpath,$description) = @_;
1129     $doc='';
1130     open(L,"lynx -nolist -dump http://$gCGIDomain/\Q$relpath\E 2>&1 |") || &quit("fork for lynx: $!");
1131     while(<L>) { $doc.=$_; }
1132     $!=0; close(L);
1133     if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1134         &transcript("Information ($description) is not available -\n".
1135                     "perhaps the $gBug does not exist or is not on the WWW yet.\n");
1136          $ok++;
1137     } elsif ($?) {
1138         &transcript("Error getting $description (code $? $!):\n$doc\n");
1139     } else {
1140         &transcript("Sending $description.\n");
1141         &sendmailmessage(<<END.$doc,$replyto);
1142 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1143 To: $replyto
1144 Subject: $gProject $gBugs information: $description
1145 References: $header{'message-id'}
1146 In-Reply-To: $header{'message-id'}
1147 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1148 Precedence: bulk
1149 X-$gProject-PR-Message: doc-html $relpath
1150
1151 END
1152          $ok++;
1153     }
1154 }
1155
1156 sub addccaddress {
1157     my ($cca) = @_;
1158     $maintccreasons{$cca}{''}{$ref}= 1;
1159 }
1160
1161 sub addmaintainers {
1162     # Data structure is:
1163     #   maintainer email address &c -> assoc of packages -> assoc of bug#'s
1164     my $data = shift;
1165     my ($p, $addmaint);
1166     &ensuremaintainersloaded;
1167     $anymaintfound=0; $anymaintnotfound=0;
1168     for $p (split(m/[ \t?,():]+/, $data->{package})) {
1169         $p =~ y/A-Z/a-z/;
1170         $p =~ /([a-z0-9.+-]+)/;
1171         $p = $1;
1172         next unless defined $p;
1173         if (defined $gSubscriptionDomain) {
1174             if (defined($pkgsrc{$p})) {
1175                 addbcc("$pkgsrc{$p}\@$gSubscriptionDomain");
1176             } else {
1177                 addbcc("$p\@$gSubscriptionDomain");
1178             }
1179         }
1180         if (defined $data->{severity} and defined $gStrongList and
1181                 isstrongseverity($data->{severity})) {
1182             addbcc("$gStrongList\@$gListDomain");
1183         }
1184         if (defined($maintainerof{$p})) {
1185             $addmaint= $maintainerof{$p};
1186             &transcript("MR|$addmaint|$p|$ref|\n") if $dl>2;
1187             $maintccreasons{$addmaint}{$p}{$ref}= 1;
1188             print "maintainer add >$p|$addmaint<\n" if $debug;
1189         } else { 
1190             print "maintainer none >$p<\n" if $debug; 
1191             &transcript("Warning: Unknown package '$p'\n");
1192             &transcript("MR|unknown-package|$p|$ref|\n") if $dl>2;
1193             $maintccreasons{$gUnknownMaintainerEmail}{$p}{$ref}= 1;
1194         }
1195     }
1196
1197     if (length $data->{owner}) {
1198         $addmaint = $data->{owner};
1199         &transcript("MO|$addmaint|$data->{package}|$ref|\n") if $dl>2;
1200         $maintccreasons{$addmaint}{$data->{package}}{$ref} = 1;
1201         print "owner add >$data->{package}|$addmaint<\n" if $debug;
1202     }
1203 }
1204
1205 sub ensuremaintainersloaded {
1206     my ($a,$b);
1207     return if $maintainersloaded++;
1208     open(MAINT,"$gMaintainerFile") || die &quit("maintainers open: $!");
1209     while (<MAINT>) {
1210         m/^\n$/ && next;
1211         m/^\s*$/ && next;
1212         m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers bogus \`$_'");
1213         $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
1214         $maintainerof{$1}= $2;
1215     }
1216     close(MAINT);
1217     open(MAINT,"$gMaintainerFileOverride") || die &quit("maintainers.override open: $!");
1218     while (<MAINT>) {
1219         m/^\n$/ && next;
1220         m/^\s*$/ && next;
1221         m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers.override bogus \`$_'");
1222         $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
1223         $maintainerof{$1}= $2;
1224     }
1225
1226     open(SOURCES, "$gPackageSource") || &quit("pkgsrc open: $!");
1227     while (<SOURCES>) {
1228         next unless m/^(\S+)\s+\S+\s+(\S.*\S)\s*$/;
1229         my ($a, $b) = ($1, $2);
1230         $pkgsrc{lc($a)} = $b;
1231     }
1232     close(SOURCES);
1233 }
1234
1235 sub sendinfo {
1236     local ($wherefrom,$path,$description) = @_;
1237     if ($wherefrom eq "ftp.d.o") {
1238       $doc = `lynx -nolist -dump http://ftp.debian.org/debian/indices/$path.gz 2>&1 | gunzip -cf` or &quit("fork for lynx/gunzip: $!");
1239       $! = 0;
1240       if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
1241           &transcript("$description is not available.\n");
1242           $ok++; return;
1243       } elsif ($?) {
1244           &transcript("Error getting $description (code $? $!):\n$doc\n");
1245           return;
1246       }
1247     } elsif ($wherefrom eq "local") {
1248       open P, "$path";
1249       $doc = do { local $/; <P> };
1250       close P;
1251     } else {
1252       &transcript("internal errror: info files location unknown.\n");
1253       $ok++; return;
1254     }
1255     &transcript("Sending $description.\n");
1256     &sendmailmessage(<<END.$doc,$replyto);
1257 From: $gMaintainerEmail ($gProject $gBug Tracking System)
1258 To: $replyto
1259 Subject: $gProject $gBugs information: $description
1260 References: $header{'message-id'}
1261 In-Reply-To: $header{'message-id'}
1262 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
1263 Precedence: bulk
1264 X-$gProject-PR-Message: getinfo
1265
1266 $description follows:
1267
1268 END
1269     $ok++;
1270     &transcript("\n");
1271 }