| 1 |
#!/usr/bin/perl -w
|
| 2 |
# vim:sw=4:
|
| 3 |
|
| 4 |
# Copyright 2002-2006 Raphaël Hertzog <hertzog@debian.org>
|
| 5 |
# Copyright 2006-2007 Christoph Berg <myon@debian.org>
|
| 6 |
# Available under the terms of the General Public License version 2
|
| 7 |
# or (at your option) any later version
|
| 8 |
|
| 9 |
use lib '/org/packages.qa.debian.org/perl';
|
| 10 |
|
| 11 |
use ConfirmationSpool;
|
| 12 |
use DB_File;
|
| 13 |
|
| 14 |
use strict;
|
| 15 |
use vars qw($spool_dir $conf_sub_template $conf_unsub_template
|
| 16 |
$conf_unsuball_template $sendmaildefault $sendmailnobody
|
| 17 |
%db_tags_content);
|
| 18 |
|
| 19 |
# Command line frontend for pts@qa.debian.org
|
| 20 |
|
| 21 |
require "common.pl";
|
| 22 |
|
| 23 |
my $email = ((getpwuid($<))[0]) . "\@debian.org";
|
| 24 |
|
| 25 |
# Lines of the mail we got
|
| 26 |
my @lines = @ARGV ? join " ", @ARGV : <>;
|
| 27 |
|
| 28 |
# Lines of the answer that we'll send
|
| 29 |
my @ans; # = ("Processing commands for pts\@qa.debian.org:\n", "\n");
|
| 30 |
|
| 31 |
foreach my $line (@lines) {
|
| 32 |
#push @ans, "> $line\n";
|
| 33 |
|
| 34 |
# Try to detect commands
|
| 35 |
if ($line =~ /^\s*#/) {
|
| 36 |
next;
|
| 37 |
|
| 38 |
} elsif ($line =~ /^\s*subscribe\s+(\S+)(?:\s+(\S+))?/i) {
|
| 39 |
my ($package, $address) = (lc($1), lc($2));
|
| 40 |
$address = $email if (! (defined($address) && $address));
|
| 41 |
my @explanation;
|
| 42 |
($package, @explanation) = map_package($package);
|
| 43 |
push @ans, @explanation;
|
| 44 |
if (subscribe($address, $package)) {
|
| 45 |
push @ans, "$address has been subscribed to " .
|
| 46 |
"$package\@packages.qa.debian.org.\n";
|
| 47 |
} else {
|
| 48 |
push @ans, "$address is already subscribed ...\n";
|
| 49 |
}
|
| 50 |
|
| 51 |
} elsif ($line =~ /^\s*unsubscribe\s+(\S+)(?:\s+(\S+))?/i) {
|
| 52 |
my ($package, $address) = (lc($1), lc($2));
|
| 53 |
$address = $email if (! (defined($address) && $address));
|
| 54 |
if (unsubscribe($address, $package)) {
|
| 55 |
# users might still be subscribed to a renamed package
|
| 56 |
push @ans, "$address has been unsubscribed from " .
|
| 57 |
"$package\@packages.qa.debian.org.\n";
|
| 58 |
} else {
|
| 59 |
# try the canonical name
|
| 60 |
my ($new_package, @explanation) = map_package($package);
|
| 61 |
push @ans, @explanation;
|
| 62 |
if (unsubscribe($address, $new_package)) {
|
| 63 |
push @ans, "$address has been unsubscribed from " .
|
| 64 |
"$new_package\@packages.qa.debian.org.\n";
|
| 65 |
} else {
|
| 66 |
push @ans, "$address is not subscribed, you can't unsubscribe.\n";
|
| 67 |
}
|
| 68 |
}
|
| 69 |
|
| 70 |
} elsif ($line =~ /^\s*unsubscribeall(?:\s+(\S+))?/i) {
|
| 71 |
my $address = lc($1);
|
| 72 |
$address = $email if (! (defined($address) && $address));
|
| 73 |
my @explanation;
|
| 74 |
push @ans, "All your subscriptions have been terminated :\n";
|
| 75 |
foreach my $package (which($address)) {
|
| 76 |
if (unsubscribe($address, $package)) {
|
| 77 |
push @ans, "$address has been unsubscribed from " .
|
| 78 |
"$package\@packages.qa.debian.org.\n";
|
| 79 |
} else {
|
| 80 |
push @ans, "$address is not subscribed, you can't unsubscribe.\n";
|
| 81 |
}
|
| 82 |
}
|
| 83 |
|
| 84 |
} elsif ($line =~ /^\s*confirm\s+(\S+)/i) {
|
| 85 |
# my $key = $1;
|
| 86 |
# next if (defined($done{"CONFIRM $key"})); # Not twice..
|
| 87 |
# if (defined($cmd)) {
|
| 88 |
# my ($package, $address);
|
| 89 |
# if ($cmd =~ /^SUBSCRIBE (\S+) (\S+)/) {
|
| 90 |
# ($package, $address) = (lc($1), lc($2));
|
| 91 |
# if (subscribe($address, $package)) {
|
| 92 |
# push @ans, "$address has been subscribed to " .
|
| 93 |
# "$package\@packages.qa.debian.org.\n";
|
| 94 |
# $subject = "You are now subscribed to $package";
|
| 95 |
# } else {
|
| 96 |
# push @ans, "$address is already subscribed ...\n";
|
| 97 |
# }
|
| 98 |
# } elsif ($cmd =~ /^UNSUBSCRIBE (\S+) (\S+)/) {
|
| 99 |
# ($package, $address) = (lc($1), lc($2));
|
| 100 |
# if (unsubscribe($address, $package)) {
|
| 101 |
# push @ans, "$address has been unsubscribed from " .
|
| 102 |
# "$package\@packages.qa.debian.org.\n";
|
| 103 |
# $subject = "You are no longer subscribed to $package";
|
| 104 |
# } else {
|
| 105 |
# push @ans, "$address is not subscribed, you can't unsubscribe.\n";
|
| 106 |
# }
|
| 107 |
# } elsif ($cmd =~ /^UNSUBSCRIBEALL (\S+)/) {
|
| 108 |
# $address = lc($1);
|
| 109 |
# push @ans, "All your subscriptions have been terminated :\n";
|
| 110 |
# foreach my $package (which($address)) {
|
| 111 |
# if (unsubscribe($address, $package)) {
|
| 112 |
# push @ans, "$address has been unsubscribed from " .
|
| 113 |
# "$package\@packages.qa.debian.org.\n";
|
| 114 |
# $subject = "All your subcriptions have been terminated";
|
| 115 |
# } else {
|
| 116 |
# push @ans, "$address is not subscribed, you can't unsubscribe.\n";
|
| 117 |
# }
|
| 118 |
# }
|
| 119 |
# } else {
|
| 120 |
# push @ans, "Confirmation failed. Retry with a new command.\n";
|
| 121 |
# }
|
| 122 |
# $done{"CONFIRM $key"} = 1;
|
| 123 |
# #push @cc, $address if ($address ne $email);
|
| 124 |
# } else {
|
| 125 |
push @ans, "Confirmation failed. Retry with a new command.\n";
|
| 126 |
# }
|
| 127 |
push @ans, "\n";
|
| 128 |
|
| 129 |
} elsif ($line =~ /^\s*which(?:\s+(\S+))?/i) {
|
| 130 |
|
| 131 |
my $address = lc($1);
|
| 132 |
$address = $email if (! (defined($address) && $address));
|
| 133 |
my $default_tags = join ',', get_default_tags($address);
|
| 134 |
push @ans, "Here's the list of subscriptions for $address :\n";
|
| 135 |
push @ans, map {
|
| 136 |
my $tags = join ',', get_tags($address, $_);
|
| 137 |
"* $_" . ($tags ne $default_tags ? " [$tags]" : "") . "\n"
|
| 138 |
} (which($address));
|
| 139 |
push @ans, "\n";
|
| 140 |
|
| 141 |
} elsif ($line =~ /^\s*(?:list|who)\s+(\S+)/i) {
|
| 142 |
|
| 143 |
my $package = lc($1);
|
| 144 |
push @ans, "Here's the list of subscribers to $package :\n";
|
| 145 |
push @ans, map { $_ . "\n" } (list($package));
|
| 146 |
push @ans, "\n";
|
| 147 |
|
| 148 |
} elsif ($line =~ /^\s*(?:keyword|tag)s?(?:\s+(\S+@\S+))?\s*$/i) {
|
| 149 |
|
| 150 |
my $address = lc($1);
|
| 151 |
$address = $email if (! (defined($address) && $address));
|
| 152 |
push @ans, "Here's the default list of accepted keywords " .
|
| 153 |
"for $address :\n";
|
| 154 |
push @ans, map { "* " . $_ . "\n" } (get_default_tags($address));
|
| 155 |
push @ans, "\n";
|
| 156 |
|
| 157 |
} elsif ($line =~ /^\s*(?:keyword|tag)s?\s+(\S+)(?:\s+(\S+@\S+))?\s*$/i) {
|
| 158 |
|
| 159 |
my $package = lc($1);
|
| 160 |
my $address = lc($2);
|
| 161 |
$address = $email if (! (defined($address) && $address));
|
| 162 |
push @ans, "Here's the list of accepted keywords associated to " .
|
| 163 |
"package\n";
|
| 164 |
push @ans, "$package for $address :\n";
|
| 165 |
push @ans, map { "* " . $_ . "\n" } (get_tags($address, $package));
|
| 166 |
push @ans, "\n";
|
| 167 |
|
| 168 |
} elsif ($line =~ /^\s*(?:keyword|tag)s?(?:\s+(\S+@\S+))?\s+([-+=])\s+(\S+(?:\s+\S+)*)\s*$/i) {
|
| 169 |
|
| 170 |
my $address = lc($1);
|
| 171 |
$address = $email if (! (defined($address) && $address));
|
| 172 |
my $cmd = $2;
|
| 173 |
my @t = split(/[,\s]+/, lc($3));
|
| 174 |
foreach (@t) {
|
| 175 |
push @ans, "WARNING: $_ is not a valid keyword.\n"
|
| 176 |
if (! is_valid_tag($_));
|
| 177 |
}
|
| 178 |
open_db_write();
|
| 179 |
if ($cmd eq "=") {
|
| 180 |
set_default_tags($address, @t);
|
| 181 |
} elsif ($cmd eq "+") {
|
| 182 |
my @tags = get_default_tags($address);
|
| 183 |
push @tags, @t;
|
| 184 |
set_default_tags($address, @tags);
|
| 185 |
} elsif ($cmd eq "-") {
|
| 186 |
my $check = sub {
|
| 187 |
foreach my $t (@t) {
|
| 188 |
return 0 if ($_[0] eq $t);
|
| 189 |
}
|
| 190 |
return 1;
|
| 191 |
};
|
| 192 |
my @tags = grep { &$check($_) } (get_default_tags($address));
|
| 193 |
set_default_tags($address, @tags);
|
| 194 |
}
|
| 195 |
push @ans, "Here's the new default list of accepted keywords " .
|
| 196 |
"for $address :\n";
|
| 197 |
push @ans, map { "* " . $_ . "\n" } (get_default_tags($address));
|
| 198 |
push @ans, "\n";
|
| 199 |
close_db();
|
| 200 |
|
| 201 |
} elsif ($line =~ /^\s*(?:keyword|tag)s?all(?:\s+(\S+@\S+))?\s+([-+=])\s+(\S+(?:\s+\S+)*)\s*$/i) {
|
| 202 |
|
| 203 |
my $address = lc($1);
|
| 204 |
$address = $email if (! (defined($address) && $address));
|
| 205 |
my $cmd = $2;
|
| 206 |
my @t = split(/[,\s]+/, lc($3));
|
| 207 |
foreach (@t) {
|
| 208 |
push @ans, "WARNING: $_ is not a valid keyword.\n"
|
| 209 |
if (! is_valid_tag($_));
|
| 210 |
}
|
| 211 |
open_db_write();
|
| 212 |
if (not exists $db_tags_content{$address}) {
|
| 213 |
my @tags = get_default_tags($address);
|
| 214 |
set_default_tags($address, @tags);
|
| 215 |
}
|
| 216 |
foreach (sort keys %db_tags_content) {
|
| 217 |
if (/^\Q$address\E(?:#([^#]+))?$/) {
|
| 218 |
my $package = (defined($1) && $1) ? $1 : "";
|
| 219 |
if ($cmd eq "=") {
|
| 220 |
if ($package) {
|
| 221 |
set_tags($address, $package, @t);
|
| 222 |
} else {
|
| 223 |
set_default_tags($address, @t);
|
| 224 |
}
|
| 225 |
} elsif ($cmd eq "+") {
|
| 226 |
if ($package) {
|
| 227 |
my @tags = get_tags($address, $package);
|
| 228 |
push @tags, @t;
|
| 229 |
set_tags($address, $package, @tags);
|
| 230 |
} else {
|
| 231 |
my @tags = get_default_tags($address);
|
| 232 |
push @tags, @t;
|
| 233 |
set_default_tags($address, @tags);
|
| 234 |
}
|
| 235 |
} elsif ($cmd eq "-") {
|
| 236 |
my $check = sub {
|
| 237 |
foreach my $t (@t) {
|
| 238 |
return 0 if ($_[0] eq $t);
|
| 239 |
}
|
| 240 |
return 1;
|
| 241 |
};
|
| 242 |
if ($package) {
|
| 243 |
my @tags = grep { &$check($_) } (get_tags($address, $package));
|
| 244 |
set_tags($address, $package, @tags);
|
| 245 |
} else {
|
| 246 |
my @tags = grep { &$check($_) } (get_default_tags($address));
|
| 247 |
set_default_tags($address, @tags);
|
| 248 |
}
|
| 249 |
}
|
| 250 |
if ($package) {
|
| 251 |
push @ans, "Updated the list of keywords accepted by $address ".
|
| 252 |
"for the package $package.\n";
|
| 253 |
} else {
|
| 254 |
push @ans, "Updated the default list of keywords accepted by $address.\n";
|
| 255 |
}
|
| 256 |
}
|
| 257 |
}
|
| 258 |
close_db();
|
| 259 |
|
| 260 |
} elsif ($line =~ /^\s*(?:keyword|tag)s?\s+(\S+)(?:\s+(\S+@\S+))?\s+([-+=])\s+(\S+(?:\s+\S+)*)\s*$/i) {
|
| 261 |
|
| 262 |
my $package = lc($1);
|
| 263 |
my $address = lc($2);
|
| 264 |
$address = $email if (! (defined($address) && $address));
|
| 265 |
my $cmd = $3;
|
| 266 |
my @t = split(/[,\s]+/, lc($4));
|
| 267 |
foreach (@t) {
|
| 268 |
push @ans, "$_ is not a valid keyword.\n" if (! is_valid_tag($_));
|
| 269 |
}
|
| 270 |
open_db_write();
|
| 271 |
if ($cmd eq "=") {
|
| 272 |
set_tags($address, $package, @t);
|
| 273 |
} elsif ($cmd eq "+") {
|
| 274 |
my @tags = get_tags($address, $package);
|
| 275 |
push @tags, @t;
|
| 276 |
set_tags($address, $package, @tags);
|
| 277 |
} elsif ($cmd eq "-") {
|
| 278 |
my $check = sub {
|
| 279 |
foreach my $t (@t) {
|
| 280 |
return 0 if ($_[0] eq $t);
|
| 281 |
}
|
| 282 |
return 1;
|
| 283 |
};
|
| 284 |
my @tags = grep { &$check($_) } (get_tags($address, $package));
|
| 285 |
set_tags($address, $package, @tags);
|
| 286 |
}
|
| 287 |
push @ans, "Here's the new list of accepted keywords associated to " .
|
| 288 |
"package\n";
|
| 289 |
push @ans, "$package for $address :\n";
|
| 290 |
push @ans, map { "* " . $_ . "\n" } (get_tags($address, $package));
|
| 291 |
push @ans, "\n";
|
| 292 |
close_db();
|
| 293 |
|
| 294 |
} elsif ($line =~ /^\s*help/i) {
|
| 295 |
push @ans, <DATA>;
|
| 296 |
|
| 297 |
} elsif ($line =~ /^(--|\s*quit|\s*thanks?|\s*txs)/i) {
|
| 298 |
push @ans, "Stopping processing here.\n";
|
| 299 |
last;
|
| 300 |
|
| 301 |
} else {
|
| 302 |
push @ans, "Invalid command.\n";
|
| 303 |
}
|
| 304 |
}
|
| 305 |
|
| 306 |
print join "", @ans;
|
| 307 |
|
| 308 |
|
| 309 |
__DATA__
|
| 310 |
|
| 311 |
Debian Package Tracking System
|
| 312 |
------------------------------
|
| 313 |
|
| 314 |
The Package Tracking System (PTS) has the following commands:
|
| 315 |
|
| 316 |
subscribe <srcpackage> [<email>]
|
| 317 |
Subscribes <email> to all messages regarding <srcpackage>. If
|
| 318 |
<email> is not given, it subscribes the From address. If the
|
| 319 |
<srcpackage> is not a valid source package, you'll get a warning.
|
| 320 |
If it's a valid binary package, the mapping will automatically be
|
| 321 |
done for you.
|
| 322 |
|
| 323 |
unsubscribe <srcpackage> [<email>]
|
| 324 |
Unsubscribes <email> from <srcpackage>. Like the subscribe command,
|
| 325 |
it will use the From address if <email> is not given.
|
| 326 |
|
| 327 |
unsubscribeall [<email>]
|
| 328 |
Cancel all subscriptions of <email>. Like the subscribe command,
|
| 329 |
it will use the From address if <email> is not given.
|
| 330 |
|
| 331 |
which [<email>]
|
| 332 |
Tells you which packages <email> is subscribed to.
|
| 333 |
|
| 334 |
keyword [<email>]
|
| 335 |
Tells you the keywords that you are accepting. Each mail sent through
|
| 336 |
the Package Tracking System is associated to a keyword and you receive
|
| 337 |
only the mails associated to keywords that you are accepting. Here is
|
| 338 |
the list of available keywords :
|
| 339 |
* bts: mails coming from the Debian Bug Tracking System
|
| 340 |
* bts-control: mails sent to control@bugs.debian.org
|
| 341 |
* summary: automatic summary mails about the state of a package
|
| 342 |
* cvs: notification of cvs commits
|
| 343 |
* ddtp: notification of translations from the DDTP (cf ddtp.debian.org)
|
| 344 |
* derivatives: notification of changes in derivative distributions
|
| 345 |
* upload-source: announce of a new source upload that has been installed
|
| 346 |
* upload-binary: announce of a new binary-only upload (porting)
|
| 347 |
* katie-other: other mails from ftpmasters (override disparity, etc.)
|
| 348 |
* default: all the other mails (those which aren't "automatic")
|
| 349 |
By default you have the following keywords : bts, bts-control, summary,
|
| 350 |
upload-source, katie-other, default.
|
| 351 |
|
| 352 |
keyword <srcpackage> [<email>]
|
| 353 |
Same as previous item but for the given source package since
|
| 354 |
you may select a different set of keywords for each source package.
|
| 355 |
|
| 356 |
keyword [<email>] {+|-|=} <list of keywords>
|
| 357 |
Accept (+) or refuse (-) mails associated to the given keyword(s).
|
| 358 |
Define the list (=) of accepted keywords.
|
| 359 |
|
| 360 |
keyword <srcpackage> [<email>] {+|-|=} <list of keywords>
|
| 361 |
Same as previous item but overrides the keywords list for the indicated
|
| 362 |
source package.
|
| 363 |
|
| 364 |
quit
|
| 365 |
thanks
|
| 366 |
Stops processing commands.
|
| 367 |
|