+
+# select a set of bugs
+sub select_bugs{
+ my ($options) = @_;
+
+ my %valid_keys = (package => 'package',
+ pkg => 'package',
+ src => 'src',
+ source => 'src',
+ maint => 'maint',
+ maintainer => 'maint',
+ submitter => 'submitter',
+ from => 'submitter',
+ status => 'status',
+ tag => 'tag',
+ tags => 'tag',
+ usertag => 'tag',
+ usertags => 'tag',
+ owner => 'owner',
+ dist => 'dist',
+ distribution => 'dist',
+ bugs => 'bugs',
+ archive => 'archive',
+ severity => 'severity',
+ correspondent => 'correspondent',
+ affects => 'affects',
+ );
+
+ my $soap = SOAP::Lite
+ -> uri('Debbugs/SOAP/V1')
+ -> proxy("http://$options{bug_mirror}/cgi-bin/soap.cgi");
+ my @bugs;
+ my @bug_selections = ();
+ if (not -e $options{bugs_to_get}) {
+ my ($addr) = get_addresses(exists $ENV{DEBEMAIL}?
+ $ENV{DEBEMAIL} :
+ (User->Login . '@' . qx(hostname --fqdn)));
+ # by default include bugs talked to by this user packages
+ # maintained by this user, submitted by this user, and rc
+ # bugs
+ push @bug_selections,
+ ("correspondent:$addr archive:both",
+ "maint:$addr archive:both",
+ "submitter:$addr archive:both",
+ "severity:serious severity:grave severity:critical archive:both",
+ );
+ }
+ else {
+ my $btg_fh = IO::File->new($options{bugs_to_get},'r') or
+ die "unable to open bugs to get file '$options{bugs_to_get}' for reading: $!";
+ while (<$btg_fh>) {
+ chomp;
+ next if /^\s*#/;
+ if (/^\d+$/) {
+ push @bugs,$_;
+ }
+ elsif (/\s\w+\:/) {
+ push @bug_selections, $_;
+ }
+ }
+ }
+ for my $selection (@bug_selections) {
+ my @subselects = split /\s+/,$selection;
+ my %search_parameters;
+ my %users;
+ for my $subselect (@subselects) {
+ my ($key,$value) = split /:/, $subselect, 2;
+ next unless $key;
+ if (exists $valid_keys{$key}) {
+ push @{$search_parameters{$valid_keys{$key}}},
+ $value if $value;
+ } elsif ($key =~/users?$/) {
+ $users{$value} = 1 if $value;
+ }
+ }
+ my %usertags;
+ for my $user (keys %users) {
+ my $ut = $soap->get_usertag($user)->result();
+ next unless defined $ut and $ut ne "";
+ for my $tag (keys %{$ut}) {
+ push @{$usertags{$tag}},
+ @{$ut->{$tag}};
+ }
+ }
+ my $bugs = $soap->get_bugs(%search_parameters,
+ (keys %usertags)?(usertags=>\%usertags):()
+ )->result();
+ push @bugs,@{$bugs} if defined $bugs and @{$bugs};
+ }
+ return @bugs;