]> git.donarmstrong.com Git - debbugs.git/blobdiff - scripts/service
Strip BOM before regexes involving spaces (closes: #488554)
[debbugs.git] / scripts / service
index df289c9c40406fa20a2df0c83547891c143693b8..94b2571b5a08dca6fdc121b47f8bba4c68fb81e2 100755 (executable)
@@ -17,7 +17,7 @@ use Params::Validate qw(:types validate_with);
 
 use Debbugs::Common qw(:util :quit :misc :lock);
 
-use Debbugs::Status qw(:read :status :write :versions);
+use Debbugs::Status qw(:read :status :write :versions :hook);
 
 use Debbugs::MIME qw(decode_rfc1522 encode_rfc1522);
 use Debbugs::Mail qw(send_mail_message);
@@ -29,7 +29,7 @@ use Debbugs::Versions::Dpkg;
 use Debbugs::Status qw(splitpackages);
 
 use Debbugs::CGI qw(html_escape);
-use Debbugs::Control qw(:archive :log :owner);
+use Debbugs::Control qw(:all);
 use Debbugs::Log qw(:misc);
 use Debbugs::Text qw(:templates);
 
@@ -84,6 +84,7 @@ for (@headerlines) {
     }
 }
 $header{'message-id'} ||= '';
+$header{subject} ||= '';
 
 grep(s/\s+$//,@bodylines);
 
@@ -107,7 +108,7 @@ if ( defined($header{'reply-to'}) && $header{'reply-to'} ne "" ) {
 
 # This is an error counter which should be incremented every time there is an error.
 my $errors = 0;
-my $controlrequestaddr= ($control ? 'control' : 'request').$config{email_domain};
+my $controlrequestaddr= ($control ? 'control' : 'request').'@'.$config{email_domain};
 my $transcript_scalar = '';
 my $transcript = IO::Scalar->new(\$transcript_scalar) or
      die "Unable to create new IO::Scalar";
@@ -175,6 +176,9 @@ for ($procline=0; $procline<=$#bodylines; $procline++) {
         last;
     }
     $_= $bodylines[$procline]; s/\s+$//;
+    # Remove BOM markers from UTF-8 strings
+    # Fixes #488554
+    s/\xef\xbb\xbf//g;
     next unless m/\S/;
     print {$transcript} "> $_\n";
     next if m/^\s*\#/;
@@ -387,12 +391,14 @@ END
            Debbugs::User::read_usertags(\%ut, $user);
             my @oldtags = (); my @newtags = (); my @badtags = ();
            my %chtags;
-           for my $t (split /[,\s]+/, $tags) {
-               if ($t =~ m/^[a-zA-Z0-9.+\@-]+$/) {
-                   $chtags{$t} = 1;
-               } else {
-                   push @badtags, $t;
-               }
+           if (defined $tags and length $tags) {
+                for my $t (split /[,\s]+/, $tags) {
+                     if ($t =~ m/^[a-zA-Z0-9.+\@-]+$/) {
+                          $chtags{$t} = 1;
+                     } else {
+                          push @badtags, $t;
+                     }
+                }
            }
            if (@badtags) {
                 print {$transcript} "Ignoring illegal tag/s: ".join(', ', @badtags).".\nPlease use only alphanumerics, at, dot, plus and dash.\n";
@@ -451,9 +457,11 @@ END
                 do {
                   $affected_packages{$data->{package}} = 1;
                    add_recipients(data => $data,
-                                  recipients => \%recipients,
-                                  actions_taken => {done => 1},
-                                 );
+                                 recipients => \%recipients,
+                                 actions_taken => {done => 1},
+                                 transcript   => $transcript,
+                                 ($dl > 0 ? (debug => $transcript):()),
+                                );
                    $data->{done}= $replyto;
                     my @keywords= split ' ', $data->{keywords};
                    my $extramessage = '';
@@ -509,13 +517,21 @@ END
             }
             do {
                $affected_packages{$data->{package}} = 1;
-                add_recipients(data => $data, recipients => \%recipients);
+                add_recipients(data => $data,
+                              recipients => \%recipients,
+                              transcript   => $transcript,
+                              ($dl > 0 ? (debug => $transcript):()),
+                             );
                 $data->{package}= $newpackage;
                 $data->{found_versions}= [];
                 $data->{fixed_versions}= [];
                 # TODO: what if $newpackage is a source package?
                 addfoundversions($data, $data->{package}, $version, 'binary');
-                add_recipients(data => $data, recipients => \%recipients);
+                add_recipients(data => $data,
+                              recipients => \%recipients,
+                              transcript   => $transcript,
+                              ($dl > 0 ? (debug => $transcript):()),
+                             );
             } while (&getnextbug);
         }
     } elsif (m/^reopen\s+\#?(-?\d+)$/i ? ($noriginator='', 1) :
@@ -538,7 +554,11 @@ END
                         "$gBug reopened, originator set to $noriginator.";
                 do {
                    $affected_packages{$data->{package}} = 1;
-                    add_recipients(data => $data, recipients => \%recipients);
+                    add_recipients(data => $data,
+                                  recipients => \%recipients,
+                                  transcript   => $transcript,
+                                  ($dl > 0 ? (debug => $transcript):()),
+                                 );
                     $data->{originator}= $noriginator eq '' ?  $data->{originator} : $noriginator;
                     $data->{fixed_versions}= [];
                     $data->{done}= '';
@@ -563,7 +583,11 @@ END
                         "$gBug reopened.";
                 do {
                     $affected_packages{$data->{package}} = 1;
-                   add_recipients(data => $data, recipients => \%recipients);
+                   add_recipients(data => $data,
+                                  recipients => \%recipients,
+                                  transcript   => $transcript,
+                                  ($dl > 0 ? (debug => $transcript):()),
+                                 );
                     # 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
@@ -603,7 +627,11 @@ END
             }
             do {
                 $affected_packages{$data->{package}} = 1;
-               add_recipients(data => $data, recipients => \%recipients);
+               add_recipients(data => $data,
+                              recipients => \%recipients,
+                              transcript   => $transcript,
+                              ($dl > 0 ? (debug => $transcript):()),
+                             );
                 removefoundversions($data, $data->{package}, $version, 'binary');
             } while (&getnextbug);
        }
@@ -621,7 +649,11 @@ END
                            "$gBug reopened.";
                 do {
                     $affected_packages{$data->{package}} = 1;
-                   add_recipients(data => $data, recipients => \%recipients);
+                   add_recipients(data => $data,
+                                  recipients => \%recipients,
+                                  transcript   => $transcript,
+                                  ($dl > 0 ? (debug => $transcript):()),
+                                 );
                     addfixedversions($data, $data->{package}, $version, 'binary');
               } while (&getnextbug);
        }
@@ -639,7 +671,11 @@ END
                            "$gBug reopened.";
                 do {
                     $affected_packages{$data->{package}} = 1;
-                   add_recipients(data => $data, recipients => \%recipients);
+                   add_recipients(data => $data,
+                                  recipients => \%recipients,
+                                  transcript   => $transcript,
+                                  ($dl > 0 ? (debug => $transcript):()),
+                                 );
                     removefixedversions($data, $data->{package}, $version, 'binary');
               } while (&getnextbug);
        }
@@ -660,7 +696,11 @@ END
             if (&checkpkglimit) {
                 &foundbug;
                 $affected_packages{$data->{package}} = 1;
-               add_recipients(data => $data, recipients => \%recipients);
+               add_recipients(data => $data,
+                              recipients => \%recipients,
+                              transcript   => $transcript,
+                              ($dl > 0 ? (debug => $transcript):()),
+                             );
                 $oldsubmitter= $data->{originator};
                 $data->{originator}= $newsubmitter;
                 $action= "Changed $gBug submitter from $oldsubmitter to $newsubmitter.";
@@ -724,6 +764,8 @@ END
                add_recipients(data => $data,
                               recipients => \%recipients,
                               actions_taken => {forwarded => 1},
+                              transcript   => $transcript,
+                              ($dl > 0 ? (debug => $transcript):()),
                              );
                $data->{forwarded}= $whereto;
             } while (&getnextbug);
@@ -740,7 +782,11 @@ END
     $action= "Removed annotation that $gBug had been forwarded to $data->{forwarded}.";
                 do {
                     $affected_packages{$data->{package}} = 1;
-                   add_recipients(data => $data, recipients => \%recipients);
+                   add_recipients(data => $data,
+                                  recipients => \%recipients,
+                                  transcript   => $transcript,
+                                  ($dl > 0 ? (debug => $transcript):()),
+                                 );
                     $data->{forwarded}= '';
                 } while (&getnextbug);
             }
@@ -765,7 +811,11 @@ END
            $action= "Severity set to \`$newseverity' from \`$printseverity'";
            do {
                 $affected_packages{$data->{package}} = 1;
-               add_recipients(data => $data, recipients => \%recipients);
+               add_recipients(data => $data,
+                              recipients => \%recipients,
+                              transcript   => $transcript,
+                              ($dl > 0 ? (debug => $transcript):()),
+                             );
                 if (defined $gStrongList and isstrongseverity($newseverity)) {
                     addbcc("$gStrongList\@$gListDomain");
                 }
@@ -813,7 +863,11 @@ END
            }
            do {
                 $affected_packages{$data->{package}} = 1;
-               add_recipients(data => $data, recipients => \%recipients);
+               add_recipients(data => $data,
+                              recipients => \%recipients,
+                              transcript   => $transcript,
+                              ($dl > 0 ? (debug => $transcript):()),
+                             );
                $data->{keywords} = '' if ($addsub eq "set");
                # Allow removing obsolete tags.
                if ($addsub eq "sub") {
@@ -835,7 +889,7 @@ END
        $ok++;
        my $bugnum = $2; my $blockers = $4;
        my $addsub = "add";
-       $addsub = "sub" if ($1 eq "un");
+       $addsub = "sub" if (defined $1 and $1 eq "un");
        if ($bugnum =~ m/^-\d+$/ && defined $clonebugs{$bugnum}) {
             $bugnum = $clonebugs{$bugnum};
        }
@@ -897,7 +951,11 @@ END
            my %addedblocks;
            do {
                 $affected_packages{$data->{package}} = 1;
-               add_recipients(data => $data, recipients => \%recipients);
+               add_recipients(data => $data,
+                              recipients => \%recipients,
+                              transcript   => $transcript,
+                              ($dl > 0 ? (debug => $transcript):()),
+                             );
                my @oldblockerlist = split ' ', $data->{blockedby};
                $data->{blockedby} = '' if ($addsub eq "set");
                foreach my $b (@okayblockers) {
@@ -947,7 +1005,11 @@ END
             if (&checkpkglimit) {
                 &foundbug;
                 $affected_packages{$data->{package}} = 1;
-               add_recipients(data => $data, recipients => \%recipients);
+               add_recipients(data => $data,
+                              recipients => \%recipients,
+                              transcript   => $transcript,
+                              ($dl > 0 ? (debug => $transcript):()),
+                             );
                my $oldtitle = $data->{subject};
                 $data->{subject}= $newtitle;
                 $action= "Changed $gBug title to `$newtitle' from `$oldtitle'.";
@@ -979,7 +1041,11 @@ END
                @bug_affected{@newmergelist} = 1 x @newmergelist;
                 do {
                     $affected_packages{$data->{package}} = 1;
-                   add_recipients(data => $data, recipients => \%recipients);
+                   add_recipients(data => $data,
+                                  recipients => \%recipients,
+                                  transcript   => $transcript,
+                                  ($dl > 0 ? (debug => $transcript):()),
+                                 );
                    $data->{mergedwith}= ($ref == $discref) ? ''
                         : join(' ',grep($_ ne $ref,@newmergelist));
                 } while (&getnextbug);
@@ -1013,6 +1079,8 @@ END
            &checkmatch('blocked-by','m_blockedby',$data->{blockedby},@newmergelist);
            &checkmatch('done mark','m_done',length($data->{done}) ? 'done' : 'open',@newmergelist);
            &checkmatch('owner','m_owner',$data->{owner},@newmergelist);
+           &checkmatch('summary','m_summary',$data->{summary},@newmergelist);
+           &checkmatch('affects','m_affects',$data->{affects},@newmergelist);
            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; }
@@ -1033,7 +1101,11 @@ END
            for $ref (@newmergelist) {
                &getbug || die "huh ?  $gBug $ref disappeared during merge";
                 $affected_packages{$data->{package}} = 1;
-               add_recipients(data => $data, recipients => \%recipients);
+               add_recipients(data => $data,
+                              recipients => \%recipients,
+                              transcript   => $transcript,
+                              ($dl > 0 ? (debug => $transcript):()),
+                             );
                @bug_affected{@newmergelist} = 1 x @newmergelist;
                $data->{mergedwith}= join(' ',grep($_ != $ref,@newmergelist));
                $data->{keywords}= join(' ', keys %tags);
@@ -1095,13 +1167,17 @@ END
            for $ref (@newmergelist) {
                &getbug || die "huh ?  $gBug $ref disappeared during merge";
                 $affected_packages{$data->{package}} = 1;
-               add_recipients(data => $data, recipients => \%recipients);
+               add_recipients(data => $data,
+                              recipients => \%recipients,
+                              transcript   => $transcript,
+                              ($dl > 0 ? (debug => $transcript):()),
+                             );
                @bug_affected{@newmergelist} = 1 x @newmergelist;
                $data->{mergedwith}= join(' ',grep($_ != $ref,@newmergelist));
                $data->{keywords}= join(' ', keys %tags);
                $data->{found_versions}= [sort keys %found];
                $data->{fixed_versions}= [sort keys %fixed];
-               my @field_list = qw(forwarded package severity blocks blockedby owner done);
+               my @field_list = qw(forwarded package severity blocks blockedby owner done affects summary);
                @{$data}{@field_list} = @{$master_bug_data}{@field_list};
                &savebug;
            }
@@ -1184,9 +1260,57 @@ END
                %limit_pkgs = ();
                print {$transcript} "Not ignoring any bugs.\n\n";
        }
+    } elsif (m/^affects?\s+\#?(-?\d+)(?:\s+((?:[=+-])?)\s*(\S.*)?)?\s*$/i) {
+       $ok++;
+        $ref = $1;
+       my $add_remove = $2 || '';
+       my $packages = $3 || '';
+       $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
+       $bug_affected{$ref} = 1;
+       eval {
+            affects(bug          => $ref,
+                    transcript   => $transcript,
+                    ($dl > 0 ? (debug => $transcript):()),
+                    requester    => $header{from},
+                    request_addr => $controlrequestaddr,
+                    message      => \@log,
+                    recipients   => \%recipients,
+                    packages     => [splitpackages($3)],
+                    ($add_remove eq '+'?(add => 1):()),
+                    ($add_remove eq '-'?(remove => 1):()),
+                   );
+       };
+       if ($@) {
+           $errors++;
+           print {$transcript} "Failed to give $ref a summary: $@";
+       }
+
+    } elsif (m/^summary\s+\#?(-?\d+)\s*(\d+|)\s*$/i) {
+       $ok++;
+        $ref = $1;
+       my $summary_msg = length($2)?$2:undef;
+       $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
+       $bug_affected{$ref} = 1;
+       eval {
+           summary(bug          => $ref,
+                   transcript   => $transcript,
+                   ($dl > 0 ? (debug => $transcript):()),
+                   requester    => $header{from},
+                   request_addr => $controlrequestaddr,
+                   message      => \@log,
+                   recipients   => \%recipients,
+                   summary      => $summary_msg,
+                  );
+       };
+       if ($@) {
+           $errors++;
+           print {$transcript} "Failed to give $ref a summary: $@";
+       }
+
     } elsif (m/^owner\s+\#?(-?\d+)\s+((?:\S.*\S)|\!)\s*$/i) {
        $ok++;
         $ref = $1;
+       $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
        my $newowner = $2;
        if ($newowner eq '!') {
            $newowner = $replyto;
@@ -1203,9 +1327,14 @@ END
                  owner        => $newowner,
                 );
        };
+       if ($@) {
+           $errors++;
+           print {$transcript} "Failed to mark $ref as having an owner: $@";
+       }
     } elsif (m/^noowner\s+\#?(-?\d+)\s*$/i) {
         $ok++;
         $ref = $1;
+       $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
        $bug_affected{$ref} = 1;
        eval {
            owner(bug          => $ref,
@@ -1225,6 +1354,7 @@ END
     } elsif (m/^unarchive\s+#?(\d+)$/i) {
         $ok++;
         $ref = $1;
+        $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
         $bug_affected{$ref} = 1;
         eval {
              bug_unarchive(bug        => $ref,
@@ -1243,6 +1373,7 @@ END
     } elsif (m/^archive\s+#?(\d+)$/i) {
         $ok++;
         $ref = $1;
+        $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
         $bug_affected{$ref} = 1;
         eval {
              bug_archive(bug => $ref,
@@ -1401,20 +1532,23 @@ sub message_body_template{
 }
 
 sub sendhelp {
-        &sendtxthelpraw("bug-log-mailserver.txt","instructions for request\@$gEmailDomain");
-        &sendtxthelpraw("bug-maint-mailcontrol.txt","instructions for control\@$gEmailDomain")
-            if $control;
+     if ($control) {
+         &sendtxthelpraw("bug-maint-mailcontrol.txt","instructions for control\@$gEmailDomain")
+     }
+     else {
+         &sendtxthelpraw("bug-log-mailserver.txt","instructions for request\@$gEmailDomain");
+     }
 }
 
 #sub unimplemented {
 #    print {$transcript} "Sorry, command $_[0] not yet implemented.\n\n";
 #}
-
+our %checkmatch_values;
 sub checkmatch {
     my ($string,$mvarname,$svarvalue,@newmergelist) = @_;
     my ($mvarvalue);
     if (@newmergelist) {
-        eval "\$mvarvalue= \$$mvarname";
+       $mvarvalue = $checkmatch_values{$mvarname};
         print {$transcript} "D| checkmatch \`$string' /$mvarname/$mvarvalue/$svarvalue/\n"
             if $dl;
         $mismatch .=
@@ -1425,7 +1559,7 @@ sub checkmatch {
     } else {
         print {$transcript} "D| setupmatch \`$string' /$mvarname/$svarvalue/\n"
              if $dl;
-        eval "\$$mvarname= \$svarvalue";
+        $checkmatch_values{$mvarname} = $svarvalue;
     }
 }