my $wbuf;
if ($sock->can('accept_SSL') && !$sock->accept_SSL) {
return CORE::close($sock) if $! != EAGAIN;
- $ev = PublicInbox::TLS::epollbit();
+ $ev = PublicInbox::TLS::epollbit() or return CORE::close($sock);
$wbuf = [ \&PublicInbox::DS::accept_tls_step, \&greet ];
}
$self->SUPER::new($sock, $ev | EPOLLONESHOT);
wildmat2re($wildmat);
foreach my $ng (@{$self->{nntpd}->{grouplist}}) {
$ng->{newsgroup} =~ $wildmat or next;
- my $c = eval { $ng->mm->created_at } || time;
+ my $c = eval { $ng->uidvalidity } // time;
more($self, "$ng->{newsgroup} $c $ng->{-primary_address}");
}
}
sub group_line ($$) {
my ($self, $ng) = @_;
my ($min, $max) = $ng->mm->minmax;
- more($self, "$ng->{newsgroup} $max $min n") if defined $min && defined $max;
+ more($self, "$ng->{newsgroup} $max $min n");
}
sub cmd_newgroups ($$$;$$) {
# TODO dists
more($self, '231 list of new newsgroups follows');
foreach my $ng (@{$self->{nntpd}->{grouplist}}) {
- my $c = eval { $ng->mm->created_at } || 0;
+ my $c = eval { $ng->uidvalidity } // 0;
next unless $c > $ts;
group_line($self, $ng);
}
$self->{ng} = $ng;
my ($min, $max) = $ng->mm->minmax;
- $min ||= 0;
- $max ||= 0;
$self->{article} = $min;
my $est_size = $max - $min;
"211 $est_size $min $max $group";
my ($hdr, $smsg) = @_;
my ($mid) = $smsg->{mid};
- # why? leafnode requires a Path: header for some inexplicable
- # reason. We'll fake the shortest one possible.
- $hdr->header_set('Path', 'y');
-
# leafnode (and maybe other NNTP clients) have trouble dealing
# with v2 messages which have multiple Message-IDs (either due
# to our own content-based dedupe or buggy git-send-email versions).
$hdr->header_set('X-Alt-Message-ID', @alt);
}
- # clobber some
+ # clobber some existing headers
my $ibx = $smsg->{-ibx};
my $xref = xref($smsg->{nntp}, $ibx, $smsg->{num}, $mid);
$hdr->header_set('Xref', $xref);
- $xref =~ s/:[0-9]+//g;
- $hdr->header_set('Newsgroups', (split(/ /, $xref, 2))[1]);
+
+ # RFC 5536 3.1.4
+ my ($server_name, $newsgroups) = split(/ /, $xref, 2);
+ $newsgroups =~ s/:[0-9]+\b//g; # drop NNTP article numbers
+ $newsgroups =~ tr/ /,/;
+ $hdr->header_set('Newsgroups', $newsgroups);
+
+ # *something* here is required for leafnode, try to follow
+ # RFC 5536 3.1.5...
+ $hdr->header_set('Path', $server_name . '!not-for-mail');
+
header_append($hdr, 'List-Post', "<mailto:$ibx->{-primary_address}>");
if (my $url = $ibx->base_url) {
$mid = mid_escape($mid);
}
}
-sub art_lookup ($$) {
- my ($self, $art) = @_;
+sub art_lookup ($$$) {
+ my ($self, $art, $code) = @_;
my $ng = $self->{ng};
my ($n, $mid);
my $err;
found:
my $smsg = $ng->over->get_art($n) or return $err;
$smsg->{-ibx} = $ng;
- $smsg;
+ if ($code == 223) { # STAT
+ set_art($self, $n);
+ "223 $n <$smsg->{mid}> article retrieved - " .
+ "request text separately";
+ } else { # HEAD | BODY | ARTICLE
+ $smsg->{nntp} = $self;
+ $smsg->{nntp_code} = $code;
+ set_art($self, $art);
+ # this dereferences to `undef'
+ ${git_async_cat($ng->git, $smsg->{blob}, \&blob_cb, $smsg)};
+ }
}
sub msg_body_write ($$) {
sub blob_cb { # called by git->cat_async via git_async_cat
my ($bref, $oid, $type, $size, $smsg) = @_;
my $self = $smsg->{nntp};
- my $code = $smsg->{nntp_code} // 220;
+ my $code = $smsg->{nntp_code};
if (!defined($oid)) {
# it's possible to have TOCTOU if an admin runs
# public-inbox-(edit|purge), just move onto the next message
sub cmd_article ($;$) {
my ($self, $art) = @_;
- my $smsg = art_lookup($self, $art);
- return $smsg unless ref $smsg;
- set_art($self, $art);
- $smsg->{nntp} = $self;
- ${git_async_cat($smsg->{-ibx}->git, $smsg->{blob}, \&blob_cb, $smsg)};
+ art_lookup($self, $art, 220);
}
sub cmd_head ($;$) {
my ($self, $art) = @_;
- my $smsg = art_lookup($self, $art);
- return $smsg unless ref $smsg;
- set_art($self, $art);
- $smsg->{nntp} = $self;
- $smsg->{nntp_code} = 221;
- ${git_async_cat($smsg->{-ibx}->git, $smsg->{blob}, \&blob_cb, $smsg)};
+ art_lookup($self, $art, 221);
}
sub cmd_body ($;$) {
my ($self, $art) = @_;
- my $smsg = art_lookup($self, $art);
- return $smsg unless ref $smsg;
- set_art($self, $art);
- $smsg->{nntp} = $self;
- $smsg->{nntp_code} = 222;
- ${git_async_cat($smsg->{-ibx}->git, $smsg->{blob}, \&blob_cb, $smsg)};
+ art_lookup($self, $art, 222);
}
sub cmd_stat ($;$) {
my ($self, $art) = @_;
- my $smsg = art_lookup($self, $art); # art may be msgid
- return $smsg unless ref $smsg;
- $art = $smsg->{num};
- set_art($self, $art);
- "223 $art <$smsg->{mid}> article retrieved - request text separately";
+ art_lookup($self, $art, 223); # art may be msgid
}
sub cmd_ihave ($) { '435 article not wanted - do not send it' }