]> 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 4a8b5cdc98ddb04d8a846f1d7eba1b23489c4ca5..66a2b5e0c668318af84efa4a58d53b04b6232902 100755 (executable)
@@ -1,26 +1,34 @@
 #!/usr/bin/perl
-# $Id: service.in,v 1.39 2001/08/16 07:22:21 doogie 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'};
+use File::Copy;
+use MIME::Parser;
+
+$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'};
+
 chdir("$gSpoolDir") || die "chdir spool: $!\n";
 
 # open(DEBUG,">&4");
 open DEBUG, ">/dev/null";
 $debug = 0;
+umask(002);
 
 $_=shift;
 m/^[RC]\.\d+$/ || &quit("bad argument");
 $control= m/C/;
 $nn= $_;
-if (!rename("incoming/G$nn","incoming/P$nn")) 
-{      $_=$!.'';  m/no such file or directory/i && exit 0;
+if (!rename("incoming/G$nn","incoming/P$nn")) {
+    $_=$!.'';  m/no such file or directory/i && exit 0;
     &quit("renaming to lock: $!");
 }    
 
@@ -29,37 +37,66 @@ open(M,"incoming/P$nn");
 @msg=@log;
 close(M);
 
-grep((s/\n$//,s/\s+$//),@msg);
+chomp @msg;
 
 print "###\n",join("##\n",@msg),"\n###\n" if $debug;
 
-chop($tdate= `date -u '+%a, %d %h %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)) };
+
+# 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, $_;
+    }
+
+    @bodylines = @msg[$i..$#msg];
+}
 
-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];
+for (@headerlines) {
+    s/\n\s/ /g;
+    print ">$_<\n" if $debug;
+    if (s/^(\S+):\s*//) {
+       my $v = lc $1;
+       print ">$v=$_<\n" if $debug;
+       $header{$v} = $_;
+    } else {
+       print "!>$_<\n" if $debug;
     }
-       print ">$_<\n" if $debug;
-    if (s/^(\S+):\s*//) 
-       {       $v= $1; $v =~ y/A-Z/a-z/;
-               print ">$v=$_<\n" if $debug;
-        $header{$v}= $_;
-    } else { 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");
-delete $header{'reply-to'} if ( defined($header{'reply-to'}) && $header{'reply-to'} =~ m/^\s*$/ );
+
+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 {
@@ -77,30 +114,31 @@ $mergelowstate= 'idle';
 $midix=0;    
 $extras="";
 
-#strip blank line(s) after header
-while ( $i <= $#msg && !length( $msg[$i] ) ) { $fwd .= "\n"; $i++; }
+my $quickabort = 0;
 
-#strip, if exists, mime header
-if ( $msg[$i] =~ /^This is a multi-part message in MIME format./ )
-{      while ( $i <= $#msg && length( $msg[$i] ) ) { $fwd .= $msg[$i] . "\n"; $i++; }
-       while ( $i <= $#msg && !length( $msg[$i] ) ) { $fwd .= "\n"; $i++; }
+my $fuckheads = "(" . join("|", @gFuckheads) . ")";
+if (@gFuckheads and $replyto =~ m/$fuckheads/) {
+       &transcript("This service is unavailable.\n\n");
+       $quickabort = 1;
 }
-if ( $msg[$i] =~ /^--/ || $msg[$i] =~ /^\s*$/ )
-{      while ( $i <= $#msg && length( $msg[$i] ) ) { $fwd .= $msg[$i]; $i++; }
-       while ( $i <= $#msg && !length( $msg[$i] ) ) { $fwd .= "\n"; $i++; }
-}      
 
+my %clonebugs = ();
+my @bcc = ();
 
-for ($procline=$i; $procline<=$#msg; $procline++) 
-{      $state eq 'idle' || print "$state ?\n";
+for ($procline=0; $procline<=$#bodylines; $procline++) {
+    $state eq 'idle' || print "$state ?\n";
     $lowstate eq 'idle' || print "$lowstate ?\n";
     $mergelowstate eq 'idle' || print "$mergelowstate ?\n";
-    $_= $msg[$procline]; s/\s+$//;
+    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/i || m/^quit/i || m/^--/ || m/^thank/i) 
-       {       &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+)$/i && $1 >= 0 && $1 <= 1000) {
         $dl= $1+0;
@@ -255,7 +293,8 @@ END
             &transcript("Too many unknown commands, stopping here.\n\n");
             last;
         }
-    } elsif (m/^close\s+\#?(\d+)$/i) {
+#### interesting ones start here
+    } elsif (m/^close\s+\#?(-?\d+)$/i) {
        $ok++;
        $ref= $1;
        if (&setbug) {
@@ -277,6 +316,7 @@ Subject: $gBug#$ref acknowledged by developer
 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
 #$ref: $s_subject,
@@ -286,8 +326,7 @@ 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 myself.
+in case you haven't already. If not, please contact them directly.
 
 $gMaintainer
 (administrator, $gProject $gBugs database)
@@ -297,7 +336,7 @@ END
                 } while (&getnextbug);
             }
         }
-    } elsif (m/^reassign\s+\#?(\d+)\s+(\S.*\S)$/i) {
+    } elsif (m/^reassign\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
         $ok++;
         $ref= $1; $newpackage= $2;
        $newpackage =~ y/A-Z/a-z/;
@@ -314,10 +353,10 @@ END
                 $s_package= $newpackage;
             } while (&getnextbug);
         }
-    } 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) {
+    } 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) {
@@ -335,7 +374,7 @@ END
                 } while (&getnextbug);
             }
         }
-    } elsif (m/^forwarded\s+\#?(\d+)\s+(\S.*\S)$/i) {
+    } elsif (m/^forwarded\s+\#?(-?\d+)\s+(\S.*\S)$/i) {
         $ok++;
         $ref= $1; $whereto= $2;
         if (&setbug) {
@@ -349,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+)$/i) {
+    } elsif (m/^notforwarded\s+\#?(-?\d+)$/i) {
         $ok++;
         $ref= $1;
         if (&setbug) {
@@ -369,8 +409,8 @@ END
                 } while (&getnextbug);
             }
         }
-    } elsif (m/^severity\s+\#?(\d+)\s+([-0-9a-z]+)$/i ||
-       m/^priority\s+\#?(\d+)\s+([-0-9a-z]+)$/i) {
+    } elsif (m/^severity\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i ||
+       m/^priority\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i) {
         $ok++;
         $ref= $1;
         $newseverity= $2;
@@ -386,7 +426,7 @@ END
                 $s_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;
        $addsub = "add";
@@ -433,9 +473,12 @@ END
                $s_keywords =~ s/\s*$//;
             } while (&getnextbug);
        }
-    } elsif (m/^retitle\s+\#?(\d+)\s+(\S.*\S)\s*$/i) {
+    } 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);
@@ -450,7 +493,7 @@ END
         } else {
             &notfoundbug;
         }
-    } elsif (m/^unmerge\s+\#?(\d+)$/i) {
+    } elsif (m/^unmerge\s+\#?(-?\d+)$/i) {
        $ok++;
        $ref= $1;
        if (&setbug) {
@@ -511,6 +554,49 @@ END
            &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) {
@@ -519,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");
@@ -549,10 +635,12 @@ for $maint (keys %maintccreasons) {
     push(@maintccs,"$maint ($reasonstring)");
     push(@maintccaddrs,"$maint");
 }
+
+$maintccs = ""; 
 if (@maintccs) {
     &transcript("MC|@maintccs|\n") if $dl>2;
-    $maintccs= "Cc: ".join(",\n    ",@maintccs)."\n";
-} else { $maintccs = ""; }
+    $maintccs .= "Cc: " . join(",\n    ",@maintccs) . "\n";
+}
 
 if (!defined $header{'subject'} || $header{'subject'} eq "") {
   $header{'subject'} = "your mail";
@@ -575,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".
@@ -583,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: $!");
 
@@ -604,7 +692,7 @@ sub sendmailmessage {
     $c= open(D,"|-");
     defined($c) || &quit("mailing forking for sendmail: $!");
     if (!$c) { # ie, we are the child process
-        exec '/usr/lib/sendmail','-f'."$gMaintainerEmail",'-odq','-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: $!");
@@ -668,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;
@@ -782,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".
@@ -802,10 +899,10 @@ 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".
@@ -901,8 +998,8 @@ sub addccaddress {
     $maintccreasons{$cca}{''}{$ref}= 1;
 }
 
-sub addmaintainers 
-{      # Data structure is:
+sub addmaintainers {
+    # Data structure is:
     #   maintainer email address &c -> assoc of packages -> assoc of bug#'s
     my ($p, $addmaint, $pshow);
     &ensuremaintainersloaded;
@@ -910,6 +1007,11 @@ sub addmaintainers
     for $p (split(m/[ \t?,()]+/,$_[0])) {
        $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;
@@ -943,6 +1045,14 @@ sub ensuremaintainersloaded {
         $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 {