chiark / gitweb /
Make "list" command suppress rejected addresses by default
[d.git] / evade-mail-admin
index 5b997bd1bf15fcf280ffd39fbe31d2a132824fe3..4e5be404f34b863de11d7ea24b49c2c70e7aaf54 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;
 }
 
@@ -320,6 +321,7 @@ sub action_create {
 
 sub action_choose {
     genopts;
+    $|=1;
     my $template = rhsargs({'redirect'=>$user, 'comment'=>''});
     $template->{'user'} = $user;
     prepare_create();
@@ -350,6 +352,7 @@ sub action_choose {
            1;
        }) {
            my $newrow = { %$template, 'localpart' => $s };
+           insertrow($newrow);
            $dbh->commit();
            prow($newrow);
        } else {
@@ -406,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);
 }