unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [RFC] atom: implement message threading per RFC 4685
@ 2016-12-13  2:33 Eric Wong
  2016-12-14 21:04 ` [RFC 2/1] wwwtext: link to RFC4685 (Atom Threading) Eric Wong
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2016-12-13  2:33 UTC (permalink / raw)
  To: meta

This will allows certain feed readers to render a message thread
as described in <https://www.jwz.org/doc/threading.html>.

Feed readers with knowledge of of RFC 4685 are unknown to us at
this time, but perhaps this will encourage future implementations.

Existing feed readers I've tested (newsbeuter, feed2imap) seem
to ignore these tags gracefully without degradation.
---
 TODO                             |  2 --
 lib/PublicInbox/WwwAtomStream.pm | 40 ++++++++++++++++++++++++++--------------
 2 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/TODO b/TODO
index d2efcbb..ee3db1a 100644
--- a/TODO
+++ b/TODO
@@ -34,8 +34,6 @@ all need to be considered for everything we introduce)
   the links should point to an anchor tag within the same page,
   instead; giving the user options.
 
-* implement RFC 4685 (Atom message threading)
-
 * configurable constants (index limits, search results)
 
 * handle messages with multiple Message-IDs
diff --git a/lib/PublicInbox/WwwAtomStream.pm b/lib/PublicInbox/WwwAtomStream.pm
index 5720384..a6817b3 100644
--- a/lib/PublicInbox/WwwAtomStream.pm
+++ b/lib/PublicInbox/WwwAtomStream.pm
@@ -9,10 +9,10 @@ use warnings;
 # FIXME: locale-independence:
 use POSIX qw(strftime);
 use Date::Parse qw(strptime);
-
+use Digest::SHA qw(sha1_hex);
 use PublicInbox::Address;
 use PublicInbox::Hval qw(ascii_html);
-use PublicInbox::MID qw/mid_clean mid2path mid_escape/;
+use PublicInbox::MID qw/mid_clean mid_escape/;
 
 # called by PSGI server after getline:
 sub close {}
@@ -72,7 +72,8 @@ sub atom_header {
 	my $mtime = (stat($ibx->{mainrepo}))[9] || time;
 
 	qq(<?xml version="1.0" encoding="us-ascii"?>\n) .
-	qq{<feed\nxmlns="http://www.w3.org/2005/Atom">} .
+	qq(<feed\nxmlns="http://www.w3.org/2005/Atom"\n) .
+	qq(xmlns:thr="http://purl.org/syndication/thread/1.0">) .
 	qq{$title} .
 	qq(<link\nrel="alternate"\ntype="text/html") .
 		qq(\nhref="$base_url"/>) .
@@ -81,22 +82,33 @@ sub atom_header {
 	feed_updated(gmtime($mtime));
 }
 
+sub mid2uuid ($) {
+	my ($mid) = @_;
+	utf8::encode($mid); # really screwed up In-Reply-To fields exist
+	$mid = sha1_hex($mid);
+	my $h = '[a-f0-9]';
+	my (@uuid5) = ($mid =~ m!\A($h{8})($h{4})($h{4})($h{4})($h{12})!o);
+	'urn:uuid:' . join('-', @uuid5);
+}
+
 # returns undef or string
 sub feed_entry {
 	my ($self, $mime) = @_;
 	my $ctx = $self->{ctx};
 	my $hdr = $mime->header_obj;
 	my $mid = mid_clean($hdr->header_raw('Message-ID'));
-
-	my $uuid = mid2path($mid);
-	$uuid =~ tr!/!!d;
-	my $h = '[a-f0-9]';
-	my (@uuid5) = ($uuid =~ m!\A($h{8})($h{4})($h{4})($h{4})($h{12})!o);
-	$uuid = 'urn:uuid:' . join('-', @uuid5);
-
-	$mid = PublicInbox::Hval->new_msgid($mid);
-	my $href = $ctx->{feed_base_url} . $mid->{href}. '/';
-
+	my $irt = PublicInbox::View::in_reply_to($hdr);
+	my $uuid = mid2uuid($mid);
+	my $base = $ctx->{feed_base_url};
+	if (defined $irt) {
+		my $irt_uuid = mid2uuid($irt);
+		$irt = mid_escape($irt);
+		$irt = qq(<thr:in-reply-to\nref="$irt_uuid"\n).
+			qq(href="$base$irt/"/>);
+	} else {
+		$irt = '';
+	}
+	my $href = $base . mid_escape($mid) . '/';
 	my $date = $hdr->header('Date');
 	my @t = eval { strptime($date) } if defined $date;
 	@t = gmtime(time) unless scalar @t;
@@ -124,7 +136,7 @@ sub feed_entry {
 		PublicInbox::View::multipart_text_as_html($mime, $href) .
 		'</pre>' .
 		qq!</div></content><link\nhref="$href"/>!.
-		"<id>$uuid</id></entry>";
+		"<id>$uuid</id>$irt</entry>";
 }
 
 sub feed_updated {
-- 
EW


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [RFC 2/1] wwwtext: link to RFC4685 (Atom Threading)
  2016-12-13  2:33 [RFC] atom: implement message threading per RFC 4685 Eric Wong
@ 2016-12-14 21:04 ` Eric Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2016-12-14 21:04 UTC (permalink / raw)
  To: meta

This should give this feature some more visibility.
---
 lib/PublicInbox/WwwText.pm | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm
index 2e58eeb..449cb49 100644
--- a/lib/PublicInbox/WwwText.pm
+++ b/lib/PublicInbox/WwwText.pm
@@ -181,6 +181,10 @@ message threading
 	$WIKI_URL/Atom_(standard)
 	https://tools.ietf.org/html/rfc4287
 
+      Atom Threading Extensions (RFC4685) is supported:
+
+	https://tools.ietf.org/html/rfc4685
+
     Finally, the gzipped mbox for a thread is available for
     downloading and importing into your favorite mail client:
 
-- 
EW

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-12-14 21:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-13  2:33 [RFC] atom: implement message threading per RFC 4685 Eric Wong
2016-12-14 21:04 ` [RFC 2/1] wwwtext: link to RFC4685 (Atom Threading) Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).