]> git.donarmstrong.com Git - debbugs.git/blobdiff - scripts/service.in
[project @ 2005-07-30 03:22:36 by don]
[debbugs.git] / scripts / service.in
index ad784ae3700705ab6c488ef5f93e92e03a9c5faf..693caec7477f605b297b4604037b9bc6efca6c7d 100755 (executable)
@@ -1,16 +1,15 @@
 #!/usr/bin/perl
-# $Id: service.in,v 1.55 2002/10/12 18:39:01 cjwatson Exp $
-# ^ more or less ^
+# $Id: service.in,v 1.111 2005/07/30 03:22:36 don Exp $
 #
 # Usage: service <code>.nn
 # Temps:  incoming/P<code>.nn
 
-use Mail::Address;
 use File::Copy;
 use MIME::Parser;
+use Debbugs::MIME qw(decode_rfc1522 encode_rfc1522);
 
-$config_path = '/org/bugs.debian.org/etc';
-$lib_path = '/org/bugs.debian.org/scripts';
+$config_path = '/etc/debbugs';
+$lib_path = '/usr/lib/debbugs';
 
 require "$config_path/config";
 require "$lib_path/errorlib";
@@ -48,6 +47,9 @@ my $entity = eval { $parser->parse_data(join('',@log)) };
 
 # header and decoded body respectively
 my (@headerlines, @bodylines);
+# Bug numbers to send e-mail to, hash so that we don't send to the
+# same bug twice.
+my (%bug_affected);
 
 if ($entity and $entity->head->tags) {
     @headerlines = @{$entity->head->header};
@@ -73,6 +75,7 @@ if ($entity and $entity->head->tags) {
 }
 
 for (@headerlines) {
+    $_ = decode_rfc1522($_);
     s/\n\s/ /g;
     print ">$_<\n" if $debug;
     if (s/^(\S+):\s*//) {
@@ -84,6 +87,19 @@ for (@headerlines) {
     }
 }
 
+# Strip off RFC2440-style PGP clearsigning.
+if (@bodylines and $bodylines[0] =~ /^-----BEGIN PGP SIGNED/) {
+    shift @bodylines while @bodylines and length $bodylines[0];
+    shift @bodylines while @bodylines and $bodylines[0] !~ /\S/;
+    for my $findsig (0 .. $#bodylines) {
+       if ($bodylines[$findsig] =~ /^-----BEGIN PGP SIGNATURE/) {
+           $#bodylines = $findsig - 1;
+           last;
+       }
+    }
+    map { s/^- // } @bodylines;
+}
+
 grep(s/\s+$//,@bodylines);
 
 print "***\n",join("\n",@bodylines),"\n***\n" if $debug;
@@ -122,9 +138,14 @@ if (@gFuckheads and $replyto =~ m/$fuckheads/) {
        $quickabort = 1;
 }
 
+my %limit_pkgs = ();
 my %clonebugs = ();
 my @bcc = ();
 
+sub addbcc {
+    push @bcc, $_[0] unless grep { $_ eq $_[0] } @bcc;
+}
+
 for ($procline=0; $procline<=$#bodylines; $procline++) {
     $state eq 'idle' || print "$state ?\n";
     $lowstate eq 'idle' || print "$lowstate ?\n";
@@ -134,8 +155,9 @@ for ($procline=0; $procline<=$#bodylines; $procline++) {
         last;
     }
     $_= $bodylines[$procline]; s/\s+$//;
-    next unless m/\S/; next if m/^\s*\#/;
+    next unless m/\S/;
     &transcript("> $_\n");
+    next if m/^\s*\#/;
     $action= '';
     if (m/^stop/i || m/^quit/i || m/^--/ || m/^thank/i) {
        &transcript("Stopping processing here.\n\n");
@@ -145,115 +167,45 @@ for ($procline=0; $procline<=$#bodylines; $procline++) {
         &transcript("Debug level $dl.\n\n");
     } 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");
+        &sendlynxdoc("bugreport.cgi?bug=$ref","logs for $gBug#$ref");
+    } elsif (m/^send-detail\s+\#?(\d{2,})$/i) {
+       $ref= $1+0;
+       &sendlynxdoc("bugreport.cgi?bug=$ref&boring=yes",
+                    "detailed 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');
+       &sendlynxdoc("pkgindex.cgi?indexon=pkg",'index of packages');
     } elsif (m/^index(\s+|-)maints?$/i) {
-       &sendlynxdoc("cgi-bin/pkgindex.cgi?indexon=maint",'index of maintainers');
+       &sendlynxdoc("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))) {
-            next unless m/^l/ && m/\.html$/;
-            &transcript("F|$_\n") if $dl>1;
-            $filename= $_; s/^l//; s/\.html$//;
-            &transcript("P|$_\n") if $dl>2;
-            while (s/-(..)([^_])/-$1_-$2/) { }
-            &transcript("P|$_\n") if $dl>2;
-            s/^(.{0,2})_/$1-20_/g; while (s/([^-]..)_/$1-20_/) { };
-            &transcript("P|$_\n") if $dl>2;
-            s/^,(.*),(.*),([^,]+)$/$1-40_$2-20_-28_$3-29_/;
-            &transcript("P|$_\n") if $dl>2;
-            s/^([^,]+),(.*),(.*),$/$1-20_-3c_$2-40_$3-3e_/;
-            &transcript("P|$_\n") if $dl>2;
-            s/\./-2e_/g;
-            &transcript("P|$_\n") if $dl>2;
-            $out='';
-            while (m/-(..)_/) { $out.= $`.sprintf("%c",hex($1)); $_=$'; }
-            $out.=$_;
-            &transcript("M|$out\n") if $dl>1;
-            next unless index(lc $out, lc $substrg)>=0;
-            &transcript("S|$filename\n") if $dl>0;
-            &transcript("S|$out\n") if $dl>0;
-            $matches++;
-            &sendlynxdocraw("db/ma/$filename","$gBug list for maintainer \`$out'");
-        }
-        if ($matches) {
-            &transcript("$gBug list(s) for $matches maintainer(s) sent.\n\n");
-        } else {
-            &transcript("No maintainers found containing \`$substrg'.\n".
-                        "Use \`index-maint' to get list of maintainers.\n\n");
-        }
-} # 0
+       &sendlynxdoc("pkgreport.cgi?maint=" . urlsanit($maint),
+                    "$gBug list for maintainer \`$maint'");
         $ok++;
     } 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))) {
-            next unless m/^l/ && m/\.html$/;
-            &transcript("F|$_\n") if $dl>1;
-            $filename= $_; s/^l//; s/\.html$//;
-            next unless index(lc $_, lc $substrg)>=0;
-            &transcript("S|$filename\n") if $dl>0;
-            &transcript("S|$out\n") if $dl>0;
-            $matches++;
-            &sendlynxdocraw("db/pa/$filename","$gBug list for package \`$_'");
-        }
-        if ($matches) {
-            &transcript("$gBug list(s) for $matches package(s) sent.\n\n");
-        } else {
-            &transcript("No packages found containing \`$substrg'.\n".
-                        "Use \`index-packages' to get list of packages.\n\n");
-        }
-} # 0
+       &sendlynxdoc("pkgreport.cgi?pkg=" . urlsanit($package),
+                    "$gBug list for package $package");
         $ok++;
     } 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
+        # 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");
@@ -294,33 +246,49 @@ END
             last;
         }
 #### interesting ones start here
-    } elsif (m/^close\s+\#?(-?\d+)$/i) {
+    } elsif (m/^close\s+\#?(-?\d+)(?:\s+(\d.*))?$/i) {
        $ok++;
        $ref= $1;
+       $bug_affected{$ref}=1;
+       $version= $2;
        if (&setbug) {
-           if (length($s_done)) {
+           &transcript("'close' is deprecated; see http://$gWebDomain/Developer$gHTMLSuffix#closing.\n");
+           if (length($data->{done}) and not defined($version)) {
                &transcript("$gBug is already closed, cannot re-close.\n\n");
                 &nochangebug;
             } else {
-                $action= "$gBug closed, send any further explanations to $s_originator";
+                $action= "$gBug " .
+                    (defined($version) ?
+                        "marked as fixed in version $version" :
+                        "closed") .
+                    ", send any further explanations to $data->{originator}";
                 do {
-                    &addmaintainers($s_package);
+                    &addmaintainers($data);
                                        if ( length( $gDoneList ) > 0 && length( $gListDomain ) >
                                        0 ) { &addccaddress("$gDoneList\@$gListDomain"); }
-                    $s_done= $replyto;
+                    $data->{done}= $replyto;
+                    my @keywords= split ' ', $data->{keywords};
+                    if (grep $_ eq 'pending', @keywords) {
+                        $extramessage= "Removed pending tag.\n";
+                        $data->{keywords}= join ' ', grep $_ ne 'pending',
+                                                @keywords;
+                    }
+                    addfixedversions($data, $data->{package}, $version, 'binary');
+
                    $message= <<END;
 From: $gMaintainerEmail ($gProject $gBug Tracking System)
-To: $s_originator
+To: $data->{originator}
 Subject: $gBug#$ref acknowledged by developer
          ($header{'subject'})
-References: $header{'message-id'} $s_msgid
-In-Reply-To: $s_msgid
+References: $header{'message-id'} $data->{msgid}
+In-Reply-To: $data->{msgid}
 Message-ID: <handler.$ref.$nn.notifdonectrl.$midix\@$gEmailDomain>
 Reply-To: $ref\@$gEmailDomain
+X-$gProject-PR-Message: they-closed-control $ref
 
 This is an automatic notification regarding your $gBug report
-#$ref: $s_subject,
-which was filed against the $s_package package.
+#$ref: $data->{subject},
+which was filed against the $data->{package} package.
 
 It has been marked as closed by one of the developers, namely
 $replyto.
@@ -332,25 +300,31 @@ $gMaintainer
 (administrator, $gProject $gBugs database)
 
 END
-                    &sendmailmessage($message,$s_originator);
+                    &sendmailmessage($message,$data->{originator});
                 } while (&getnextbug);
             }
         }
-    } elsif (m/^reassign\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
+    } elsif (m/^reassign\s+\#?(-?\d+)\s+(\S+)(?:\s+(\d.*))?$/i) {
         $ok++;
         $ref= $1; $newpackage= $2;
+       $bug_affected{$ref}=1;
+        $version= $3;
        $newpackage =~ y/A-Z/a-z/;
         if (&setbug) {
-            if (length($s_package)) {
-                $action= "$gBug reassigned from package \`$s_package'".
+            if (length($data->{package})) {
+                $action= "$gBug reassigned from package \`$data->{package}'".
                          " to \`$newpackage'.";
             } else {
                 $action= "$gBug assigned to package \`$newpackage'.";
             }
             do {
-                &addmaintainers($s_package);
-                &addmaintainers($newpackage);
-                $s_package= $newpackage;
+                &addmaintainers($data);
+                $data->{package}= $newpackage;
+                $data->{found_versions}= [];
+                $data->{fixed_versions}= [];
+                # TODO: what if $newpackage is a source package?
+                addfoundversions($data, $data->{package}, $version, 'binary');
+                &addmaintainers($data);
             } while (&getnextbug);
         }
     } elsif (m/^reopen\s+\#?(-?\d+)$/i ? ($noriginator='', 1) :
@@ -359,8 +333,12 @@ END
              m/^reopen\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($noriginator=$2, 1) : 0) {
         $ok++;
         $ref= $1;
+       $bug_affected{$ref}=1;
         if (&setbug) {
-            if (!length($s_done)) {
+            if (@{$data->{fixed_versions}}) {
+                &transcript("'reopen' is deprecated when a bug has been closed with a version;\nuse 'found' or 'submitter' as appropriate instead.\n");
+            }
+            if (!length($data->{done})) {
                 &transcript("$gBug is already open, cannot reopen.\n\n");
                 &nochangebug;
             } else {
@@ -368,44 +346,157 @@ END
                     $noriginator eq '' ? "$gBug reopened, originator not changed." :
                         "$gBug reopened, originator set to $noriginator.";
                 do {
-                    &addmaintainers($s_package);
-                    $s_originator= $noriginator eq '' ?  $s_originator : $noriginator;
-                    $s_done= '';
+                    &addmaintainers($data);
+                    $data->{originator}= $noriginator eq '' ?  $data->{originator} : $noriginator;
+                    $data->{fixed_versions}= [];
+                    $data->{done}= '';
+                } while (&getnextbug);
+            }
+        }
+    } elsif (m/^found\s+\#?(-?\d+)(?:\s+(\d.*))?$/i) {
+        $ok++;
+        $ref= $1;
+        $version= $2;
+        if (&setbug) {
+            if (!length($data->{done}) and not defined($version)) {
+                &transcript("$gBug is already open, cannot reopen.\n\n");
+                &nochangebug;
+            } else {
+                $action=
+                    defined($version) ?
+                        "$gBug marked as found in version $version." :
+                        "$gBug reopened.";
+                do {
+                    &addmaintainers($data);
+                    # The 'done' field gets a bit weird with version
+                    # tracking, because a bug may be closed by multiple
+                    # people in different branches. Until we have something
+                    # more flexible, we set it every time a bug is fixed,
+                    # and clear it precisely when a found command is
+                    # received for the rightmost fixed-in version, which
+                    # equates to the most recent fixing of the bug, or when
+                    # a versionless found command is received.
+                    if (defined $version) {
+                        my $lastfixed =
+                            (reverse @{$data->{fixed_versions}})[0];
+                        # TODO: what if $data->{package} is a source package?
+                        addfoundversions($data, $data->{package}, $version, 'binary');
+                        if (defined $lastfixed and not grep { $_ eq $lastfixed } @{$data->{fixed_versions}}) {
+                            $data->{done} = '';
+                        }
+                    } else {
+                        # Versionless found; assume old-style "not fixed at
+                        # all".
+                        $data->{fixed_versions} = [];
+                        $data->{done} = '';
+                    }
                 } while (&getnextbug);
             }
         }
+    } elsif (m/^notfound\s+\#?(-?\d+)\s+(\d.*)$/i) {
+        $ok++;
+        $ref= $1;
+        $version= $2;
+        if (&setbug) {
+            $action= "$gBug marked as not found in version $version.";
+            if (length($data->{done})) {
+                $extramessage= "(By the way, this $gBug is currently marked as done.)\n";
+            }
+            do {
+                &addmaintainers($data);
+                removefoundversions($data, $data->{package}, $version, 'binary');
+            } while (&getnextbug);
+        }
+    } elsif (m/^submitter\s+\#?(-?\d+)\s+\!$/i ? ($newsubmitter=$replyto, 1) :
+             m/^submitter\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($newsubmitter=$2, 1) : 0) {
+        $ok++;
+        $ref= $1;
+       $bug_affected{$ref}=1;
+        if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
+            $ref = $clonebugs{$ref};
+        }
+        if (&getbug) {
+            if (&checkpkglimit) {
+                &foundbug;
+                &addmaintainers($data);
+                $oldsubmitter= $data->{originator};
+                $data->{originator}= $newsubmitter;
+                $action= "Changed $gBug submitter from $oldsubmitter to $newsubmitter.";
+                &savebug;
+                &transcript("$action\n");
+                if (length($data->{done})) {
+                    &transcript("(By the way, that $gBug is currently marked as done.)\n");
+                }
+                &transcript("\n");
+                $message= <<END;
+From: $gMaintainerEmail ($gProject $gBug Tracking System)
+To: $oldsubmitter
+Subject: $gBug#$ref submitter address changed
+         ($header{'subject'})
+References: $header{'message-id'} $data->{msgid}
+In-Reply-To: $data->{msgid}
+Message-ID: <handler.$ref.$nn.newsubmitter.$midix\@$gEmailDomain>
+Reply-To: $ref\@$gEmailDomain
+X-$gProject-PR-Message: submitter-changed $ref
+
+The submitter address recorded for your $gBug report
+#$ref: $data->{subject}
+has been changed.
+
+The old submitter address for this report was
+$oldsubmitter.
+The new submitter address is
+$newsubmitter.
+
+This change was made by
+$replyto.
+If it was incorrect, please contact them directly.
+
+$gMaintainer
+(administrator, $gProject $gBugs database)
+
+END
+                &sendmailmessage($message,$oldsubmitter);
+            } else {
+                &cancelbug;
+            }
+        } else {
+            &notfoundbug;
+        }
     } elsif (m/^forwarded\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
         $ok++;
         $ref= $1; $whereto= $2;
+       $bug_affected{$ref}=1;
         if (&setbug) {
-            if (length($s_forwarded)) {
-    $action= "Forwarded-to-address changed from $s_forwarded to $whereto.";
+            if (length($data->{forwarded})) {
+    $action= "Forwarded-to-address changed from $data->{forwarded} to $whereto.";
             } else {
     $action= "Noted your statement that $gBug has been forwarded to $whereto.";
             }
-            if (length($s_done)) {
+            if (length($data->{done})) {
                 $extramessage= "(By the way, this $gBug is currently marked as done.)\n";
             }
             do {
-                &addmaintainers($s_package);
-               if (length($gFowardList)>0 && length($gListDomain)>0 ) {
-                    &addccaddress("$gFowardList\@$gListDomain"); 
+                &addmaintainers($data);
+               if (length($gForwardList)>0 && length($gListDomain)>0 ) {
+                    &addccaddress("$gForwardList\@$gListDomain"); 
                }
-                $s_forwarded= $whereto;
+                $data->{forwarded}= $whereto;
             } while (&getnextbug);
         }
     } elsif (m/^notforwarded\s+\#?(-?\d+)$/i) {
         $ok++;
         $ref= $1;
+       $bug_affected{$ref}=1;
         if (&setbug) {
-            if (!length($s_forwarded)) {
+            if (!length($data->{forwarded})) {
                 &transcript("$gBug is not marked as having been forwarded.\n\n");
                 &nochangebug;
             } else {
-    $action= "Removed annotation that $gBug had been forwarded to $s_forwarded.";
+    $action= "Removed annotation that $gBug had been forwarded to $data->{forwarded}.";
                 do {
-                    &addmaintainers($s_package);
-                    $s_forwarded= '';
+                    &addmaintainers($data);
+                    $data->{forwarded}= '';
                 } while (&getnextbug);
             }
         }
@@ -413,22 +504,30 @@ END
        m/^priority\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i) {
         $ok++;
         $ref= $1;
+       $bug_affected{$ref}=1;
         $newseverity= $2;
         if (!grep($_ eq $newseverity, @gSeverityList, "$gDefaultSeverity")) {
             &transcript("Severity level \`$newseverity' is not known.\n".
                        "Recognized are: $gShowSeverities.\n\n");
+        } elsif (exists $gObsoleteSeverities{$newseverity}) {
+            &transcript("Severity level \`$newseverity' is obsolete. " .
+                        "$gObsoleteSeverities{$newseverity}\n\n");
         } elsif (&setbug) {
-            $printseverity= $s_severity;
+            $printseverity= $data->{severity};
             $printseverity= "$gDefaultSeverity" if $printseverity eq '';
-           $action= "Severity set to \`$newseverity'.";
+           $action= "Severity set to \`$newseverity' from \`$printseverity'";
            do {
-                &addmaintainers($s_package);
-                $s_severity= $newseverity;
+                &addmaintainers($data);
+                if (defined $gStrongList and isstrongseverity($newseverity)) {
+                    addbcc("$gStrongList\@$gListDomain");
+                }
+                $data->{severity}= $newseverity;
             } while (&getnextbug);
         }
-    } elsif (m/^tags?\s+\#?(-?\d+)\s+(([=+-])\s+)?(\S.*)?$/i) {
+    } elsif (m/^tags?\s+\#?(-?\d+)\s+(([=+-])\s*)?(\S.*)?$/i) {
        $ok++;
        $ref = $1; $addsubcode = $3; $tags = $4;
+       $bug_affected{$ref}=1;
        $addsub = "add";
        if (defined $addsubcode) {
            $addsub = "sub" if ($addsubcode eq "-");
@@ -449,6 +548,11 @@ END
                        "Recognized are: ".join(' ', @gTags).".\n\n");
        }
        if (&setbug) {
+           if ($data->{keywords} eq '') {
+               &transcript("There were no tags set.\n");
+           } else {
+               &transcript("Tags were: $data->{keywords}\n");
+           }
            if ($addsub eq "set") {
                $action= "Tags set to: " . join(", ", @okaytags);
            } elsif ($addsub eq "add") {
@@ -457,98 +561,120 @@ END
                $action= "Tags removed: " . join(", ", @okaytags);
            }
            do {
-                &addmaintainers($s_package);
-               $s_keywords = '' if ($addsub eq "set");
+                &addmaintainers($data);
+               $data->{keywords} = '' if ($addsub eq "set");
+               # Allow removing obsolete tags.
                if ($addsub eq "sub") {
                    foreach my $t (@badtags) {
-                       $s_keywords = join ' ', grep $_ ne $t, 
-                           split ' ', $s_keywords;
+                       $data->{keywords} = join ' ', grep $_ ne $t, 
+                           split ' ', $data->{keywords};
                    }
                }
+               # Now process all other additions and subtractions.
                foreach my $t (@okaytags) {
-                   $s_keywords = join ' ', grep $_ ne $t, 
-                       split ' ', $s_keywords;
-                   $s_keywords = "$t $s_keywords" unless($addsub eq "sub");
+                   $data->{keywords} = join ' ', grep $_ ne $t, 
+                       split ' ', $data->{keywords};
+                   $data->{keywords} = "$t $data->{keywords}" unless($addsub eq "sub");
                }
-               $s_keywords =~ s/\s*$//;
+               $data->{keywords} =~ s/\s*$//;
             } while (&getnextbug);
        }
     } elsif (m/^retitle\s+\#?(-?\d+)\s+(\S.*\S)\s*$/i) {
         $ok++;
         $ref= $1; $newtitle= $2;
+       $bug_affected{$ref}=1;
        if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
            $ref = $clonebugs{$ref};
        }
         if (&getbug) {
-            &foundbug;
-            &addmaintainers($s_package);
-            $s_subject= $newtitle;
-            $action= "Changed $gBug title.";
-            &savebug;
-            &transcript("$action\n");
-            if (length($s_done)) {
-                &transcript("(By the way, that $gBug is currently marked as done.)\n");
+            if (&checkpkglimit) {
+                &foundbug;
+                &addmaintainers($data);
+                $data->{subject}= $newtitle;
+                $action= "Changed $gBug title.";
+                &savebug;
+                &transcript("$action\n");
+                if (length($data->{done})) {
+                    &transcript("(By the way, that $gBug is currently marked as done.)\n");
+                }
+                &transcript("\n");
+            } else {
+                &cancelbug;
             }
-            &transcript("\n");
         } else {
             &notfoundbug;
         }
     } elsif (m/^unmerge\s+\#?(-?\d+)$/i) {
        $ok++;
        $ref= $1;
+       $bug_affected{$ref} = 1;
        if (&setbug) {
-           if (!length($s_mergedwith)) {
+           if (!length($data->{mergedwith})) {
                &transcript("$gBug is not marked as being merged with any others.\n\n");
                &nochangebug;
            } else {
                 $mergelowstate eq 'locked' || die "$mergelowstate ?";
                $action= "Disconnected #$ref from all other report(s).";
-               @newmergelist= split(/ /,$s_mergedwith);
+               @newmergelist= split(/ /,$data->{mergedwith});
                 $discref= $ref;
+               @bug_affected{@newmergelist} = 1 x @newmergelist;
                 do {
-                    &addmaintainers($s_package);
-                   $s_mergedwith= ($ref == $discref) ? ''
+                    &addmaintainers($data);
+                   $data->{mergedwith}= ($ref == $discref) ? ''
                         : join(' ',grep($_ ne $ref,@newmergelist));
                 } while (&getnextbug);
            }
        }
-    } elsif (m/^merge\s+(\d+(\s+\d+)+)\s*$/i) {
+    } elsif (m/^merge\s+#?(-?\d+(\s+#?-?\d+)+)\s*$/i) {
        $ok++;
-        @tomerge= sort { $a <=> $b } split(/\s+/,$1);
+        @tomerge= sort { $a <=> $b } split(/\s+#?/,$1);
         @newmergelist= ();
        my %tags = ();
+       my %found = ();
+       my %fixed = ();
         &getmerge;
         while (defined($ref= shift(@tomerge))) {
             &transcript("D| checking merge $ref\n") if $dl;
            $ref+= 0;
+           if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
+               $ref = $clonebugs{$ref};
+           }
            next if grep($_ eq $ref,@newmergelist);
            if (!&getbug) { &notfoundbug; @newmergelist=(); last }
+            if (!&checkpkglimit) { &cancelbug; @newmergelist=(); last; }
             &foundbug;
-            &transcript("D| adding $ref ($s_mergedwith)\n") if $dl;
+            &transcript("D| adding $ref ($data->{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; }
+           &checkmatch('package','m_package',$data->{package});
+           &checkmatch('forwarded addr','m_forwarded',$data->{forwarded});
+           $data->{severity} = '$gDefaultSeverity' if $data->{severity} eq '';
+           &checkmatch('severity','m_severity',$data->{severity});
+           &checkmatch('done mark','m_done',length($data->{done}) ? 'done' : 'open');
+           &checkmatch('owner','m_owner',$data->{owner});
+           foreach my $t (split /\s+/, $data->{keywords}) { $tags{$t} = 1; }
+           foreach my $f (@{$data->{found_versions}}) { $found{$f} = 1; }
+           foreach my $f (@{$data->{fixed_versions}}) { $fixed{$f} = 1; }
            if (length($mismatch)) {
                &transcript("Mismatch - only $gBugs in same state can be merged:\n".
                             $mismatch."\n");
                &cancelbug; @newmergelist=(); last;
            }
             push(@newmergelist,$ref);
-            push(@tomerge,split(/ /,$s_mergedwith));
+            push(@tomerge,split(/ /,$data->{mergedwith}));
            &cancelbug;
        }
        if (@newmergelist) {
             @newmergelist= sort { $a <=> $b } @newmergelist;
             $action= "Merged @newmergelist.";
+           delete @fixed{keys %found};
            for $ref (@newmergelist) {
                &getbug || die "huh ?  $gBug $ref disappeared during merge";
-                &addmaintainers($s_package);
-               $s_mergedwith= join(' ',grep($_ ne $ref,@newmergelist));
-               $s_keywords= join(' ', keys %tags);
+                &addmaintainers($data);
+               @bug_affected{@newmergelist} = 1 x @newmergelist;
+               $data->{mergedwith}= join(' ',grep($_ ne $ref,@newmergelist));
+               $data->{keywords}= join(' ', keys %tags);
+               $data->{found_versions}= [sort keys %found];
+               $data->{fixed_versions}= [sort keys %fixed];
                &savebug;
            }
            &transcript("$action\n\n");
@@ -562,8 +688,9 @@ END
        $newbugsneeded = scalar(@newclonedids);
 
        $ref = $origref;
+       $bug_affected{$ref} = 1;
        if (&setbug) {
-           if (length($s_mergedwith)) {
+           if (length($data->{mergedwith})) {
                &transcript("$gBug is marked as being merged with others.\n\n");
                &nochangebug;
            } else {
@@ -584,19 +711,69 @@ END
                &getnextbug;
                my $ohash = get_hashname($origref);
                $ref = $firstref;
+               @bug_affected{@newclonedids} = 1 x @newclonedids;
                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.summary", "db-h/$hash/$ref.summary");
                    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");
+                   &bughook('new', $ref, $data);
 
                    $ref++;
                }
            }
        }
+    } elsif (m/^package\s+(\S.*\S)?\s*$/i) {
+        $ok++;
+       my @pkgs = split /\s+/, $1;
+       if (scalar(@pkgs) > 0) {
+               %limit_pkgs = map { ($_, 1) } @pkgs;
+               &transcript("Ignoring bugs not assigned to: " . 
+                       join(" ", keys(%limit_pkgs)) . "\n\n");
+       } else {
+               %limit_pkgs = ();
+               &transcript("Not ignoring any bugs.\n\n");
+       }
+    } elsif (m/^owner\s+\#?(-?\d+)\s+!$/i ? ($newowner = $replyto, 1) :
+             m/^owner\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($newowner = $2, 1) : 0) {
+        $ok++;
+        $ref = $1;
+       $bug_affected{$ref} = 1;
+        if (&setbug) {
+            if (length $data->{owner}) {
+                $action = "Owner changed from $data->{owner} to $newowner.";
+            } else {
+                $action = "Owner recorded as $newowner.";
+            }
+            if (length $data->{done}) {
+                $extramessage = "(By the way, this $gBug is currently " .
+                                "marked as done.)\n";
+            }
+            do {
+                &addmaintainers($data);
+                $data->{owner} = $newowner;
+            } while (&getnextbug);
+        }
+    } elsif (m/^noowner\s+\#?(-?\d+)$/i) {
+        $ok++;
+        $ref = $1;
+       $bug_affected{$ref} = 1;
+        if (&setbug) {
+            if (length $data->{owner}) {
+                $action = "Removed annotation that $gBug was owned by " .
+                          "$data->{owner}.";
+                do {
+                    &addmaintainers($data);
+                    $data->{owner} = '';
+                } while (&getnextbug);
+            } else {
+                &transcript("$gBug is not marked as having an owner.\n\n");
+                &nochangebug;
+            }
+        }
     } else {
         &transcript("Unknown command or malformed arguments to command.\n\n");
         if (++$unknowns >= 5) {
@@ -642,6 +819,9 @@ if (@maintccs) {
     $maintccs .= "Cc: " . join(",\n    ",@maintccs) . "\n";
 }
 
+# Add Bcc's to subscribed bugs
+push @bcc, map {"bugs=$_\@$gListDomain"} keys %bug_affected;
+
 if (!defined $header{'subject'} || $header{'subject'} eq "") {
   $header{'subject'} = "your mail";
 }
@@ -653,6 +833,8 @@ ${maintccs}Subject: Processed: $header{'subject'}
 In-Reply-To: $header{'message-id'}
 References: $header{'message-id'}
 Message-ID: <handler.s.$nn.transcript\@$gEmailDomain>
+Precedence: bulk
+X-$gProject-PR-Message: transcript
 
 ${transcript}Please contact me if you need assistance.
 
@@ -671,7 +853,7 @@ print(AP
       &sani($header{'from'})."</code>\n".
       "to <code>".&sani($controlrequestaddr)."</code>\n".
       "\3\n".
-      "\7\n",@log,"\n\3\n") || &quit("writing db-h/-1.log: $!");
+      "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/-1.log: $!");
 close(AP) || &quit("open db-h/-1.log: $!");
 &unfilelock;
 utime(time,time,"db-h");
@@ -680,15 +862,16 @@ utime(time,time,"db-h");
 
 unlink("incoming/P$nn") || &quit("unlinking incoming/P$nn: $!");
 
-sub get_addresses {
-    return
-       map { $_->address() }
-       map { Mail::Address->parse($_) } @_;
-}
-
 sub sendmailmessage {
     local ($message,@recips) = @_;
     $message = "X-Loop: $gMaintainerEmail\n" . $message;
+    # The original message received is written out above, so before
+    # writing out the other messages we've sent out, we need to
+    # RFC1522 encode the header.
+    my ($header,$body) = split /\n\n/, $message, 2;
+    $header = encode_rfc1522($header);
+    $message = $header . qq(\n\n). $body;
+
     print "mailing to >@recips<\n" if $debug;
     $c= open(D,"|-");
     defined($c) || &quit("mailing forking for sendmail: $!");
@@ -730,6 +913,14 @@ sub checkmatch {
     }
 }
 
+sub checkpkglimit {
+    if (keys %limit_pkgs and not defined $limit_pkgs{$data->{package}}) {
+        &transcript("$gBug number $ref belongs to package $data->{package}, skipping.\n\n");
+        return 0;
+    }
+    return 1;
+}
+
 # High-level bug manipulation calls
 # Do announcements themselves
 #
@@ -771,7 +962,13 @@ sub setbug {
         &dlex("setbug => 0s");
         return 0;
     }
-    @thisbugmergelist= split(/ /,$s_mergedwith);
+
+    if (!&checkpkglimit) {
+        &cancelbug;
+        return 0;
+    }
+
+    @thisbugmergelist= split(/ /,$data->{mergedwith});
     if (!@thisbugmergelist) {
         &foundbug;
         $manybugs= 0;
@@ -833,7 +1030,7 @@ sub getnextbug {
 #    endmerge
 
 sub notfoundbug { &transcript("$gBug number $ref not found.\n\n"); }
-sub foundbug { &transcript("$gBug#$ref: $s_subject\n"); }
+sub foundbug { &transcript("$gBug#$ref: $data->{subject}\n"); }
 
 sub getmerge {
     &dlen("getmerge");
@@ -854,7 +1051,7 @@ sub endmerge {
 sub getbug {
     &dlen("getbug $ref");
     $lowstate eq 'idle' || die "$state ?";
-    if (&lockreadbug($ref)) {
+    if (($data = &lockreadbug($ref))) {
         $sref= $ref;
         $lowstate= "open";
         &dlex("getbug => 1");
@@ -887,35 +1084,9 @@ sub savebug {
           "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-h/$hash/$ref.log: $!");
+          "\7\n",@{escapelog(@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".
-          "$s_subject\n".
-          "$s_msgid\n".
-          "$s_package\n".
-          "$s_keywords\n".
-          "$s_done\n".
-          "$s_forwarded\n".
-          "$s_mergedwith\n".
-         "$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;
+    unlockwritebug($ref, $data);
     $lowstate= "idle";
     &dlex("savebug");
 }
@@ -935,6 +1106,15 @@ sub transcript {
     $transcript.= $_[0];
 }
 
+sub urlsanit {
+    my $url = shift;
+    $url =~ s/%/%25/g;
+    $url =~ s/\+/%2b/g;
+    my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
+    $url =~ s/([<>&"])/\&$saniarray{$1};/g;
+    return $url;
+}
+
 sub sendlynxdoc {
     &sendlynxdocraw;
     &transcript("\n");
@@ -961,6 +1141,8 @@ Subject: $gProject $gBug help: $description
 References: $header{'message-id'}
 In-Reply-To: $header{'message-id'}
 Message-ID: <handler.s.$nn.help.$midix\@$gEmailDomain>
+Precedence: bulk
+X-$gProject-PR-Message: doc-text $relpath
 
 END
     $ok++;
@@ -969,8 +1151,7 @@ END
 sub sendlynxdocraw {
     local ($relpath,$description) = @_;
     $doc='';
-# 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: $!");
+    open(L,"lynx -nolist -dump http://$gCGIDomain/\Q$relpath\E 2>&1 |") || &quit("fork for lynx: $!");
     while(<L>) { $doc.=$_; }
     $!=0; close(L);
     if ($? == 255 && $doc =~ m/^\n*lynx: Can\'t access start file/) {
@@ -988,6 +1169,8 @@ Subject: $gProject $gBugs information: $description
 References: $header{'message-id'}
 In-Reply-To: $header{'message-id'}
 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
+Precedence: bulk
+X-$gProject-PR-Message: doc-html $relpath
 
 END
          $ok++;
@@ -1002,17 +1185,26 @@ sub addccaddress {
 sub addmaintainers {
     # Data structure is:
     #   maintainer email address &c -> assoc of packages -> assoc of bug#'s
-    my ($p, $addmaint, $pshow);
+    my $data = shift;
+    my ($p, $addmaint);
     &ensuremaintainersloaded;
     $anymaintfound=0; $anymaintnotfound=0;
-    for $p (split(m/[ \t?,()]+/,$_[0])) {
+    for $p (split(m/[ \t?,():]+/, $data->{package})) {
        $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";
+       $p =~ /([a-z0-9.+-]+)/;
+       $p = $1;
+       next unless defined $p;
+       if (defined $gSubscriptionDomain) {
+           if (defined($pkgsrc{$p})) {
+               addbcc("$pkgsrc{$p}\@$gSubscriptionDomain");
+           } else {
+               addbcc("$p\@$gSubscriptionDomain");
+           }
        }
+        if (defined $data->{severity} and defined $gStrongList and
+                isstrongseverity($data->{severity})) {
+            addbcc("$gStrongList\@$gListDomain");
+        }
         if (defined($maintainerof{$p})) {
            $addmaint= $maintainerof{$p};
            &transcript("MR|$addmaint|$p|$ref|\n") if $dl>2;
@@ -1020,10 +1212,18 @@ sub addmaintainers {
            print "maintainer add >$p|$addmaint<\n" if $debug;
         } else { 
            print "maintainer none >$p<\n" if $debug; 
+           &transcript("Warning: Unknown package '$p'\n");
            &transcript("MR|unknown-package|$p|$ref|\n") if $dl>2;
             $maintccreasons{$gUnknownMaintainerEmail}{$p}{$ref}= 1;
        }
     }
+
+    if (length $data->{owner}) {
+        $addmaint = $data->{owner};
+        &transcript("MO|$addmaint|$data->{package}|$ref|\n") if $dl>2;
+        $maintccreasons{$addmaint}{$data->{package}}{$ref} = 1;
+        print "owner add >$data->{package}|$addmaint<\n" if $debug;
+    }
 }
 
 sub ensuremaintainersloaded {
@@ -1049,7 +1249,7 @@ sub ensuremaintainersloaded {
 
     open(SOURCES, "$gPackageSource") || &quit("pkgsrc open: $!");
     while (<SOURCES>) {
-       next unless m/^(\S+)\s+(\S.*\S)\s*$/;
+       next unless m/^(\S+)\s+\S+\s+(\S.*\S)\s*$/;
        my ($a, $b) = ($1, $2);
        $pkgsrc{lc($a)} = $b;
     }
@@ -1084,6 +1284,8 @@ Subject: $gProject $gBugs information: $description
 References: $header{'message-id'}
 In-Reply-To: $header{'message-id'}
 Message-ID: <handler.s.$nn.info.$midix\@$gEmailDomain>
+Precedence: bulk
+X-$gProject-PR-Message: getinfo
 
 $description follows: