user => eval{(getpwuid($<))[0]} || $ENV{USER} || $ENV{USERNAME},
passwd => undef,
server => 'http://localhost/rt/',
+ query => undef,
+ orderby => undef,
),
config_from_file($ENV{RTCONFIG} || ".rtrc"),
config_from_env()
my $title = $item->[2]{Title};
my @titles = ref $title eq 'ARRAY' ? @$title : $title;
- foreach $title (grep $_, @titles) {
- $help{$title} = $item->[2]{Text};
- }
+ foreach $title (grep $_, @titles) {
+ $help{$title} = $item->[2]{Text};
+ }
}
# What does the user want help with?
sub list {
my ($q, $type, %data, $orderby);
+ if ($config{orderby}) {
+ $data{orderby} = $config{orderby};
+ }
my $bad = 0;
while (@ARGV) {
$bad = 1, last unless get_var_argument(\%data);
}
elsif (/^-o$/) {
- $orderby = shift @ARGV;
+ $data{'orderby'} = shift @ARGV;
}
elsif (/^-([isl])$/) {
$data{format} = $1;
$bad = 1; last;
}
}
-
+
+ if (!defined $q) {
+ $q = $config{query};
+ }
+
$type ||= "ticket";
unless ($type && defined $q) {
my $item = $type ? "query string" : "object type";
}
return help("list", $type) if $bad;
- my $r = submit("$REST/search/$type", { query => $q, %data, orderby => $orderby || "" });
+ my $r = submit("$REST/search/$type", { query => $q, %data });
print $r->content;
}
my $a = $_ eq "-b" ? \@bcc : \@cc;
@$a = split /\s*,\s*/, shift @ARGV;
}
- elsif (/-m/) { $msg = shift @ARGV }
+ elsif (/-m/) {
+ $msg = shift @ARGV;
+ if ( $msg =~ /^-$/ ) {
+ undef $msg;
+ while (<STDIN>) { $msg .= $_ }
+ }
+ }
+
elsif (/-w/) { $wtime = shift @ARGV }
}
elsif (!$id && m|^(?:ticket/)?($idlist)$|) {
my ($head, $text) = split /\n\n/, $res->content, 2;
my ($status, @headers) = split /\n/, $head;
- $text =~ s/\n*$/\n/;
+ $text =~ s/\n*$/\n/ if ($text);
# "RT/3.0.1 401 Credentials required"
- if ($status !~ m#^RT/\d+(?:\.\d+)+(?:-?\w+)? (\d+) ([\w\s]+)$#) {
+ if ($status !~ m#^RT/\d+(?:\S+) (\d+) ([\w\s]+)$#) {
warn "rt: Malformed RT response from $config{server}.\n";
warn "(Rerun with RTDEBUG=3 for details.)\n" if $config{debug} < 3;
exit -1;
sub cookie {
my ($self) = @_;
my $cookie = $self->{sids}{$s}{$u};
- return defined $cookie ? "RT_SID=$cookie" : undef;
+ return defined $cookie ? "RT_SID_$cookie" : undef;
}
# Deletes the current session cookie.
my ($self, $response) = @_;
my $cookie = $response->header("Set-Cookie");
- if (defined $cookie && $cookie =~ /^RT_SID=([0-9A-Fa-f]+);/) {
+ if (defined $cookie && $cookie =~ /^RT_SID_(.[^;,\s]+=[0-9A-Fa-f]+);/) {
$self->{sids}{$s}{$u} = $1;
}
}
while (<F>) {
chomp;
next if /^$/ || /^#/;
- next unless m#^https?://[^ ]+ \w+ [0-9A-Fa-f]+$#;
+ next unless m#^https?://[^ ]+ \w+ [^;,\s]+=[0-9A-Fa-f]+$#;
my ($server, $user, $cookie) = split / /, $_;
$sids->{$server}{$user} = $cookie;
}
sub config_from_env {
my %env;
- foreach my $k ("DEBUG", "USER", "PASSWD", "SERVER") {
+ foreach my $k ("DEBUG", "USER", "PASSWD", "SERVER", "QUERY", "ORDERBY") {
if (exists $ENV{"RT$k"}) {
$env{lc $k} = $ENV{"RT$k"};
}
chomp;
next if (/^#/ || /^\s*$/);
- if (/^(user|passwd|server)\s+([^ ]+)$/) {
+ if (/^(user|passwd|server|query|orderby)\s+(.*)\s?$/) {
$cfg{$1} = $2;
}
else {
- server <URL> URL to RT server.
- user <username> RT username.
- passwd <passwd> RT user's password.
+ - query <RT Query> Default RT Query for list action
+ - orderby <order> Default RT order for list action
Blank and #-commented lines are ignored.
- RTDEBUG Numeric debug level. (Set to 3 for full logs.)
- RTCONFIG Specifies a name other than ".rtrc" for the
configuration file.
+ - RTQUERY Default RT Query for rt list
+ - RTORDERBY Default order for rt list
--
be used to specify more than one object of the same type. Note that
the list must be a single argument (i.e., no spaces). For example,
"user/root,1-3,5,7-10,ams" is a list of ten users; the same list
- can also be written as "user/ams,root,1,2,3,5,7,8-20".
+ can also be written as "user/ams,root,1,2,3,5,7,8-10".
Examples: