]> 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 aaf9be5ac408f047aecb8c76abbb1fd6e6002160..66a2b5e0c668318af84efa4a58d53b04b6232902 100755 (executable)
@@ -1,11 +1,14 @@
 #!/usr/bin/perl
-# $Id: service.in,v 1.43 2001/09/18 19:35:22 joy 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;
+use File::Copy;
+use MIME::Parser;
+
 $config_path = '/org/bugs.debian.org/etc';
 $lib_path = '/org/bugs.debian.org/scripts';
 
@@ -24,8 +27,8 @@ $_=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: $!");
 }    
 
@@ -34,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);
 
-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];
+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 (@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 {
@@ -82,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;
@@ -260,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) {
@@ -282,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,
@@ -301,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/;
@@ -318,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) {
@@ -339,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) {
@@ -353,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) {
@@ -373,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;
@@ -390,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";
@@ -437,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);
@@ -454,7 +493,7 @@ END
         } else {
             &notfoundbug;
         }
-    } elsif (m/^unmerge\s+\#?(\d+)$/i) {
+    } elsif (m/^unmerge\s+\#?(-?\d+)$/i) {
        $ok++;
        $ref= $1;
        if (&setbug) {
@@ -515,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) {
@@ -523,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");
@@ -553,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";
@@ -592,7 +676,7 @@ close(AP) || &quit("open db-h/-1.log: $!");
 &unfilelock;
 utime(time,time,"db-h");
 
-&sendmailmessage($reply,$replyto,@maintccaddrs);
+&sendmailmessage($reply,$replyto,@maintccaddrs,@bcc);
 
 unlink("incoming/P$nn") || &quit("unlinking incoming/P$nn: $!");
 
@@ -608,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: $!");
@@ -672,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;
@@ -906,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;
@@ -915,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;
@@ -948,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 {