my $v = $self->{"$pfx.$k"};
$rv->{$k} = $v if defined $v;
}
- foreach my $k (qw(altid)) { # TODO: more arrays
+
+ # TODO: more arrays, we should support multi-value for
+ # more things to encourage decentralization
+ foreach my $k (qw(altid nntpmirror)) {
if (defined(my $v = $self->{"$pfx.$k"})) {
$rv->{$k} = ref($v) eq 'ARRAY' ? $v : [ $v ];
}
}
}
+sub nntp_url {
+ my ($self) = @_;
+ $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->{-pi_config}->{'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;
+ foreach (@$mirrors) {
+ my $u = m!\Anntps?://! ? $_ : "nntp://$_";
+ if ($u =~ m!\Anntps?://[^/]+/?\z!) {
+ if ($group) {
+ $u .= '/' if $u !~ m!/\z!;
+ $u .= $group;
+ } else {
+ warn
+"publicinbox.$self->{name}.nntpmirror=$_ missing newsgroup name\n";
+ }
+ }
+ # else: allow full URLs like:
+ # nntp://news.example.com/alt.example
+ push @m, $u;
+ }
+ my %seen = map { $_ => 1 } @urls;
+ foreach my $u (@m) {
+ next if $seen{$u};
+ $seen{$u} = 1;
+ push @urls, $u;
+ }
+ }
+ \@urls;
+ };
+}
+
sub nntp_usable {
my ($self) = @_;
my $ret = $self->mm && $self->search;
chop $http;
my %seen = ( $http => 1 );
my @urls = ($http);
- my $need_tor;
foreach my $u (@{$obj->cloneurl}) {
next if $seen{$u};
- $need_tor = 1 if $u =~ m!\A[^:]+://\w+\.onion/!;
$seen{$u} = 1;
push @urls, $u =~ /\Ahttps?:/ ? qq(<a\nhref="$u">$u</a>) : $u;
}
join("\n", map { "\tgit clone --mirror $_" } @urls);
}
- if ($need_tor) {
+ my @nntp = map { qq(<a\nhref="$_">$_</a>) } @{$obj->nntp_url};
+ if (@nntp) {
+ $urls .= "\n\n";
+ $urls .= @nntp == 1 ? 'Newsgroup' : 'Newsgroups are';
+ $urls .= ' available over NNTP:';
+ $urls .= "\n\t" . join("\n\t", @nntp) . "\n";
+ }
+ if ($urls =~ m!\b[^:]+://\w+\.onion/!) {
$urls .= "\n note: .onion URLs require Tor: ";
$urls .= qq[<a\nhref="$TOR_URL">$TOR_URL</a>];
}
search => sub { undef },
base_url => sub { 'http://example.com/' },
cloneurl => sub {[]},
+ nntp_url => sub {[]},
description => sub { '' }),
};
$ctx->{-inbox}->{-primary_address} = 'test@example.com';