]> Sergey Matveev's repositories - public-inbox.git/commitdiff
.txt links return an mbox instead
authorEric Wong <e@80x24.org>
Sun, 23 Aug 2015 00:02:34 +0000 (00:02 +0000)
committerEric Wong <e@80x24.org>
Sun, 23 Aug 2015 00:02:50 +0000 (00:02 +0000)
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
lib/PublicInbox/Mbox.pm
lib/PublicInbox/WWW.pm

index 92897043ed85d80ae13578447b848bfe10bb889e..55e9268c90506135009d1212c70c1a8e3f196ae0 100644 (file)
@@ -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
index d49e9b39da0e9d96864a4c4c8e04aa56a5537505..bc4d639ebad0809f3591cc38ecea7bb736039cb0 100644 (file)
@@ -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);
index 33c7110147bf451627eb6e5d7b0dac7c4d669cea..86c64fb665746815a1839a9584665126a988589d 100644 (file)
@@ -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)