my ($self, $name) = @_;
my $pfx = "publicinbox.$name";
my $ibx = {};
- for my $k (qw(watch nntpserver)) {
+ for my $k (qw(watch)) {
my $v = $self->{"$pfx.$k"};
$ibx->{$k} = $v if defined $v;
}
# TODO: more arrays, we should support multi-value for
# more things to encourage decentralization
for my $k (qw(address altid nntpmirror coderepo hide listid url
- infourl watchheader)) {
+ infourl watchheader nntpserver)) {
my $v = $self->{"$pfx.$k"} // next;
$ibx->{$k} = _array($v);
}
} else {
delete $opts->{feedmax};
}
- $opts->{nntpserver} ||= $pi_cfg->{'publicinbox.nntpserver'};
-
# allow any combination of multi-line or comma-delimited hide entries
my $hide = {};
if (defined(my $h = $opts->{hide})) {
}
sub nntp_url {
- my ($self) = @_;
+ my ($self, $ctx) = @_;
$self->{-nntp_url} ||= do {
# no checking for nntp_usable here, we can point entirely
# to non-local servers or users run by a different user
- my $ns = $self->{nntpserver};
+ my $ns = $self->{nntpserver} //
+ $ctx->{www}->{pi_cfg}->get_all('publicinbox.nntpserver');
my $group = $self->{newsgroup};
my @urls;
if ($ns && $group) {
- $ns = [ $ns ] if ref($ns) ne 'ARRAY';
@urls = map {
my $u = m!\Anntps?://! ? $_ : "nntp://$_";
$u .= '/' if $u !~ m!/\z!;
$u.$group;
} @$ns;
}
-
my $mirrors = $self->{nntpmirror};
if ($mirrors) {
my @m;
defined(my $v = $ibx->{$k}) or next;
$$txt .= "\t$k = $v\n";
}
- $$txt .= "\tnntpmirror = $_\n" for (@{$ibx->nntp_url});
+ $$txt .= "\tnntpmirror = $_\n" for (@{$ibx->nntp_url($ctx)});
_coderepo_config($ctx, $txt);
1;
}
Example config snippet for mirrors: $cfg_link
EOF
if ($ibx->can('nntp_url')) {
- my $nntp = $ibx->nntp_url;
+ my $nntp = $ibx->nntp_url($ctx);
if (scalar @$nntp) {
$$txt .= "\n";
$$txt .= @$nntp == 1 ? 'Newsgroup' : 'Newsgroups are';
-primary_address => 'meta@public-inbox.org',
'name' => 'meta',
-httpbackend_limiter => undef,
- nntpserver => undef,
}, "lookup matches expected output");
is($cfg->lookup('blah@example.com'), undef,
'name' => 'test',
'url' => [ 'http://example.com/test' ],
-httpbackend_limiter => undef,
- nntpserver => undef,
}, "lookup matches expected output for test");
}
my $str = <<EOF;
$pfx.address=test\@example.com
$pfx.inboxdir=/path/to/non/existent
+$pfx.newsgroup=inbox.test
publicinbox.nntpserver=news.example.com
EOF
my $cfg = PublicInbox::Config->new(\$str);
my $ibx = $cfg->lookup_name('test');
- is($ibx->{nntpserver}, 'news.example.com', 'global NNTP server');
+ is_deeply($ibx->nntp_url({ www => { pi_cfg => $cfg }}),
+ [ 'nntp://news.example.com/inbox.test' ],
+ 'nntp_url uses global NNTP server');
$str = <<EOF;
$pfx.address=test\@example.com
$pfx.inboxdir=/path/to/non/existent
+$pfx.newsgroup=inbox.test
$pfx.nntpserver=news.alt.example.com
+publicinbox.nntpserver=news.example.com
EOF
$cfg = PublicInbox::Config->new(\$str);
$ibx = $cfg->lookup_name('test');
- is($ibx->{nntpserver}, 'news.alt.example.com','per-inbox NNTP server');
+ is_deeply($ibx->nntp_url({ www => { pi_cfg => $cfg }}),
+ [ 'nntp://news.alt.example.com/inbox.test' ],
+ 'nntp_url uses per-inbox NNTP server');
}
# no obfuscate domains