X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FInbox.pm;h=414973c6dedd9b6137852695092877cc0b62e7a1;hb=50c1b933afec4937ebc99e1d372cef2dc6b295c2;hp=4fbbb522f9c9d208dd54a240a3b68662f90163a5;hpb=e0b7cf5eb5e6828d07094fa44be67e2d7d63e722;p=public-inbox.git diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index 4fbbb522..414973c6 100644 --- a/lib/PublicInbox/Inbox.pm +++ b/lib/PublicInbox/Inbox.pm @@ -87,7 +87,7 @@ sub search { my ($self) = @_; $self->{search} ||= eval { _weaken_later($self); - PublicInbox::Search->new($self->{mainrepo}); + PublicInbox::Search->new($self->{mainrepo}, $self->{altid}); }; } @@ -147,6 +147,52 @@ sub base_url { } } +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; @@ -162,6 +208,18 @@ sub msg_by_path ($$;$) { $str; } +sub msg_by_smsg ($$;$) { + my ($self, $smsg, $ref) = @_; + + # backwards compat to fallback to msg_by_mid + # TODO: remove if we bump SCHEMA_VERSION in Search.pm: + defined(my $blob = $smsg->blob) or return msg_by_mid($self, $smsg->mid); + + my $str = git($self)->cat_file($blob, $ref); + $$str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s if $str; + $str; +} + sub path_check { my ($self, $path) = @_; git($self)->check('HEAD:'.$path);