Ian's feedback on the previous patch has been incorporated:
* make whitespace consistent
* check argv before shifting
* don't repeat any parts of the query
* check $priv rather than passing an argument to action_list
Signed-off-by: Matthew Vernon <matthewv@chiark.greenend.org.uk>
}
}
-sub action_list (;$) {
+sub action_list {
my ($q, $listall);
- my ($x) = @_;
- if ( defined $x ) { $listall = 1; }
- my $v =shift @ARGV;
- if ( defined $v ) {
- if ($v ne "-a") {die "only legal argument to list is -a";}
- else { $listall=1; }
+ if ($priv) { $listall = 1; }
+ if (@ARGV) {
+ my $v = shift @ARGV;
+ if ($v ne "-a") {
+ die "only legal argument to list is -a";
+ } else { $listall=1; }
}
nomoreargs;
- if($listall){
- $q = $dbh->prepare("SELECT * FROM addrs WHERE user=?".
- " ORDER BY localpart");
- }else{
- $q = $dbh->prepare("SELECT * FROM addrs WHERE user=?".
- " AND redirect <>'' ORDER BY localpart");
+ $q="SELECT * FROM addrs WHERE user=?";
+ if (!$listall) {
+ $q = $q. " AND NOT redirect = ''";
}
+ $q = $q. " ORDER BY localpart";
+ $q = $dbh->prepare($q);
$q->execute($user);
listq($q);
}
die unless $priv;
$user = nextarg;
nomoreargs;
- action_list "-a";
+ action_list;
}
sub action_list_all {