+sub gen_local_part_wordlist {
+ my @cmd = (qw(random-word), "-f$wordlist","-n$numwords");
+ push @cmd, "-F$wordlistlen" if $wordlistlen < 1e9;
+ for (;;) {
+ open P, "-|", @cmd or die $!;
+ my $s = <P>;
+ $!=0; $?=0; close P or die "$? $!";
+ chomp $s or die;
+ $s =~ s/ /$worddelim/g;
+ my $efflen = length $s;
+ $efflen += 1 + length($dom) if defined $dom;
+ return $s if $efflen <= $maxdomainlen;
+ }
+}
+
+sub genopt_wordlist {
+ local ($_) = @_;
+ if (m/^-l(\d+)$/) {
+ $numwords = $1;
+ die "length out of range $minnumwords..$maxnumwords\n"
+ unless ($minnumwords<=$numwords &&
+ $numwords<=$maxnumwords);
+ } elsif (m/^-d(.)$/) {
+ $worddelim = $1;
+ die "word delimiter must be one of \`$worddelims'\n"
+ unless grep { $worddelim eq $_ } split //, $worddelims;
+ } elsif (m/^-F(\d+)$/) {
+ $wordlistlen = $1 ? 0+$1 : 1e9;
+ die "requested dictionary size too small\n"
+ unless $wordlistlen >= $minwordlistlen;
+ } elsif (m/^-m(\d+)$/) {
+ $maxdomainlen = $1 ? 0+$1 : 1e9;
+ } else {
+ die "unknown wordlist generation option\n";
+ }
+}
+
+sub gendefaults_wordlist {
+ $numwords ||= $minnumwords;
+ $worddelim = substr($worddelims,0,1) unless defined $worddelim;
+ $worddelim = '' if $worddelim eq ',';
+ my $expectedmindomlen =
+ (defined $dom ? (1 + length $dom) : 0) # @domain.name
+ + $minmaxmeanwordlen * $numwords # some words
+ + (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"
+ if $expectedmindomlen > $maxdomainlen;
+}
+