]> 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 a3eb9eb23ea220dfbf86a749ac919f9e16b3394a..66a2b5e0c668318af84efa4a58d53b04b6232902 100755 (executable)
@@ -1,11 +1,14 @@
 #!/usr/bin/perl
-# $Id: service.in,v 1.46 2002/01/19 05:39:28 ajt 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';
 
@@ -34,34 +37,57 @@ 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*//) {
-       $v= $1; $v =~ y/A-Z/a-z/;
+       my $v = lc $1;
        print ">$v=$_<\n" if $debug;
-        $header{$v}= $_;
+       $header{$v} = $_;
     } else {
-       print "!>$_<\n" if $debug; 
+       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'};
 }
@@ -88,34 +114,18 @@ $mergelowstate= 'idle';
 $midix=0;    
 $extras="";
 
-#strip blank line(s) after header
-while ( $i <= $#msg && !length( $msg[$i] ) ) { $fwd .= "\n"; $i++; }
-
 my $quickabort = 0;
 
 my $fuckheads = "(" . join("|", @gFuckheads) . ")";
-if ($replyto =~ m/$fuckheads/) {
+if (@gFuckheads and $replyto =~ m/$fuckheads/) {
        &transcript("This service is unavailable.\n\n");
        $quickabort = 1;
 }
 
-#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++; 
-    }
-}
-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++) {
+for ($procline=0; $procline<=$#bodylines; $procline++) {
     $state eq 'idle' || print "$state ?\n";
     $lowstate eq 'idle' || print "$lowstate ?\n";
     $mergelowstate eq 'idle' || print "$mergelowstate ?\n";
@@ -123,7 +133,7 @@ for ($procline=$i; $procline<=$#msg; $procline++) {
          &transcript("Stopping processing here.\n\n");
         last;
     }
-    $_= $msg[$procline]; s/\s+$//;
+    $_= $bodylines[$procline]; s/\s+$//;
     next unless m/\S/; next if m/^\s*\#/;
     &transcript("> $_\n");
     $action= '';
@@ -378,8 +388,9 @@ 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);
         }
@@ -465,6 +476,9 @@ END
     } 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);
@@ -498,7 +512,7 @@ END
                 } 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);
         @newmergelist= ();
@@ -540,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) {
@@ -548,7 +605,7 @@ END
         }
     }
 }
-if ($procline>$#msg) {
+if ($procline>$#bodylines) {
     &transcript(">\nEnd of message, stopping processing here.\n\n");
 }
 if (!$ok && !quickabort) {
@@ -578,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";
@@ -617,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: $!");
 
@@ -633,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: $!");
@@ -948,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;
@@ -981,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 {