]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/NNTP.pm
nntp: attempt RFC 5536 3.1.5-conformant Path: headers
[public-inbox.git] / lib / PublicInbox / NNTP.pm
index 88fe2bb03a0797e424224771d8eab5e2c411784f..2f821fa6b9b51902ddc221c9ca3f225d06e708af 100644 (file)
@@ -53,7 +53,7 @@ sub new ($$$) {
        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);
@@ -415,10 +415,6 @@ sub set_nntp_headers ($$) {
        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).
@@ -432,12 +428,21 @@ sub set_nntp_headers ($$) {
                $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);