unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: Eric Wong <e@80x24.org>
Subject: [PATCH] .txt links return an mbox instead
Date: Sun, 23 Aug 2015 00:02:34 +0000	[thread overview]
Message-ID: <1440288155-20688-1-git-send-email-e@80x24.org> (raw)

This improves compatibility and allows individual messages
to be concatenated into an existing mbox without further
modifications.  "git format-patch" does something similar
(but does not do "From " line escaping(!))
---
 Documentation/design_www.txt |  2 +-
 lib/PublicInbox/Mbox.pm      | 12 +++++++++++-
 lib/PublicInbox/WWW.pm       |  7 ++++---
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/Documentation/design_www.txt b/Documentation/design_www.txt
index 9289704..55e9268 100644
--- a/Documentation/design_www.txt
+++ b/Documentation/design_www.txt
@@ -10,7 +10,7 @@ URL naming
 
 ### Stable endpoints
 /$LISTNAME/m/$MESSAGE_ID.html                   -> HTML content (short quotes)
-/$LISTNAME/m/$MESSAGE_ID.txt                    -> raw original
+/$LISTNAME/m/$MESSAGE_ID.txt                    -> raw mbox
 /$LISTNAME/m/$MESSAGE_ID                        -> 301 to .html version
 /$LISTNAME/f/$MESSAGE_ID.html                   -> HTML content (full quotes)
 /$LISTNAME/f/$MESSAGE_ID                        -> 301 to .html version
diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index d49e9b3..bc4d639 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -5,6 +5,7 @@ package PublicInbox::Mbox;
 use strict;
 use warnings;
 use PublicInbox::MID qw/mid_compressed mid2path/;
+require Email::Simple;
 
 sub thread_mbox {
 	my ($ctx, $srch, $sfx) = @_;
@@ -14,6 +15,16 @@ sub thread_mbox {
 	}
 }
 
+sub emit1 {
+	my $simple = Email::Simple->new(pop);
+	sub {
+		my ($response) = @_;
+		# single message should be easily renderable in browsers
+		my $fh = $response->([200, ['Content-Type'=>'text/plain']]);
+		emit_msg($fh, $simple);
+	}
+}
+
 sub emit_msg {
 	my ($fh, $simple) = @_; # Email::Simple object
 
@@ -52,7 +63,6 @@ sub emit_mbox {
 	$fh = PublicInbox::MboxGz->new($fh) if $sfx;
 
 	require PublicInbox::GitCatFile;
-	require Email::Simple;
 	my $mid = mid_compressed($ctx->{mid});
 	my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
 	my %opts = (offset => 0);
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 33c7110..86c64fb 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -157,11 +157,12 @@ sub mid2blob {
 	}
 }
 
-# /$LISTNAME/m/$MESSAGE_ID.txt                    -> raw original
+# /$LISTNAME/m/$MESSAGE_ID.txt                    -> raw mbox
 sub get_mid_txt {
 	my ($ctx, $cgi) = @_;
-	my $x = mid2blob($ctx);
-	$x ? [ 200, [ 'Content-Type' => 'text/plain' ], [ $$x ] ] : r404();
+	my $x = mid2blob($ctx) or return r404();
+	require PublicInbox::Mbox;
+	PublicInbox::Mbox::emit1($x);
 }
 
 # /$LISTNAME/m/$MESSAGE_ID.html                   -> HTML content (short quotes)
-- 
EW


                 reply	other threads:[~2015-08-23  0:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly 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=1440288155-20688-1-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).