}
sub urlmatch {
- my ($self, $key, $url, $try_git) = @_;
+ my $self = shift;
+ my @bool = $_[0] eq '--bool' ? (shift) : ();
+ my ($key, $url, $try_git) = @_;
state $urlmatch_broken; # requires git 1.8.5
return if $urlmatch_broken;
my (%env, %opt);
my $cmd = $self->config_cmd(\%env, \%opt);
- push @$cmd, qw(-z --includes --get-urlmatch), $key, $url;
+ push @$cmd, @bool, qw(--includes -z --get-urlmatch), $key, $url;
my $fh = popen_rd($cmd, \%env, \%opt);
local $/ = "\0";
my $val = <$fh>;
if (!close($fh)) {
undef $val;
- if (($? >> 8) != 1) {
+ if (@bool && ($? >> 8) == 128) { # not boolean
+ } elsif (($? >> 8) != 1) {
$urlmatch_broken = 1;
} elsif ($try_git) { # n.b. this takes cwd into account
- $cmd = [qw(git config -z --get-urlmatch), $key, $url];
- $fh = popen_rd($cmd);
+ $fh = popen_rd([qw(git config), @bool,
+ qw(-z --get-urlmatch), $key, $url]);
$val = <$fh>;
close($fh) or undef($val);
}
}
$? = 0; # don't influence lei exit status
- chomp $val if defined $val;
+ if (defined($val)) {
+ chomp $val;
+ $val = git_bool($val) if @bool;
+ }
$val;
}
}
}
-sub cfg_bool ($$$) {
- my ($cfg, $key, $url) = @_;
- my $orig = $cfg->urlmatch($key, $url) // return;
- my $bool = $cfg->git_bool($orig);
- warn "W: $key=$orig for $url is not boolean\n" unless defined($bool);
- $bool;
-}
-
# flesh out common IMAP-specific data structures
sub imap_common_init ($;$) {
my ($self, $lei) = @_;
# knobs directly for Mail::IMAPClient->new
for my $k (qw(Starttls Debug Compress)) {
- my $bool = cfg_bool($cfg, "imap.$k", $$uri) // next;
- $mic_common->{$sec}->{$k} = $bool;
+ my $v = $cfg->urlmatch('--bool', "imap.$k", $$uri);
+ $mic_common->{$sec}->{$k} = $v if defined $v;
}
my $to = cfg_intvl($cfg, 'imap.timeout', $$uri);
$mic_common->{$sec}->{Timeout} = $to if $to;
my $args = $nn_common->{$sec} //= {};
# Debug and Timeout are passed to Net::NNTP->new
- my $v = cfg_bool($cfg, 'nntp.Debug', $$uri);
+ my $v = $cfg->urlmatch(qw(--bool nntp.Debug), $$uri);
$args->{Debug} = $v if defined $v;
my $to = cfg_intvl($cfg, 'nntp.Timeout', $$uri);
$args->{Timeout} = $to if $to;
# Net::NNTP post-connect commands
for my $k (qw(starttls compress)) {
- $v = cfg_bool($cfg, "nntp.$k", $$uri) // next;
- $self->{cfg_opt}->{$sec}->{$k} = $v;
+ $v = $cfg->urlmatch('--bool', "nntp.$k", $$uri);
+ $self->{cfg_opt}->{$sec}->{$k} = $v if defined $v;
}
# -watch internal option
test_lei(sub {
lei_ok qw(ls-mail-source), "imap://$starttls_addr",
\'STARTTLS not used by default';
- ok(!lei(qw(ls-mail-source -c imap.starttls=true),
+ ok(!lei(qw(ls-mail-source -c imap.starttls),
"imap://$starttls_addr"), 'STARTTLS verify fails');
+ unlike $lei_err, qr!W: imap\.starttls= .*? is not boolean!i,
+ 'no non-boolean warning';
});
SKIP: {
test_lei(sub {
lei_ok qw(ls-mail-source), "nntp://$starttls_addr",
\'STARTTLS not used by default';
- ok(!lei(qw(ls-mail-source -c nntp.starttls=true),
+ ok(!lei(qw(ls-mail-source -c nntp.starttls),
"nntp://$starttls_addr"), 'STARTTLS verify fails');
like $lei_err, qr/STARTTLS requested/,
'STARTTLS noted in stderr';
+ unlike $lei_err, qr!W: nntp\.starttls= .*? is not boolean!i,
+ 'no non-boolean warning';
});
SKIP: {