+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->{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 = mm($self) && over($self);
+ $self->{mm} = $self->{over} = $self->{search} = undef;
+ $ret;
+}
+
+sub msg_by_path ($$;$) {
+ my ($self, $path, $ref) = @_;
+ # TODO: allow other refs:
+ my $str = git($self)->cat_file('HEAD:'.$path, $ref);
+ $$str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s if $str;
+ $str;
+}
+
+sub msg_by_smsg ($$;$) {
+ my ($self, $smsg, $ref) = @_;
+
+ # ghosts may have undef smsg (from SearchThread.node) or
+ # no {blob} field
+ return unless defined $smsg;
+ defined(my $blob = $smsg->{blob}) or return;
+
+ my $str = git($self)->cat_file($blob, $ref);
+ $$str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s if $str;
+ $str;
+}
+
+sub smsg_mime {
+ my ($self, $smsg, $ref) = @_;
+ if (my $s = msg_by_smsg($self, $smsg, $ref)) {
+ $smsg->{mime} = PublicInbox::MIME->new($s);
+ return $smsg;
+ }
+}
+
+sub mid2num($$) {
+ my ($self, $mid) = @_;
+ my $mm = mm($self) or return;
+ $mm->num_for($mid);
+}
+
+sub smsg_by_mid ($$) {
+ my ($self, $mid) = @_;
+ my $over = over($self) or return;
+ # favor the Message-ID we used for the NNTP article number:
+ defined(my $num = mid2num($self, $mid)) or return;
+ my $smsg = $over->get_art($num) or return;
+ PublicInbox::SearchMsg::psgi_cull($smsg);
+}
+
+sub msg_by_mid ($$;$) {
+ my ($self, $mid, $ref) = @_;
+
+ over($self) or
+ return msg_by_path($self, mid2path($mid), $ref);
+
+ my $smsg = smsg_by_mid($self, $mid);
+ $smsg ? msg_by_smsg($self, $smsg, $ref) : undef;
+}
+
+sub recent {
+ my ($self, $opts, $after, $before) = @_;
+ over($self)->recent($opts, $after, $before);
+}
+
+sub modified {
+ my ($self) = @_;
+ if (my $over = over($self)) {
+ my $msgs = $over->recent({limit => 1});
+ if (my $smsg = $msgs->[0]) {
+ return $smsg->{ts};
+ }
+ return time;
+ }
+ git($self)->modified; # v1
+}
+