chiark
/
gitweb
/
~ijackson
/
evade-mail-usrlocal.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
41ae1e7
)
pregen: wip
author
Ian Jackson
<ijackson@chiark.greenend.org.uk>
Sun, 27 Oct 2013 21:12:48 +0000
(21:12 +0000)
committer
Ian Jackson
<ijackson@chiark.greenend.org.uk>
Sun, 3 Nov 2013 15:26:37 +0000
(15:26 +0000)
evade-mail-pregen
patch
|
blob
|
history
diff --git
a/evade-mail-pregen
b/evade-mail-pregen
index 91466a1cc6271c2013d6816bceec8b7084c2d521..9ab3d220747af761e09e5617e40e235f492baf6a 100755
(executable)
--- a/
evade-mail-pregen
+++ b/
evade-mail-pregen
@@
-12,6
+12,7
@@
usage:
opts:
-G<generator> generator/lister program
-N do not generate more aliases
opts:
-G<generator> generator/lister program
-N do not generate more aliases
+ -q do not show domain, just local part
-l.., -d.., -F.., -m.. passed to generator
notes:
Always use $us to edit the comment of a pregen alias;
-l.., -d.., -F.., -m.. passed to generator
notes:
Always use $us to edit the comment of a pregen alias;
@@
-27,6
+28,7
@@
sub failstdout () { fail "stdout: $!"; }
our $generator;
our $no_generate=0;
our $generator;
our $no_generate=0;
+our $show_domain=1;
our @genopts;
our %by_localpart;
our @genopts;
our %by_localpart;
@@
-36,6
+38,25
@@
our $min_number;
our $comment_pattern = '### PREGEN <number>';
our $comment_re;
our $comment_pattern = '### PREGEN <number>';
our $comment_re;
+open DEBUG, ">/dev/null" or die $!;
+
+sub debug {
+ print DEBUG "$us: DEBUG: ", @_, "\n" or die $!;
+}
+
+sub debug_cmd {
+ debug "running ", join ' ',
+ map {
+ if (m/[^-_.=+0-9a-z]/i) {
+ my $s = $_;
+ $s =~ s/['\\]/'\\$&'/g;
+ "'$s'";
+ } else {
+ $_;
+ }
+ } @_;
+}
+
sub comment_make ($) {
my ($num) = @_;
my $r = $comment_pattern;
sub comment_make ($) {
my ($num) = @_;
my $r = $comment_pattern;
@@
-45,9
+66,13
@@
sub comment_make ($) {
sub run_generator {
my @genargs = @_;
sub run_generator {
my @genargs = @_;
- open P, "-|", $generator, @genargs or fail "fork $generator: $!";
+ my @cmd = ($generator, @genargs);
+ debug_cmd @cmd;
+ open P, "-|", @cmd or fail "fork $generator: $!";
while (<P>) {
my ($alias,$comment);
while (<P>) {
my ($alias,$comment);
+ chomp or fail "$generator truncated output?";
+ debug "| ", $_;
if (m/^\# user/) {
next;
} elsif (m/^\# reject (\S+) (\#.*)$/) {
if (m/^\# user/) {
next;
} elsif (m/^\# reject (\S+) (\#.*)$/) {
@@
-91,13
+116,13
@@
sub perhaps_generate ($) {
return $alias;
}
return $alias;
}
-sub parse_target {
+sub parse_target
()
{
@ARGV or badusage "missing specification for alias to change";
my $spec = shift @ARGV;
my $target;
if ($spec =~ m/^(\d{1,9})$/) {
$target = $by_number[$spec];
@ARGV or badusage "missing specification for alias to change";
my $spec = shift @ARGV;
my $target;
if ($spec =~ m/^(\d{1,9})$/) {
$target = $by_number[$spec];
- fail "no alias number $
target
" unless $target;
+ fail "no alias number $
spec (already assigned perhaps?)
" unless $target;
} elsif ($spec =~ m/^(.*)\@[^\@]*/) {
$target = $by_localpart{$1};
fail "no alias with local part \`$1'" unless $target;
} elsif ($spec =~ m/^(.*)\@[^\@]*/) {
$target = $by_localpart{$1};
fail "no alias with local part \`$1'" unless $target;
@@
-107,17
+132,19
@@
sub parse_target {
} else {
badusage "bad specification for alias to change";
}
} else {
badusage "bad specification for alias to change";
}
+ return $target;
}
sub report ($) {
my ($alias) = @_;
confess unless $alias;
}
sub report ($) {
my ($alias) = @_;
confess unless $alias;
- print $alias->{Number}, ' ', $alias->{LocalPart}, "\n"
+ print $alias->{Number}, ' ',
+ $alias->{ $show_domain ? 'Alias' : 'LocalPart' }, "\n"
or failstdout;
}
sub action_update {
or failstdout;
}
sub action_update {
- my $target = parse_target;
+ my $target = parse_target
()
;
@ARGV or badusage "missing update info\n";
if (defined $target->{Number} && $target->{Number} == $#by_number) {
my $wanted = $#by_number + 1;
@ARGV or badusage "missing update info\n";
if (defined $target->{Number} && $target->{Number} == $#by_number) {
my $wanted = $#by_number + 1;
@@
-127,8
+154,9
@@
$us: Losing track of next number ($wanted), due to use of -N;
$us: will start next alias at #0, unless you say (e.g.) "range $wanted".
END
}
$us: will start next alias at #0, unless you say (e.g.) "range $wanted".
END
}
- exec $generator, qw(update), $target->{Alias}, @ARGV
- or fail "exec $generator: $!";
+ my @cmd = ($generator, qw(update), $target->{Alias}, @ARGV);
+ debug_cmd @cmd;
+ exec @cmd or fail "exec $generator: $!";
}
sub action_assign {
}
sub action_assign {
@@
-146,7
+174,6
@@
sub action_list {
for (; $num <= $#by_number; $num++) {
my $alias = $by_number[$num];
report $alias if $alias;
for (; $num <= $#by_number; $num++) {
my $alias = $by_number[$num];
report $alias if $alias;
- $num++;
}
}
}
}
@@
-157,7
+184,7
@@
sub action_some {
my ($count) = $1;
my $num = $min_number;
$num ||= 0;
my ($count) = $1;
my $num = $min_number;
$num ||= 0;
-
while ($count > 0
) {
+
for (; $count > 0; $num++
) {
my $alias = perhaps_generate $num;
if ($alias) {
report $alias;
my $alias = perhaps_generate $num;
if ($alias) {
report $alias;
@@
-169,7
+196,6
@@
$us: fewer than requested aliases printed, due to -N
END
last;
}
END
last;
}
- $num++;
}
}
}
}
}
}
@@
-199,6
+225,10
@@
for (;;) {
push @genopts, $arg;
} elsif ($arg =~ s/^-G(.*)//) {
$generator = $1;
push @genopts, $arg;
} elsif ($arg =~ s/^-G(.*)//) {
$generator = $1;
+ } elsif ($arg =~ s/^-D/-/) {
+ open DEBUG, ">&STDERR" or die $!;
+ } elsif ($arg =~ s/^-q/-/) {
+ $show_domain = 0;
} elsif ($arg =~ s/^-N/-/) {
$no_generate = 1;
} else {
} elsif ($arg =~ s/^-N/-/) {
$no_generate = 1;
} else {