chiark / gitweb /
Revise patch in line with Ian's comments
authorMatthew Vernon <mcv21@cam.ac.uk>
Thu, 13 Feb 2014 17:39:09 +0000 (17:39 +0000)
committerMatthew Vernon <mcv21@cam.ac.uk>
Thu, 13 Feb 2014 17:39:09 +0000 (17:39 +0000)
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>
evade-mail-admin

index 6a6af061694f349c0bc886a03e1541458dd0d8b9..6f3fe21f91d2ee279aa9ca4139ca1491200953b8 100755 (executable)
@@ -408,23 +408,22 @@ sub listq ($) {
     }
 }
 
-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);
 }
@@ -433,7 +432,7 @@ sub action_list_user {
     die unless $priv;
     $user = nextarg;
     nomoreargs;
-    action_list "-a";
+    action_list;
 }
 
 sub action_list_all {