]> Sergey Matveev's repositories - public-inbox.git/commitdiff
nntp: ensure Message-ID is not folded for leafnode
authorEric Wong <e@80x24.org>
Thu, 13 Jun 2019 20:46:52 +0000 (20:46 +0000)
committerEric Wong <e@80x24.org>
Thu, 13 Jun 2019 20:47:16 +0000 (20:47 +0000)
Leafnode cannot handle Message-ID headers which are too long and
require folding via Email::Simple::Header.  Since there are
already many of these messages in git with the header already
folded, we need to handle the unfolding when emitting the
message via NNTP.

As far as we know, Leafnode is the only client software
incapable of handling this case.

lib/PublicInbox/NNTP.pm
t/nntpd.t

index 1d07220de1ec977fb30ba296c93a989f8ddafe11..d409e7828f29e2d6d75f8d8309fee027d3665c69 100644 (file)
@@ -519,6 +519,13 @@ sub _header ($) {
        my $hdr = $_[0]->header_obj->as_string;
        utf8::encode($hdr);
        $hdr =~ s/(?<!\r)\n/\r\n/sg;
+
+       # for leafnode compatibility, we need to ensure Message-ID headers
+       # are only a single line.  We can't subclass Email::Simple::Header
+       # and override _default_fold_at in here, either; since that won't
+       # affect messages already in the archive.
+       $hdr =~ s/^(Message-ID:)[ \t]*\r\n[ \t]+([^\r]+)\r\n/$1 $2\r\n/igsm;
+
        $hdr
 }
 
index c73cc122eaa009618fd6bab0df357fe5b23e6173..cce21eeb620d09bfc9c783993ce5de743b94d9fa 100644 (file)
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -231,6 +231,26 @@ EOF
                ok($date >= $t0, 'valid date after start');
                ok($date <= $t1, 'valid date before stop');
        }
+       if ('leafnode interop') {
+               my $for_leafnode = PublicInbox::MIME->new(<<"");
+From: longheader\@example.com
+To: $addr
+Subject: none
+Date: Fri, 02 Oct 1993 00:00:00 +0000
+
+               my $long_hdr = 'for-leafnode-'.('y'x200).'@example.com';
+               $for_leafnode->header_set('Message-ID', "<$long_hdr>");
+               $im->add($for_leafnode);
+               $im->done;
+               if ($version == 1) {
+                       my $s = PublicInbox::SearchIdx->new($mainrepo, 1);
+                       $s->index_sync;
+               }
+               my $hdr = $n->head("<$long_hdr>");
+               my $expect = qr/\AMessage-ID: /i . qr/\Q<$long_hdr>\E/;
+               ok(scalar(grep(/$expect/, @$hdr)), 'Message-ID not folded');
+               ok(scalar(grep(/^Path:/, @$hdr)), 'Path: header found');
+       }
 
        # pipelined requests:
        {