From fbfd63996ddfc9a23b8a1e0f8756e378f2e196ba Mon Sep 17 00:00:00 2001 From: Jonathan Corbet Date: Sat, 13 Oct 2018 15:42:21 -0600 Subject: Add Xrefs to over/xover lines Putting the Xref field into xover lines allows newsreaders to mark cross-posted messages read when catching up a group. That, in turn, massively improves the life of crazy people who try to follow dozens of kernel lists, where emails are often heavily cross-posted. --- lib/PublicInbox/NNTP.pm | 13 +++++++------ t/nntpd.t | 11 ++++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index cbd4ecf1..022bb809 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -28,7 +28,7 @@ use constant { sub now () { clock_gettime(CLOCK_MONOTONIC) }; -my @OVERVIEW = qw(Subject From Date Message-ID References); +my @OVERVIEW = qw(Subject From Date Message-ID References Xref); my $OVERVIEW_FMT = join(":\r\n", @OVERVIEW, qw(Bytes Lines)) . ":\r\n"; my $LIST_HEADERS = join("\r\n", @OVERVIEW, qw(:bytes :lines Xref To Cc)) . "\r\n"; @@ -812,8 +812,8 @@ sub cmd_xrover ($;$) { }); } -sub over_line ($$) { - my ($num, $smsg) = @_; +sub over_line ($$$$) { + my ($self, $ng, $num, $smsg) = @_; # n.b. field access and procedural calls can be # 10%-15% faster than OO method calls: my $s = join("\t", $num, @@ -823,7 +823,8 @@ sub over_line ($$) { "<$smsg->{mid}>", $smsg->{references}, $smsg->{bytes}, - $smsg->{lines}); + $smsg->{lines}, + "Xref: " . xref($self, $ng, $num, $smsg->{mid})); utf8::encode($s); $s } @@ -839,7 +840,7 @@ sub cmd_over ($;$) { # Only set article number column if it's the current group my $self_ng = $self->{ng}; $n = 0 if (!$self_ng || $self_ng ne $ng); - more($self, over_line($n, $smsg)); + more($self, over_line($self, $ng, $n, $smsg)); '.'; } else { cmd_xover($self, $range); @@ -861,7 +862,7 @@ sub cmd_xover ($;$) { # OVERVIEW.FMT more($self, join("\r\n", map { - over_line($_->{num}, $_); + over_line($self, $self->{ng}, $_->{num}, $_); } @$msgs)); $cur = $msgs->[-1]->{num} + 1; }); diff --git a/t/nntpd.t b/t/nntpd.t index f8599080..9c1d0762 100644 --- a/t/nntpd.t +++ b/t/nntpd.t @@ -196,7 +196,9 @@ EOF '', '', $len, - '1' ] }, "XOVER range works"); + '1', + 'Xref: '. hostname . ' test-nntpd:1'] }, + "XOVER range works"); is_deeply($n->xover('1'), { '1' => ["Testing for El\xc3\xa9anor", @@ -205,7 +207,9 @@ EOF '', '', $len, - '1' ] }, "XOVER by article works"); + '1', + 'Xref: '. hostname . ' test-nntpd:1'] }, + "XOVER by article works"); is_deeply($n->head(1), $n->head(''), 'HEAD OK'); is_deeply($n->body(1), $n->body(''), 'BODY OK'); @@ -225,7 +229,8 @@ EOF is($r[1], "0\tTesting for El\xc3\xa9anor\t" . "El\xc3\xa9anor \t" . "Thu, 01 Jan 1970 06:06:06 +0000\t" . - "$mid\t\t$len\t1", + "$mid\t\t$len\t1" . + "\tXref: " . hostname . " test-nntpd:0", 'OVER by Message-ID works'); is($r[2], '.', 'correctly terminated response'); } -- cgit v1.2.3-24-ge0c7