chiark / gitweb /
evade-mail-admin: make disable-user work
[d.git] / evade-mail-admin
index dc5e37ef2db5385531c390287242c736c56cf7cc..930d7180d8ff3b2defe71e80c5e757b07666734a 100755 (executable)
@@ -22,9 +22,10 @@ actions
   choose [<genopts>] [<redirect>] [#<comment>]  (interactively allocate)
   update <addr> [<redirect>] [#<comment>]
   show <addr>
-  list
+  list [-a] (-a also lists aliases set to reject)
   list-actions
 empty string for redirect means reject
+remember to quote comments (to protect # from your shell)
 END
 our $usage3 = <<'END';
 privileged actions
@@ -85,7 +86,7 @@ our $maxdomainlen = 40;
 sub nextarg () {
     die "too few arguments\n" unless @ARGV;
     my $v = shift @ARGV;
-    die "option too late on command line\n" if $v =~ m/^-/;
+    die "option in wrong place on command line\n" if $v =~ m/^-/;
     return $v;
 }
 
@@ -294,7 +295,7 @@ sub gendefaults_wordlist {
        + (length $worddelim) * ($numwords-1); # delimiters
     die "assuming lowest reasonable mean word length $minmaxmeanwordlen".
        " addrs would be $expectedmindomlen long but".
-       " your maximum length specified $maxdomainlen\n"
+       " maximum length is set to $maxdomainlen (use different -m?)\n"
        if $expectedmindomlen > $maxdomainlen;
 }
 
@@ -408,9 +409,23 @@ sub listq ($) {
 }
 
 sub action_list {
+    my $listall = 0;
+    $listall ||= $priv;
+    while (@ARGV) {
+       last unless $ARGV[0] =~ m/^-/;
+       $_ = shift @ARGV;
+       last if m/^--?$/;
+       if (m/^-a$/) {
+           $listall=1;
+       } else {
+           die "unknown option to list \`$_'\n";
+       }
+    }
     nomoreargs;
-    my $q = $dbh->prepare("SELECT * FROM addrs WHERE user=?".
-                         " ORDER BY localpart");
+    my $q = "SELECT * FROM addrs WHERE user=?";
+    $q .= " AND NOT redirect = ''" unless $listall;
+    $q .= " ORDER BY localpart";
+    $q = $dbh->prepare($q);
     $q->execute($user);
     listq($q);
 }
@@ -466,7 +481,7 @@ sub action_disable_user {
     die unless $priv;
     $user = nextarg;
     nomoreargs;
-    $dbh->do('INSERT INTO disabled_users VALUES user (?)',{},$user);
+    $dbh->do('INSERT INTO disabled_users (user) VALUES (?)',{},$user);
     $dbh->commit;
 }