]> git.donarmstrong.com Git - debbugs.git/blobdiff - scripts/service.in
[project @ 2002-10-06 22:54:48 by cjwatson]
[debbugs.git] / scripts / service.in
index 0316c78a754e48dff4d0e6c9ca76de4c6d8069e4..66a2b5e0c668318af84efa4a58d53b04b6232902 100755 (executable)
@@ -1,20 +1,27 @@
 #!/usr/bin/perl
-# $Id: service.in,v 1.2 1999/09/02 22:27:29 gecko Exp $
+# $Id: service.in,v 1.54 2002/10/06 22:54:48 cjwatson Exp $
+# ^ more or less ^
 #
 # Usage: service <code>.nn
 # Temps:  incoming/P<code>.nn
 
 use Mail::Address;
-require('/etc/debbugs/config');
-require('/usr/lib/debbugs/errorlib');
-$ENV{'PATH'}= '/usr/lib/debbugs'.$ENV{'PATH'};;
-chdir("$gSpoolDir") || die "chdir spool: $!\n";
+use File::Copy;
+use MIME::Parser;
 
-# open(DEBUG,">&4");
+$config_path = '/org/bugs.debian.org/etc';
+$lib_path = '/org/bugs.debian.org/scripts';
+
+require "$config_path/config";
+require "$lib_path/errorlib";
+$ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
 
-$wwwbase= "$gWebDir";
+chdir("$gSpoolDir") || die "chdir spool: $!\n";
 
-# defined($intdate= time) || &quit("failed to get time: $!");
+# open(DEBUG,">&4");
+open DEBUG, ">/dev/null";
+$debug = 0;
+umask(002);
 
 $_=shift;
 m/^[RC]\.\d+$/ || &quit("bad argument");
@@ -30,36 +37,71 @@ open(M,"incoming/P$nn");
 @msg=@log;
 close(M);
 
-grep((s/\n$//,s/\s+$//),@msg);
+chomp @msg;
 
-print DEBUG "###\n",join("##\n",@msg),"\n###\n";
+print "###\n",join("##\n",@msg),"\n###\n" if $debug;
 
-chop($tdate= `date -u '+%a, %d %h 19%y %T GMT'`);
-$fwd= <<END;
-Received: via spool for service; $tdate
-END
+my $parser = new MIME::Parser;
+mkdir "$gSpoolDir/mime.tmp", 0777;
+$parser->output_under("$gSpoolDir/mime.tmp");
+my $entity = eval { $parser->parse_data(join('',@log)) };
 
-for ($i=0; $i<=$#msg; $i++) {
-    $_ = $msg[$i];
-    last unless length($_);
-    $fwd .= $_."\n";
-    while ($msg[$i+1] =~ m/^\s/) {
-        $i++;
-        $fwd .= $msg[$i]."\n" if $ins; # Huh ? Where is ins set ?
-        $_ .= ' '.$msg[$i];
+# header and decoded body respectively
+my (@headerlines, @bodylines);
+
+if ($entity and $entity->head->tags) {
+    @headerlines = @{$entity->head->header};
+    chomp @headerlines;
+
+    my $entity_body = getmailbody($entity);
+    @bodylines = $entity_body ? $entity_body->as_lines() : ();
+    chomp @bodylines;
+} else {
+    # Legacy pre-MIME code, kept around in case MIME::Parser fails.
+    my $i;
+    for ($i = 0; $i <= $#msg; $i++) {
+       $_ = $msg[$i];
+       last unless length($_);
+       while ($msg[$i+1] =~ m/^\s/) {
+           $i++;
+           $_ .= "\n".$msg[$i];
+       }
+       push @headerlines, $_;
     }
-# print DEBUG ">$_<\n";
+
+    @bodylines = @msg[$i..$#msg];
+}
+
+for (@headerlines) {
+    s/\n\s/ /g;
+    print ">$_<\n" if $debug;
     if (s/^(\S+):\s*//) {
-        $v= $1; $v =~ y/A-Z/a-z/;
-print DEBUG ">$v=$_<\n";
-        $header{$v}= $_;
+       my $v = lc $1;
+       print ">$v=$_<\n" if $debug;
+       $header{$v} = $_;
     } else {
-print DEBUG "!>$_<\n";
+       print "!>$_<\n" if $debug;
     }
 }
 
+grep(s/\s+$//,@bodylines);
+
+print "***\n",join("\n",@bodylines),"\n***\n" if $debug;
+
+if (defined $header{'resent-from'} && !defined $header{'from'}) {
+    $header{'from'} = $header{'resent-from'};
+}
+
 defined($header{'from'}) || &quit("no From header");
-$replyto= defined($header{'reply-to'}) ? $header{'reply-to'} : $header{'from'};
+
+delete $header{'reply-to'} 
+       if ( defined($header{'reply-to'}) && $header{'reply-to'} =~ m/^\s*$/ );
+
+if ( defined($header{'reply-to'}) && $header{'reply-to'} ne "" ) {
+    $replyto = $header{'reply-to'};
+} else {
+    $replyto = $header{'from'};
+}
 
 $controlrequestaddr= $control ? "control\@$gEmailDomain" : "request\@$gEmailDomain";
 $transcript='';
@@ -70,38 +112,70 @@ $state= 'idle';
 $lowstate= 'idle';
 $mergelowstate= 'idle';
 $midix=0;    
+$extras="";
+
+my $quickabort = 0;
+
+my $fuckheads = "(" . join("|", @gFuckheads) . ")";
+if (@gFuckheads and $replyto =~ m/$fuckheads/) {
+       &transcript("This service is unavailable.\n\n");
+       $quickabort = 1;
+}
+
+my %clonebugs = ();
+my @bcc = ();
 
-for ($procline=$i; $procline<=$#msg; $procline++) {
-    $state eq 'idle' || "$state ?";
-    $lowstate eq 'idle' || "$lowstate ?";
-    $mergelowstate eq 'idle' || "$mergelowstate ?";
-    $_= $msg[$procline]; s/\s+$//;
+for ($procline=0; $procline<=$#bodylines; $procline++) {
+    $state eq 'idle' || print "$state ?\n";
+    $lowstate eq 'idle' || print "$lowstate ?\n";
+    $mergelowstate eq 'idle' || print "$mergelowstate ?\n";
+    if ($quickabort) {
+         &transcript("Stopping processing here.\n\n");
+        last;
+    }
+    $_= $bodylines[$procline]; s/\s+$//;
     next unless m/\S/; next if m/^\s*\#/;
     &transcript("> $_\n");
     $action= '';
-    if (m/^stop$/ || m/^quit$/ || m/^--/ || m/^thank/) {
-        &transcript("Stopping processing here.\n\n");
+    if (m/^stop/i || m/^quit/i || m/^--/ || m/^thank/i) {
+       &transcript("Stopping processing here.\n\n");
         last;
-    } elsif (m/^debug\s+(\d+)$/ && $1 >= 0 && $1 <= 1000) {
+    } elsif (m/^debug\s+(\d+)$/i && $1 >= 0 && $1 <= 1000) {
         $dl= $1+0;
         &transcript("Debug level $dl.\n\n");
-    } elsif (m/^(send|get)\s+\#?(\d{3,})$/) {
-        $ref= $2+0; $reffile= $ref; $reffile =~ s,^..,$&/$&,;
-        &sendlynxdoc("db/$reffile.html","logs for $gBug#$ref");
-    } elsif (m/^send-detail\s+\#?(\d+)$/) {
-        $ref= $1+0; $reffile= $ref; $reffile =~ s,^..,$&/$&,;
-        &sendlynxdoc("db/$reffile-b.html","additional logs for $gBug#$ref");
-    } elsif (m/^index(\s+full)?$/) {
-        &sendlynxdoc("db/ix/full.html",'full index');
-    } elsif (m/^index-summary\s+by-package$/) {
-        &sendlynxdoc("db/ix/psummary.html",'summary index sorted by package/title');
-    } elsif (m/^index-summary(\s+by-number)?$/) {
-        &sendlynxdoc("db/ix/summary.html",'summary index sorted by number/date');
-    } elsif (m/^index(\s+|-)pack(age)?s?$/) {
-        &sendlynxdoc("db/ix/packages.html",'index of packages');
-    } elsif (m/^index(\s+|-)maints?$/) {
-        &sendlynxdoc("db/ix/maintainers.html",'index of maintainers');
-    } elsif (m/^index(\s+|-)maint\s+(\S.*\S)$/) {
+    } elsif (m/^(send|get)\s+\#?(\d{2,})$/i) {
+        $ref= $2+0;
+        &sendlynxdoc("$ref","logs for $gBug#$ref");
+    } elsif (m/^send-detail\s+\#?(\d+)$/i) {
+       &transcript("This BTS function is currently disabled, sorry.\n\n");
+       $ok++; # well, it's not really ok, but it fixes #81224 :)
+#        $ref= $1+0; $reffile= $ref; $reffile =~ s,^..,$&/$&,;
+#        &sendlynxdoc("db/$reffile-b.html","additional logs for $gBug#$ref");
+    } elsif (m/^index(\s+full)?$/i) {
+       &transcript("This BTS function is currently disabled, sorry.\n\n");
+       $ok++; # well, it's not really ok, but it fixes #81224 :)
+#        &sendlynxdoc("db/ix/full.html",'full index');
+    } elsif (m/^index-summary\s+by-package$/i) {
+       &transcript("This BTS function is currently disabled, sorry.\n\n");
+       $ok++; # well, it's not really ok, but it fixes #81224 :)
+#        &sendlynxdoc("db/ix/psummary.html",'summary index sorted by package/title');
+    } elsif (m/^index-summary(\s+by-number)?$/i) {
+       &transcript("This BTS function is currently disabled, sorry.\n\n");
+       $ok++; # well, it's not really ok, but it fixes #81224 :)
+#        &sendlynxdoc("db/ix/summary.html",'summary index sorted by number/date');
+    } elsif (m/^index(\s+|-)pack(age)?s?$/i) {
+       &sendlynxdoc("cgi-bin/pkgindex.cgi?indexon=pkg",'index of packages');
+    } elsif (m/^index(\s+|-)maints?$/i) {
+       &sendlynxdoc("cgi-bin/pkgindex.cgi?indexon=maint",'index of maintainers');
+    } elsif (m/^index(\s+|-)maint\s+(\S+)$/i) {
+       $maint = $2;
+# check for crap in $maint
+       if ($maint =~ m/^\./ || $maint !~ m/^[\d\w-+.@]+$/) {
+               &transcript("Invalid request $maint!\n");
+               next;
+       }
+       &sendlynxdoc("$maint","$gBug list for maintainer \`$maint'");
+if (0) {
         $substrg= $2; $matches=0;
         opendir(DBD,"$gWebDir/db/ma") || die $!;
         while (defined($_=readdir(DBD))) {
@@ -135,8 +209,17 @@ for ($procline=$i; $procline<=$#msg; $procline++) {
             &transcript("No maintainers found containing \`$substrg'.\n".
                         "Use \`index-maint' to get list of maintainers.\n\n");
         }
+} # 0
         $ok++;
-    } elsif (m/^index(\s+|-)pack(age)?s?\s+(\S.*\S)$/) {
+    } elsif (m/^index(\s+|-)pack(age)?s?\s+(\S.*\S)$/i) {
+       $package = $+;
+# check for crap in $package
+       if ($package =~ m/^\./ || $package !~ m/^[\d\w-+.@]+$/) {
+               &transcript("Invalid request $package!\n");
+               next;
+       }
+       &sendlynxdoc("$package","$gBug list for package $package sent.\n\n");
+if (0) {
         $substrg= $+; $matches=0;
         opendir(DBD,"$gWebDir/db/pa") || die $!;
         while (defined($_=readdir(DBD))) {
@@ -155,40 +238,47 @@ for ($procline=$i; $procline<=$#msg; $procline++) {
             &transcript("No packages found containing \`$substrg'.\n".
                         "Use \`index-packages' to get list of packages.\n\n");
         }
+} # 0
         $ok++;
-    } elsif (m/^send-unmatched(\s+this|\s+-?0)?$/) {
-        &sendlynxdoc("db/ju/unmatched-1.html","junk (this week)");
-    } elsif (m/^send-unmatched\s+(last|-1)$/) {
-        &sendlynxdoc("db/ju/unmatched-2.html","junk (last week)");
-    } elsif (m/^send-unmatched\s+(old|-2)$/) {
-        &sendlynxdoc("db/ju/unmatched-3.html","junk (two weeks ago)");
-    } elsif (m/^getinfo\s+(\S+)$/) {
-        $file= $1;
-        if ($file =~ m/^\./ || $file !~ m/^[-.0-9a-z]+$/ || $file =~ m/\.gz$/) {
-            &transcript("Filename $file is badly formatted.\n\n");
-        } elsif (open(P,"$gDocDir/$file")) {
-            $ok++;
-            &transcript("Info file $file appears below.\n\n");
-            $extras.= "\n---------- Info file $file follows:\n\n";
-            while(<P>) { $extras.= $_; }
-            close(P);
-        } else {
-            &transcript("Info file $file does not exist.\n\n");
-         }
-    } elsif (m/^help$/) {
+    } elsif (m/^send-unmatched(\s+this|\s+-?0)?$/i) {
+       &transcript("This BTS function is currently disabled, sorry.\n\n");
+       $ok++; # well, it's not really ok, but it fixes #81224 :)
+#        &sendlynxdoc("db/ju/unmatched-1.html","junk (this week)");
+    } elsif (m/^send-unmatched\s+(last|-1)$/i) {
+       &transcript("This BTS function is currently disabled, sorry.\n\n");
+       $ok++; # well, it's not really ok, but it fixes #81224 :)
+#        &sendlynxdoc("db/ju/unmatched-2.html","junk (last week)");
+    } elsif (m/^send-unmatched\s+(old|-2)$/i) {
+       &transcript("This BTS function is currently disabled, sorry.\n\n");
+       $ok++; # well, it's not really ok, but it fixes #81224 :)
+#        &sendlynxdoc("db/ju/unmatched-3.html","junk (two weeks ago)");
+    } elsif (m/^getinfo\s+([\w-.]+)$/i) {
+# the following is basically a Debian-specific kludge, but who cares
+        $req = $1;
+       if ($req =~ /^maintainers$/i && -f "$gConfigDir/Maintainers") {
+           &sendinfo("local", "$gConfigDir/Maintainers", "Maintainers file");
+       } elsif ($req =~ /^override\.(\w+)\.([\w-.]+)$/i) {
+           $req =~ s/.gz$//;
+           &sendinfo("ftp.d.o", "$req", "override file for $2 part of $1 distribution");
+       } elsif ($req =~ /^pseudo-packages\.(description|maintainers)$/i && -f "$gConfigDir/$req") {
+           &sendinfo("local", "$gConfigDir/$req", "$req file");
+       } else {
+           &transcript("Info file $req does not exist.\n\n");
+       }
+    } elsif (m/^help/i) {
         &sendhelp;
         &transcript("\n");
         $ok++;
-    } elsif (m/^refcard$/) {
-        &sendtxthelp("bug-mailserver-refcard.txt","mailservers' reference card");
-    } elsif (m/^subscribe/) {
+    } elsif (m/^refcard/i) {
+        &sendtxthelp("bug-mailserver-refcard.txt","mail servers' reference card");
+    } elsif (m/^subscribe/i) {
         &transcript(<<END);
 There is no $gProject $gBug mailing list.  If you wish to review bug reports
-please do so via http://$gWebUrl/ or ask this mailserver
+please do so via http://$gWebDomain/ or ask this mail server
 to send them to you.
 soon: MAILINGLISTS_TEXT
 END
-    } elsif (m/^unsubscribe/) {
+    } elsif (m/^unsubscribe/i) {
         &transcript(<<END);
 soon: UNSUBSCRIBE_TEXT
 soon: MAILINGLISTS_TEXT
@@ -203,7 +293,8 @@ END
             &transcript("Too many unknown commands, stopping here.\n\n");
             last;
         }
-    } elsif (m/^close\s+\#?(\d+)$/) {
+#### interesting ones start here
+    } elsif (m/^close\s+\#?(-?\d+)$/i) {
        $ok++;
        $ref= $1;
        if (&setbug) {
@@ -211,40 +302,44 @@ END
                &transcript("$gBug is already closed, cannot re-close.\n\n");
                 &nochangebug;
             } else {
-                $action= "$gBug closed, ack sent to submitter - they'd better know why !";
+                $action= "$gBug closed, send any further explanations to $s_originator";
                 do {
                     &addmaintainers($s_package);
                                        if ( length( $gDoneList ) > 0 && length( $gListDomain ) >
                                        0 ) { &addccaddress("$gDoneList\@$gListDomain"); }
                     $s_done= $replyto;
                    $message= <<END;
-From: $gMaintainerEmail ($gMaintainer)
+From: $gMaintainerEmail ($gProject $gBug Tracking System)
 To: $s_originator
 Subject: $gBug#$ref acknowledged by developer
-         ($s_subject)
+         ($header{'subject'})
 References: $header{'message-id'} $s_msgid
 In-Reply-To: $s_msgid
 Message-ID: <handler.$ref.$nn.notifdonectrl.$midix\@$gEmailDomain>
+Reply-To: $ref\@$gEmailDomain
 
-This is an automatic notification regarding your $gBug report.
+This is an automatic notification regarding your $gBug report
+#$ref: $s_subject,
+which was filed against the $s_package package.
 
 It has been marked as closed by one of the developers, namely
 $replyto.
 
 You should be hearing from them with a substantive response shortly,
-if you have not already done so.  If not, please contact them
-directly, or email DB_SUBMIT_ADDRPQ or myself.
+in case you haven't already. If not, please contact them directly.
 
 $gMaintainer
 (administrator, $gProject $gBugs database)
+
 END
                     &sendmailmessage($message,$s_originator);
                 } while (&getnextbug);
             }
         }
-    } elsif (m/^reassign\s+\#?(\d+)\s+(\S.*\S)$/) {
+    } elsif (m/^reassign\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
         $ok++;
         $ref= $1; $newpackage= $2;
+       $newpackage =~ y/A-Z/a-z/;
         if (&setbug) {
             if (length($s_package)) {
                 $action= "$gBug reassigned from package \`$s_package'".
@@ -258,15 +353,15 @@ END
                 $s_package= $newpackage;
             } while (&getnextbug);
         }
-    } elsif (m/^reopen\s+\#?(\d+)$/ ? ($noriginator='', 1) :
-             m/^reopen\s+\#?(\d+)\s+\=$/ ? ($noriginator='', 1) :
-             m/^reopen\s+\#?(\d+)\s+\!$/ ? ($noriginator=$replyto, 1) :
-             m/^reopen\s+\#?(\d+)\s+(\S.*\S)$/ ? ($noriginator=$2, 1) : 0) {
+    } elsif (m/^reopen\s+\#?(-?\d+)$/i ? ($noriginator='', 1) :
+             m/^reopen\s+\#?(-?\d+)\s+\=$/i ? ($noriginator='', 1) :
+             m/^reopen\s+\#?(-?\d+)\s+\!$/i ? ($noriginator=$replyto, 1) :
+             m/^reopen\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($noriginator=$2, 1) : 0) {
         $ok++;
         $ref= $1;
         if (&setbug) {
             if (!length($s_done)) {
-                &transcript("$gByg is already open, cannot reopen.\n\n");
+                &transcript("$gBug is already open, cannot reopen.\n\n");
                 &nochangebug;
             } else {
                 $action=
@@ -279,7 +374,7 @@ END
                 } while (&getnextbug);
             }
         }
-    } elsif (m/^forwarded\s+\#?(\d+)\s+(\S.*\S)$/) {
+    } elsif (m/^forwarded\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
         $ok++;
         $ref= $1; $whereto= $2;
         if (&setbug) {
@@ -293,12 +388,13 @@ END
             }
             do {
                 &addmaintainers($s_package);
-                               if (length($gFowardList)>0 && length($gListDomain)>0 )
-                { &addccaddress("$gFowardList\@$gListDomain"); }
+               if (length($gFowardList)>0 && length($gListDomain)>0 ) {
+                    &addccaddress("$gFowardList\@$gListDomain"); 
+               }
                 $s_forwarded= $whereto;
             } while (&getnextbug);
         }
-    } elsif (m/^notforwarded\s+\#?(\d+)$/) {
+    } elsif (m/^notforwarded\s+\#?(-?\d+)$/i) {
         $ok++;
         $ref= $1;
         if (&setbug) {
@@ -313,13 +409,14 @@ END
                 } while (&getnextbug);
             }
         }
-    } elsif (m/^severity\s+\#?(\d+)\s+([-0-9a-z]+)$/) {
+    } elsif (m/^severity\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i ||
+       m/^priority\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i) {
         $ok++;
         $ref= $1;
         $newseverity= $2;
-        if (!grep($_ eq $newseverity, @severities, "$gDefaultSeverity")) {
+        if (!grep($_ eq $newseverity, @gSeverityList, "$gDefaultSeverity")) {
             &transcript("Severity level \`$newseverity' is not known.\n".
-                       "Recognised are: ".join(' ',@showseverities).".\n\n");
+                       "Recognized are: $gShowSeverities.\n\n");
         } elsif (&setbug) {
             $printseverity= $s_severity;
             $printseverity= "$gDefaultSeverity" if $printseverity eq '';
@@ -329,9 +426,59 @@ END
                 $s_severity= $newseverity;
             } while (&getnextbug);
         }
-    } elsif (m/^retitle\s+\#?(\d+)\s+(\S.*\S)\s*$/) {
+    } elsif (m/^tags?\s+\#?(-?\d+)\s+(([=+-])\s+)?(\S.*)?$/i) {
+       $ok++;
+       $ref = $1; $addsubcode = $3; $tags = $4;
+       $addsub = "add";
+       if (defined $addsubcode) {
+           $addsub = "sub" if ($addsubcode eq "-");
+           $addsub = "add" if ($addsubcode eq "+");
+           $addsub = "set" if ($addsubcode eq "=");
+       }
+       my @okaytags = ();
+       my @badtags = ();
+       foreach my $t (split /[\s,]+/, $tags) {
+           if (!grep($_ eq $t, @gTags)) {
+               push @badtags, $t;
+           } else {
+               push @okaytags, $t;
+           }
+       }
+       if (@badtags) {
+            &transcript("Unknown tag/s: ".join(', ', @badtags).".\n".
+                       "Recognized are: ".join(' ', @gTags).".\n\n");
+       }
+       if (&setbug) {
+           if ($addsub eq "set") {
+               $action= "Tags set to: " . join(", ", @okaytags);
+           } elsif ($addsub eq "add") {
+               $action= "Tags added: " . join(", ", @okaytags);
+           } elsif ($addsub eq "sub") {
+               $action= "Tags removed: " . join(", ", @okaytags);
+           }
+           do {
+                &addmaintainers($s_package);
+               $s_keywords = '' if ($addsub eq "set");
+               if ($addsub eq "sub") {
+                   foreach my $t (@badtags) {
+                       $s_keywords = join ' ', grep $_ ne $t, 
+                           split ' ', $s_keywords;
+                   }
+               }
+               foreach my $t (@okaytags) {
+                   $s_keywords = join ' ', grep $_ ne $t, 
+                       split ' ', $s_keywords;
+                   $s_keywords = "$t $s_keywords" unless($addsub eq "sub");
+               }
+               $s_keywords =~ s/\s*$//;
+            } while (&getnextbug);
+       }
+    } elsif (m/^retitle\s+\#?(-?\d+)\s+(\S.*\S)\s*$/i) {
         $ok++;
         $ref= $1; $newtitle= $2;
+       if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
+           $ref = $clonebugs{$ref};
+       }
         if (&getbug) {
             &foundbug;
             &addmaintainers($s_package);
@@ -346,7 +493,7 @@ END
         } else {
             &notfoundbug;
         }
-    } elsif (m/^unmerge\s+\#?(\d+)$/) {
+    } elsif (m/^unmerge\s+\#?(-?\d+)$/i) {
        $ok++;
        $ref= $1;
        if (&setbug) {
@@ -365,10 +512,11 @@ END
                 } while (&getnextbug);
            }
        }
-    } elsif (m/^merge\s(\d+(\s+\d+)+)\s*$/) {
+    } elsif (m/^merge\s+(\d+(\s+\d+)+)\s*$/i) {
        $ok++;
         @tomerge= sort { $a <=> $b } split(/\s+/,$1);
         @newmergelist= ();
+       my %tags = ();
         &getmerge;
         while (defined($ref= shift(@tomerge))) {
             &transcript("D| checking merge $ref\n") if $dl;
@@ -376,14 +524,16 @@ END
            next if grep($_ eq $ref,@newmergelist);
            if (!&getbug) { &notfoundbug; @newmergelist=(); last }
             &foundbug;
-            &transcript("D| adding $ref ($s_mergewith)\n") if $dl;
+            &transcript("D| adding $ref ($s_mergedwith)\n") if $dl;
            $mismatch= '';
            &checkmatch('package','m_package',$s_package);
            &checkmatch('forwarded addr','m_forwarded',$s_forwarded);
+           $s_severity = '$gDefaultSeverity' if $s_severity eq '';
            &checkmatch('severity','m_severity',$s_severity);
            &checkmatch('done mark','m_done',length($s_done) ? 'done' : 'open');
+           foreach my $t (split /\s+/, $s_keywords) { $tags{$t} = 1; }
            if (length($mismatch)) {
-               &transcript("Mismatch - only $Bugs in same state can be merged:\n".
+               &transcript("Mismatch - only $gBugs in same state can be merged:\n".
                             $mismatch."\n");
                &cancelbug; @newmergelist=(); last;
            }
@@ -398,11 +548,55 @@ END
                &getbug || die "huh ?  $gBug $ref disappeared during merge";
                 &addmaintainers($s_package);
                $s_mergedwith= join(' ',grep($_ ne $ref,@newmergelist));
+               $s_keywords= join(' ', keys %tags);
                &savebug;
            }
            &transcript("$action\n\n");
        }
         &endmerge;
+    } elsif (m/^clone\s+#?(\d+)\s+((-\d+\s+)*-\d+)\s*$/i) {
+       $ok++;
+
+       $origref = $1;
+       @newclonedids = split /\s+/, $2;
+       $newbugsneeded = scalar(@newclonedids);
+
+       $ref = $origref;
+       if (&setbug) {
+           if (length($s_mergedwith)) {
+               &transcript("$gBug is marked as being merged with others.\n\n");
+               &nochangebug;
+           } else {
+               &filelock("nextnumber.lock");
+               open(N,"nextnumber") || &quit("nextnumber: read: $!");
+               $v=<N>; $v =~ s/\n$// || &quit("nextnumber bad format");
+               $firstref= $v+0;  $v += $newbugsneeded;
+               open(NN,">nextnumber"); print NN "$v\n"; close(NN);
+               &unfilelock;
+
+               $lastref = $firstref + $newbugsneeded - 1;
+
+               if ($newbugsneeded == 1) {
+                   $action= "$gBug $origref cloned as bug $firstref.";
+               } else {
+                   $action= "$gBug $origref cloned as bugs $firstref-$lastref.";
+               }
+               &getnextbug;
+               my $ohash = get_hashname($origref);
+               $ref = $firstref;
+               for $newclonedid (@newclonedids) {
+                   $clonebugs{$newclonedid} = $ref;
+           
+                   my $hash = get_hashname($ref);
+                   copy("db-h/$ohash/$origref.log", "db-h/$hash/$ref.log");
+                   copy("db-h/$ohash/$origref.status", "db-h/$hash/$ref.status");
+                   copy("db-h/$ohash/$origref.report", "db-h/$hash/$ref.report");
+                   &bughook('new', $ref, "$s_originator\n$s_date\n$s_subject\n$s_msgid\n$s_package\n$s_keywords\n$s_done\n$s_forwarded\n$s_mergedwith\n$s_severity\n");
+
+                   $ref++;
+               }
+           }
+       }
     } else {
         &transcript("Unknown command or malformed arguments to command.\n\n");
         if (++$unknowns >= 5) {
@@ -411,10 +605,10 @@ END
         }
     }
 }
-if ($procline>$#msg) {
+if ($procline>$#bodylines) {
     &transcript(">\nEnd of message, stopping processing here.\n\n");
 }
-if (!$ok) {
+if (!$ok && !quickabort) {
     &transcript("No commands successfully parsed; sending the help text(s).\n");
     &sendhelp;
     &transcript("\n");
@@ -434,16 +628,26 @@ for $maint (keys %maintccreasons) {
         $reasonstring.= $p.' ' if length($p);
         $reasonstring.= join(' ',map("#$_",sort keys %{$$reasonsref{$p}}));
     }
+    if (length($reasonstring) > 40) {
+       (substr $reasonstring, 37) = "...";
+    }
+    $reasonstring = "" if (!defined($reasonstring));
     push(@maintccs,"$maint ($reasonstring)");
     push(@maintccaddrs,"$maint");
 }
+
+$maintccs = ""; 
 if (@maintccs) {
     &transcript("MC|@maintccs|\n") if $dl>2;
-    $maintccs= "Cc: ".join(",\n    ",@maintccs)."\n";
+    $maintccs .= "Cc: " . join(",\n    ",@maintccs) . "\n";
+}
+
+if (!defined $header{'subject'} || $header{'subject'} eq "") {
+  $header{'subject'} = "your mail";
 }
 
 $reply= <<END;
-From: $gMaintainerEmail ($gMaintainer)
+From: $gMaintainerEmail ($gProject $gBug Tracking System)
 To: $replyto
 ${maintccs}Subject: Processed: $header{'subject'}
 In-Reply-To: $header{'message-id'}
@@ -459,7 +663,7 @@ END
 
 $repliedshow= join(', ',$replyto,@maintccaddrs);
 &filelock("lock/-1");
-open(AP,">>db/-1.log") || &quit("open db/-1.log: $!");
+open(AP,">>db-h/-1.log") || &quit("open db-h/-1.log: $!");
 print(AP
       "\2\n$repliedshow\n\5\n$reply\n\3\n".
       "\6\n".
@@ -467,12 +671,12 @@ print(AP
       &sani($header{'from'})."</code>\n".
       "to <code>".&sani($controlrequestaddr)."</code>\n".
       "\3\n".
-      "\7\n",@log,"\n\3\n") || &quit("writing db/-1.log: $!");
-close(AP) || &quit("open db/-1.log: $!");
+      "\7\n",@log,"\n\3\n") || &quit("writing db-h/-1.log: $!");
+close(AP) || &quit("open db-h/-1.log: $!");
 &unfilelock;
-utime(time,time,"db");
+utime(time,time,"db-h");
 
-&sendmailmessage($reply,$replyto,@maintccaddrs);
+&sendmailmessage($reply,$replyto,@maintccaddrs,@bcc);
 
 unlink("incoming/P$nn") || &quit("unlinking incoming/P$nn: $!");
 
@@ -484,11 +688,11 @@ sub get_addresses {
 
 sub sendmailmessage {
     local ($message,@recips) = @_;
-    print DEBUG "mailing to >@recips<\n";
+    print "mailing to >@recips<\n" if $debug;
     $c= open(D,"|-");
     defined($c) || &quit("mailing forking for sendmail: $!");
     if (!$c) { # ie, we are the child process
-        exec '/usr/lib/sendmail','-f'."$gMaintainerEmail",'-odi','-oem','-oi',get_addresses(@recips);
+        exec '/usr/lib/sendmail','-f'."$gMaintainerEmail",'-odb','-oem','-oi',get_addresses(@recips);
         die $!;
     }
     print(D $message) || &quit("writing to sendmail process: $!");
@@ -552,6 +756,14 @@ sub nochangebug {
 
 sub setbug {
     &dlen("setbug $ref");
+    if ($ref =~ m/^-\d+/) {
+        if (!defined $clonebugs{$ref}) {
+            &notfoundbug;
+            &dlex("setbug => noclone");
+            return 0;
+        }
+        $ref = $clonebugs{$ref};
+    }
     $state eq 'idle' || die "$state ?";
     if (!&getbug) {
         &notfoundbug;
@@ -666,16 +878,17 @@ sub savebug {
     $lowstate eq 'open' || die "$lowstate ?";
     length($action) || die;
     $ref == $sref || die "read $sref but saving $ref ?";
-    open(L,">>db/$ref.log") || &quit("opening db/$ref.log: $!");
+    my $hash = get_hashname($ref);
+    open(L,">>db-h/$hash/$ref.log") || &quit("opening db-h/$hash/$ref.log: $!");
     print(L
           "\6\n".
           "<strong>".&sani($action)."</strong>\n".
           "Request was from <code>".&sani($header{'from'})."</code>\n".
           "to <code>".&sani($controlrequestaddr)."</code>. \n".
           "\3\n".
-          "\7\n",@log,"\n\3\n") || &quit("writing db/$ref.log: $!");
-    close(L) || &quit("closing db/$ref.log: $!");
-    open(S,">db/$ref.status.new") || &quit("opening db/$ref.status.new: $!");
+          "\7\n",@log,"\n\3\n") || &quit("writing db-h/$hash/$ref.log: $!");
+    close(L) || &quit("closing db-h/$hash/$ref.log: $!");
+    open(S,">db-h/$hash/$ref.status.new") || &quit("opening db-h/$hash/$ref.status.new: $!");
     print(S
           "$s_originator\n".
           "$s_date\n".
@@ -686,10 +899,21 @@ sub savebug {
           "$s_done\n".
           "$s_forwarded\n".
           "$s_mergedwith\n".
-         "$s_severity\n") || &quit("writing db/$ref.status.new: $!");
-    close(S) || &quit("closing db/$ref.status.new: $!");
-    rename("db/$ref.status.new","db/$ref.status") ||
-        &quit("installing new db/$ref.status: $!");
+         "$s_severity\n") || &quit("writing db-h/$hash/$ref.status.new: $!");
+    close(S) || &quit("closing db-h/$hash/$ref.status.new: $!");
+    rename("db-h/$hash/$ref.status.new","db-h/$hash/$ref.status") ||
+        &quit("installing new db-h/$hash/$ref.status: $!");
+       &bughook('change',$ref,
+          "$s_originator\n".
+          "$s_date\n".
+          "$s_subject\n".
+          "$s_msgid\n".
+          "$s_package\n".
+          "$s_keywords\n".
+          "$s_done\n".
+          "$s_forwarded\n".
+          "$s_mergedwith\n".
+         "$s_severity\n");
     &unfilelock;
     $lowstate= "idle";
     &dlex("savebug");
@@ -706,7 +930,7 @@ sub dlex {
 }
 
 sub transcript {
-    print(DEBUG $_[0]);
+    print $_[0] if $debug;
     $transcript.= $_[0];
 }
 
@@ -730,7 +954,7 @@ sub sendtxthelpraw {
     close(D);
     &transcript("Sending $description in separate message.\n");
     &sendmailmessage(<<END.$doc,$replyto);
-From: $gMaintainerEmail ($gMaintainer)
+From: $gMaintainerEmail ($gProject $gBug Tracking System)
 To: $replyto
 Subject: $gProject $gBug help: $description
 References: $header{'message-id'}
@@ -744,7 +968,8 @@ END
 sub sendlynxdocraw {
     local ($relpath,$description) = @_;
     $doc='';
-    open(L,"lynx -nolist -dump $wwwbase/$relpath 2>&1 |") || &quit("fork for lynx: $!");
+# the below oughta use $gWebDomain but it can't
+    open(L,"lynx -nolist -dump http://bugs.debian.org/$relpath 2>&1 |") || &quit("fork for lynx: $!");
     while(<L>) { $doc.=$_; }
     $!=0; close(L);
     if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
@@ -756,7 +981,7 @@ sub sendlynxdocraw {
     } else {
         &transcript("Sending $description.\n");
         &sendmailmessage(<<END.$doc,$replyto);
-From: $gMaintainerEmail ($gMaintainer)
+From: $gMaintainerEmail ($gProject $gBug Tracking System)
 To: $replyto
 Subject: $gProject $gBugs information: $description
 References: $header{'message-id'}
@@ -776,31 +1001,92 @@ sub addccaddress {
 sub addmaintainers {
     # Data structure is:
     #   maintainer email address &c -> assoc of packages -> assoc of bug#'s
-    my $p, $addmaint, $pshow;
+    my ($p, $addmaint, $pshow);
     &ensuremaintainersloaded;
     $anymaintfound=0; $anymaintnotfound=0;
     for $p (split(m/[ \t?,()]+/,$_[0])) {
-        $p =~ y/A-Z/a-z/;
+       $p =~ y/A-Z/a-z/;
         $pshow= ($p =~ m/[-+.a-z0-9]+/ ? $& : '');
+        if (defined($pkgsrc{$p})) {
+           push @bcc, "$pkgsrc{$p}\@packages.qa.debian.org";
+       } else {
+           push @bcc, "$p\@packages.qa.debian.org";
+       }
         if (defined($maintainerof{$p})) {
-            $addmaint= $maintainerof{$p};
-&transcript("MR|$addmaint|$p|$ref|\n") if $dl>2;
+           $addmaint= $maintainerof{$p};
+           &transcript("MR|$addmaint|$p|$ref|\n") if $dl>2;
             $maintccreasons{$addmaint}{$p}{$ref}= 1;
-print DEBUG "maintainer add >$p|$addmaint<\n";
-        } else {
-print DEBUG "maintainer none >$p<\n";
-        }
+           print "maintainer add >$p|$addmaint<\n" if $debug;
+        } else { 
+           print "maintainer none >$p<\n" if $debug; 
+           &transcript("MR|unknown-package|$p|$ref|\n") if $dl>2;
+            $maintccreasons{$gUnknownMaintainerEmail}{$p}{$ref}= 1;
+       }
     }
 }
 
 sub ensuremaintainersloaded {
-    my $a,$b;
+    my ($a,$b);
     return if $maintainersloaded++;
     open(MAINT,"$gMaintainerFile") || die &quit("maintainers open: $!");
     while (<MAINT>) {
-        m/^(\S+)\s+(\S.*\S)\n$/ || &quit("maintainers bogus \`$_'");
+       m/^\n$/ && next;
+       m/^\s*$/ && next;
+        m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers bogus \`$_'");
         $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
         $maintainerof{$1}= $2;
     }
     close(MAINT);
+    open(MAINT,"$gMaintainerFileOverride") || die &quit("maintainers.override open: $!");
+    while (<MAINT>) {
+        m/^\n$/ && next;
+        m/^\s*$/ && next;
+        m/^(\S+)\s+(\S.*\S)\s*\n$/ || &quit("maintainers.override bogus \`$_'");
+        $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
+        $maintainerof{$1}= $2;
+    }
+
+    open(SOURCES, "$gPackageSource") || &quit("pkgsrc open: $!");
+    while (<SOURCES>) {
+       next unless m/^(\S+)\s+(\S.*\S)\s*$/;
+       my ($a, $b) = ($1, $2);
+       $pkgsrc{lc($a)} = $b;
+    }
+    close(SOURCES);
+}
+
+sub sendinfo {
+    local ($wherefrom,$path,$description) = @_;
+    if ($wherefrom eq "ftp.d.o") {
+      $doc = `lynx -nolist -dump http://ftp.debian.org/debian/indices/$path.gz 2>&1 | gunzip -cf` or &quit("fork for lynx/gunzip: $!");
+      $! = 0;
+      if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
+          &transcript("$description is not available.\n");
+          $ok++; return;
+      } elsif ($?) {
+          &transcript("Error getting $description (code $? $!):\n$doc\n");
+          return;
+      }
+    } elsif ($wherefrom eq "local") {
+      open P, "$path";
+      $doc = do { local $/; <P> };
+      close P;
+    } else {
+      &transcript("internal errror: info files location unknown.\n");
+      $ok++; return;
+    }
+    &transcript("Sending $description.\n");
+    &sendmailmessage(<<END.$doc,$replyto);
+From: $gMaintainerEmail ($gProject $gBug Tracking System)
+To: $replyto
+Subject: $gProject $gBugs information: $description
+References: $header{'message-id'}
+In-Reply-To: $header{'message-id'}
+Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
+
+$description follows:
+
+END
+    $ok++;
+    &transcript("\n");
 }