user/dev discussion of public-inbox itself
 help / color / Atom feed
From: Eric Wong <e@80x24.org>
To: Dave Taht <dave@taht.net>
Cc: meta@public-inbox.org
Subject: [PATCH] nntp: ensure Message-ID is not folded for leafnode
Date: Thu, 13 Jun 2019 20:46:52 +0000
Message-ID: <20190613-204649-aaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh@horrible> (raw)
In-Reply-To: <87lfy5mkxy.fsf@taht.net>

Dave Taht <dave@taht.net> wrote:
> Eric Wong <e@80x24.org> writes:
> > However, I've also noticed leafnode (finally tried it) also
> > fails if a Message-ID is too long and spans multiple lines
> > (those were from outlook.com, go figure).
> 
> Thanks! Is there a way to reformat that?

Yeah, this seems to work:

-----------8<------------
Subject: [PATCH] nntp: ensure Message-ID is not folded for leafnode

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 |  7 +++++++
 t/nntpd.t               | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 1d07220..d409e78 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -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
 }
 
diff --git a/t/nntpd.t b/t/nntpd.t
index c73cc12..cce21ee 100644
--- 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:
 	{
-- 
EW

      reply index

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-17 16:28 interop with leafnode Dave Taht
2018-10-27  0:10 ` Eric Wong
2018-10-27  0:33   ` Dave Taht
2018-10-27  0:43     ` Eric Wong
2018-10-27 16:07       ` Dave Taht
2019-05-05 21:40   ` Eric Wong
2019-06-13  7:00 ` Eric Wong
2019-06-13 17:52   ` Dave Taht
2019-06-13 20:46     ` Eric Wong [this message]

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190613-204649-aaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh@horrible \
    --to=e@80x24.org \
    --cc=dave@taht.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox