X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=scripts%2Fservice.in;h=28482218d7fdd543acc88a832f6660d1ebe8423e;hb=7491c13db123956338883b59b4518b725cad76c9;hp=0f1d9ade85defba6dba6b14a6c16b1a265e94a59;hpb=5b07a00be15ac3ce34a2aea8bcf11de9be3c9cd0;p=debbugs.git diff --git a/scripts/service.in b/scripts/service.in index 0f1d9ad..2848221 100755 --- a/scripts/service.in +++ b/scripts/service.in @@ -1,12 +1,14 @@ #!/usr/bin/perl -# $Id: service.in,v 1.105 2005/07/24 17:31:18 cjwatson Exp $ +# $Id: service.in,v 1.118 2005/10/19 01:22:14 don Exp $ # # Usage: service .nn # Temps: incoming/P.nn use File::Copy; use MIME::Parser; -use Debbugs::MIME qw(decode_rfc1522); +use Debbugs::MIME qw(decode_rfc1522 encode_rfc1522); +use Debbugs::Mail qw(send_mail_message); +use Debbugs::User; $config_path = '/etc/debbugs'; $lib_path = '/usr/lib/debbugs'; @@ -47,6 +49,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}; @@ -72,12 +77,13 @@ if ($entity and $entity->head->tags) { } for (@headerlines) { + $_ = decode_rfc1522($_); s/\n\s/ /g; print ">$_<\n" if $debug; if (s/^(\S+):\s*//) { my $v = lc $1; print ">$v=$_<\n" if $debug; - $header{$v} = decode_rfc1522($_); + $header{$v} = $_; } else { print "!>$_<\n" if $debug; } @@ -126,6 +132,13 @@ $mergelowstate= 'idle'; $midix=0; $extras=""; +my $user = $replyto; +$user =~ s/,.*//; +$user =~ s/^.*<(.*)>.*$/$1/; +$user =~ s/[(].*[)]//; +$user =~ s/^\s*(\S+)\s+.*$/$1/; +$user = "" unless (Debbugs::User::is_valid_user($user)); + my $quickabort = 0; my $fuckheads = "(" . join("|", @gFuckheads) . ")"; @@ -155,7 +168,7 @@ for ($procline=0; $procline<=$#bodylines; $procline++) { &transcript("> $_\n"); next if m/^\s*\#/; $action= ''; - if (m/^stop/i || m/^quit/i || m/^--/ || m/^thank/i) { + if (m/^stop/i || m/^quit/i || m/^--/ || m/^thank/i || m/^kthxbye/i) { &transcript("Stopping processing here.\n\n"); last; } elsif (m/^debug\s+(\d+)$/i && $1 >= 0 && $1 <= 1000) { @@ -231,6 +244,133 @@ END soon: UNSUBSCRIBE_TEXT soon: MAILINGLISTS_TEXT END + } elsif (m/^user\s+(\S+)\s*$/i) { + my $newuser = $1; + if (Debbugs::User::is_valid_user($newuser)) { + my $olduser = ($user ne "" ? " (was $user)" : ""); + &transcript("Setting user to $newuser$olduser.\n"); + $user = $newuser; + } else { + &transcript("Selected user id ($newuser) invalid, sorry\n"); + $user = ""; + } + } elsif (m/^usercategory\s+(\S+)(\s+\[hidden\])?\s*$/i) { + $ok++; + my $catname = $1; + my $hidden = ($2 ne ""); + + my $prefix = ""; + my @cats; + my $bad = 0; + my $catsec = 0; + while (++$procline <= $#bodylines) { + unless ($bodylines[$procline] =~ m/^\s*([*+])\s*(\S.*)$/) { + $procline--; + last; + } + &transcript("> $bodylines[$procline]\n"); + next if $bad; + my ($o, $txt) = ($1, $2); + if ($#cats == -1 && $o eq "+") { + &transcript("User defined category specification must start with a category name. Skipping.\n\n"); + $bad = 1; + next; + } + if ($o eq "+") { + unless (ref($cats[-1]) eq "HASH") { + $cats[-1] = { "nam" => $cats[-1], + "pri" => [], "ttl" => [] }; + } + $catsec++; + my ($desc, $ord, $op); + if ($txt =~ m/^(.*\S)\s*\[((\d+):\s*)?\]\s*$/) { + $desc = $1; $ord = $3; $op = ""; + } elsif ($txt =~ m/^(.*\S)\s*\[((\d+):\s*)?(\S+)\]\s*$/) { + $desc = $1; $ord = $3; $op = $4; + } elsif ($txt =~ m/^([^[\s]+)\s*$/) { + $desc = ""; $op = $1; + } else { + &transcript("Unrecognised syntax for category section. Skipping.\n\n"); + $bad = 1; + next; + } + $ord = 999 unless defined $ord; + + if ($op) { + push @{$cats[-1]->{"pri"}}, $prefix . $op; + push @{$cats[-1]->{"ttl"}}, $desc; + push @ords, "$ord $catsec"; + } else { + @cats[-1]->{"def"} = $desc; + push @ords, "$ord DEF"; + $catsec--; + } + @ords = sort { my ($a1, $a2, $b1, $b2) = split / /, "$a $b"; + $a1 <=> $b1 || $a2 <=> $b2; } @ords; + $cats[-1]->{"ord"} = [map { m/^.* (\S+)/; $1 eq "DEF" ? $catsec + 1 : $1 } @ords]; + } elsif ($o eq "*") { + $catsec = 0; + my ($name); + if ($txt =~ m/^(.*\S)(\s*\[(\S+)\])\s*$/) { + $name = $1; $prefix = $3; + } else { + $name = $txt; $prefix = ""; + } + push @cats, $name; + } + } + # XXX: got @cats, now do something with it + my $u = Debbugs::User::get_user($user); + if (@cats) { + &transcript("Added usercategory $catname.\n\n"); + $u->{"categories"}->{$catname} = [ @cats ]; + } else { + &transcript("Removed usercategory $catname.\n\n"); + delete $u->{"categories"}->{$catname}; + } + $u->write(); + } elsif (m/^usertags?\s+\#?(-?\d+)\s+(([=+-])\s*)?(\S.*)?$/i) { + $ok++; + $ref = $1; $addsubcode = $3 || "+"; $tags = $4; + if ($user eq "") { + &transcript("No valid user selected\n"); + } else { + my %ut; + 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 (@badtags) { + &transcript("Ignoring illegal tag/s: ".join(', ', @badtags).".\nPlease use only alphanumerics, at, dot, plus and dash.\n"); + } + for my $t (keys %chtags) { + $ut{$t} = [] unless defined $ut{$t}; + } + for my $t (keys %ut) { + my %res = map { ($_, 1) } @{$ut{$t}}; + push @oldtags, $t if defined $res{$ref}; + my $addop = ($addsubcode eq "+" or $addsubcode eq "="); + my $del = (defined $chtags{$t} ? $addsubcode eq "-" + : $addsubcode eq "="); + $res{$ref} = 1 if ($addop && defined $chtags{$t}); + delete $res{$ref} if ($del); + push @newtags, $t if defined $res{$ref}; + $ut{$t} = [ sort { $a <=> $b } (keys %res) ]; + } + if (@oldtags == 0) { + &transcript("There were no usertags set.\n"); + } else { + &transcript("Usertags were: " . join(" ", @oldtags) . ".\n"); + } + &transcript("Usertags are now: " . join(" ", @newtags) . ".\n"); + Debbugs::User::write_usertags(\%ut, $user); + } } elsif (!$control) { &transcript(<{fixed_versions}}) { &transcript("'reopen' is deprecated when a bug has been closed with a version;\nuse 'found' or 'submitter' as appropriate instead.\n"); @@ -374,7 +517,7 @@ END (reverse @{$data->{fixed_versions}})[0]; # TODO: what if $data->{package} is a source package? addfoundversions($data, $data->{package}, $version, 'binary'); - if (defined $lastfixed and $version eq $lastfixed) { + if (defined $lastfixed and not grep { $_ eq $lastfixed } @{$data->{fixed_versions}}) { $data->{done} = ''; } } else { @@ -386,10 +529,25 @@ END } 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}; } @@ -421,7 +579,9 @@ The submitter address recorded for your $gBug report #$ref: $data->{subject} has been changed. -The new submitter address for this report is +The old submitter address for this report was +$oldsubmitter. +The new submitter address is $newsubmitter. This change was made by @@ -442,6 +602,7 @@ END } elsif (m/^forwarded\s+\#?(-?\d+)\s+(\S.*\S)$/i) { $ok++; $ref= $1; $whereto= $2; + $bug_affected{$ref}=1; if (&setbug) { if (length($data->{forwarded})) { $action= "Forwarded-to-address changed from $data->{forwarded} to $whereto."; @@ -462,6 +623,7 @@ END } elsif (m/^notforwarded\s+\#?(-?\d+)$/i) { $ok++; $ref= $1; + $bug_affected{$ref}=1; if (&setbug) { if (!length($data->{forwarded})) { &transcript("$gBug is not marked as having been forwarded.\n\n"); @@ -478,6 +640,7 @@ 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". @@ -488,7 +651,7 @@ END } elsif (&setbug) { $printseverity= $data->{severity}; $printseverity= "$gDefaultSeverity" if $printseverity eq ''; - $action= "Severity set to \`$newseverity'."; + $action= "Severity set to \`$newseverity' from \`$printseverity'"; do { &addmaintainers($data); if (defined $gStrongList and isstrongseverity($newseverity)) { @@ -500,6 +663,7 @@ END } 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 "-"); @@ -551,9 +715,106 @@ END $data->{keywords} =~ s/\s*$//; } while (&getnextbug); } + } elsif (m/^(un)?block\s+\#?(-?\d+)\s+(by|with)\s+\s*(\S.*)?$/i) { + $ok++; + my $bugnum = $2; my $blockers = $4; + $addsub = "add"; + $addsub = "sub" if ($1 eq "un"); + + my @okayblockers; + my @badblockers; + foreach my $b (split /[\s,]+/, $blockers) { + $b=~s/^\#//; + if ($b=~/[0-9]+/) { + $ref=$b; + if (&getbug) { + push @okayblockers, $b; + + # add to the list all bugs that are merged with $b, + # because all of their data must be kept in sync + @thisbugmergelist= split(/ /,$data->{mergedwith}); + &cancelbug; + + foreach $ref (@thisbugmergelist) { + if (&getbug) { + push @okayblockers, $ref; + &cancelbug; + } + } + } + else { + ¬foundbug; + push @badblockers, $b; + } + } + else { + push @badblockers, $b; + } + } + if (@badblockers) { + &transcript("Unknown blocking bug/s: ".join(', ', @badblockers).".\n"); + } + + $ref=$bugnum; + if (&setbug) { + if ($data->{blockedby} eq '') { + &transcript("Was not blocked by any bugs.\n"); + } else { + &transcript("Was blocked by: $data->{blockedby}\n"); + } + if ($addsub eq "set") { + $action= "Blocking bugs set to: " . join(", ", @okayblockers); + } elsif ($addsub eq "add") { + $action= "Blocking bugs added: " . join(", ", @okayblockers); + } elsif ($addsub eq "sub") { + $action= "Blocking bugs removed: " . join(", ", @okayblockers); + } + my %removedblocks; + my %addedblocks; + do { + &addmaintainers($data); + my @oldblockerlist = split ' ', $data->{blockedby}; + $data->{blockedby} = '' if ($addsub eq "set"); + foreach my $b (@okayblockers) { + $data->{blockedby} = manipset($data->{blockedby}, $b, + ($addsub ne "sub")); + } + + foreach my $b (@oldblockerlist) { + if (! grep { $_ eq $b } split ' ', $data->{blockedby}) { + push @{$removedblocks{$b}}, $ref; + } + } + foreach my $b (split ' ', $data->{blockedby}) { + if (! grep { $_ eq $b } @oldblockerlist) { + push @{$addedblocks{$b}}, $ref; + } + } + } while (&getnextbug); + + # Now that the blockedby data is updated, change blocks data + # to match the changes. + foreach $ref (keys %addedblocks) { + if (&getbug) { + foreach my $b (@{$addedblocks{$ref}}) { + $data->{blocks} = manipset($data->{blocks}, $b, 1); + } + &savebug; + } + } + foreach $ref (keys %removedblocks) { + if (&getbug) { + foreach my $b (@{$removedblocks{$ref}}) { + $data->{blocks} = manipset($data->{blocks}, $b, 0); + } + &savebug; + } + } + } } 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}; } @@ -578,6 +839,7 @@ END } elsif (m/^unmerge\s+\#?(-?\d+)$/i) { $ok++; $ref= $1; + $bug_affected{$ref} = 1; if (&setbug) { if (!length($data->{mergedwith})) { &transcript("$gBug is not marked as being merged with any others.\n\n"); @@ -587,6 +849,7 @@ END $action= "Disconnected #$ref from all other report(s)."; @newmergelist= split(/ /,$data->{mergedwith}); $discref= $ref; + @bug_affected{@newmergelist} = 1 x @newmergelist; do { &addmaintainers($data); $data->{mergedwith}= ($ref == $discref) ? '' @@ -618,6 +881,8 @@ END &checkmatch('forwarded addr','m_forwarded',$data->{forwarded}); $data->{severity} = '$gDefaultSeverity' if $data->{severity} eq ''; &checkmatch('severity','m_severity',$data->{severity}); + &checkmatch('blocks','m_blocks',$data->{blocks}); + &checkmatch('blocked-by','m_blockedby',$data->{blockedby}); &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; } @@ -639,10 +904,71 @@ END for $ref (@newmergelist) { &getbug || die "huh ? $gBug $ref disappeared during merge"; &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"); + } + &endmerge; + } elsif (m/^forcemerge\s+\#?(-?\d+(\s+\#?-?\d+)+)\s*$/i) { + $ok++; + my @tomerge = split /\s+\#?/,$1; + my $master_bug = shift @tomerge; + my $master_bug_data; + @tomerge = ($master_bug, sort { $a <=> $b } @tomerge); + @newmergelist= (); + my %tags = (); + my %found = (); + my %fixed = (); + # Here we try to do the right thing. + # First, if the bugs are in the same package, we merge all of the found, fixed, and tags. + # If not, we discard the found and fixed. + # Everything else we set to the values of the first bug. + &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) { ¬foundbug; @newmergelist=(); last } + if (!&checkpkglimit) { &cancelbug; @newmergelist=(); last; } + &foundbug; + &transcript("D| adding $ref ($data->{mergedwith})\n") if $dl; + $master_bug_data = $data if not defined $master_bug_data; + if ($data->{package} ne $master_bug_data->{package}) { + &transcript("Mismatch - only $gBugs in the same package can be forcibly merged:\n". + "$gBug $ref is not in the same package as $master_bug\n"); + &cancelbug; @newmergelist=(); last; + } + for my $t (split /\s+/,$data->{keywords}) { + $tags{$t} = 1; + } + @found{@{$data->{found_versions}}} = (1) x @{$data->{found_versions}}; + @fixed{@{$data->{fixed_versions}}} = (1) x @{$data->{fixed_versions}}; + push(@newmergelist,$ref); + push(@tomerge,split(/ /,$data->{mergedwith})); + &cancelbug; + } + if (@newmergelist) { + @newmergelist= sort { $a <=> $b } @newmergelist; + $action= "Forcibly Merged @newmergelist."; + delete @fixed{keys %found}; + for $ref (@newmergelist) { + &getbug || die "huh ? $gBug $ref disappeared during merge"; + &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]; + my @field_list = qw(forwarded package severity blocks blockedby owner done); + @{$data}{@field_list} = @{$master_bug_data}{@field_list} &savebug; } &transcript("$action\n\n"); @@ -656,6 +982,7 @@ END $newbugsneeded = scalar(@newclonedids); $ref = $origref; + $bug_affected{$ref} = 1; if (&setbug) { if (length($data->{mergedwith})) { &transcript("$gBug is marked as being merged with others.\n\n"); @@ -675,20 +1002,38 @@ END } else { $action= "$gBug $origref cloned as bugs $firstref-$lastref."; } + + my $blocks = $data->{blocks}; + my $blockedby = $data->{blockedby}; + &getnextbug; my $ohash = get_hashname($origref); - $ref = $firstref; + my $clone = $firstref; + @bug_affected{@newclonedids} = 1 x @newclonedids; for $newclonedid (@newclonedids) { - $clonebugs{$newclonedid} = $ref; + $clonebugs{$newclonedid} = $clone; - 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, $data); - - $ref++; + my $hash = get_hashname($clone); + copy("db-h/$ohash/$origref.log", "db-h/$hash/$clone.log"); + copy("db-h/$ohash/$origref.status", "db-h/$hash/$clone.status"); + copy("db-h/$ohash/$origref.summary", "db-h/$hash/$clone.summary"); + copy("db-h/$ohash/$origref.report", "db-h/$hash/$clone.report"); + &bughook('new', $clone, $data); + + # Update blocking info of bugs blocked by or blocking the + # cloned bug. + foreach $ref (split ' ', $blocks) { + &getbug; + $data->{blockedby} = manipset($data->{blockedby}, $clone, 1); + &savebug; + } + foreach $ref (split ' ', $blockedby) { + &getbug; + $data->{blocks} = manipset($data->{blocks}, $clone, 1); + &savebug; + } + + $clone++; } } } @@ -707,6 +1052,7 @@ END 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."; @@ -725,6 +1071,7 @@ END } 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 " . @@ -783,6 +1130,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"; } @@ -819,22 +1169,16 @@ close(AP) || &quit("open db-h/-1.log: $!"); &unfilelock; utime(time,time,"db-h"); -&sendmailmessage($reply,$replyto,@maintccaddrs,@bcc); +&sendmailmessage($reply,exists $header{'x-debbugs-no-ack'}?():$replyto,@maintccaddrs,@bcc); unlink("incoming/P$nn") || &quit("unlinking incoming/P$nn: $!"); sub sendmailmessage { local ($message,@recips) = @_; $message = "X-Loop: $gMaintainerEmail\n" . $message; - print "mailing to >@recips<\n" if $debug; - $c= open(D,"|-"); - defined($c) || &quit("mailing forking for sendmail: $!"); - if (!$c) { # ie, we are the child process - exec '/usr/lib/sendmail','-f'."$gMaintainerEmail",'-odb','-oem','-oi',get_addresses(@recips); - die $!; - } - print(D $message) || &quit("writing to sendmail process: $!"); - $!=0; close(D); $? && &quit("sendmail gave exit status $? ($!)"); + send_mail_message(message => $message, + recipients => \@recips, + ); $midix++; } @@ -875,6 +1219,21 @@ sub checkpkglimit { return 1; } +sub manipset { + my $list = shift; + my $elt = shift; + my $add = shift; + + my %h = map { $_ => 1 } split ' ', $list; + if ($add) { + $h{$elt}=1; + } + else { + delete $h{$elt}; + } + return join ' ', sort keys %h; +} + # High-level bug manipulation calls # Do announcements themselves #