]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Mbox.pm
www: fix absolute URLs when mounted under a subdir
[public-inbox.git] / lib / PublicInbox / Mbox.pm
index 0c3e52fe42367382d922b01c0e2f77f6b0ee84d1..67b671f5f4a8f31aa3bfca611ae78cc5001c10cf 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2015-2019 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # Streaming (via getline) interface for formatting messages as an mboxrd.
@@ -60,10 +60,12 @@ sub getline {
 
 sub close {} # noop
 
+# /$INBOX/$MESSAGE_ID/raw
 sub emit_raw {
        my ($ctx) = @_;
        my $mid = $ctx->{mid};
        my $ibx = $ctx->{-inbox};
+       $ctx->{base_url} = $ibx->base_url($ctx->{env});
        my ($mref, $more, $id, $prev, $next);
        if (my $over = $ibx->over) {
                my $smsg = $over->next_by_mid($mid, \$id, \$prev) or return;
@@ -97,7 +99,7 @@ sub msg_hdr ($$;$) {
                $header_obj->header_set($d);
        }
        my $ibx = $ctx->{-inbox};
-       my $base = $ibx->base_url($ctx->{env});
+       my $base = $ctx->{base_url};
        $mid = $ctx->{mid} unless defined $mid;
        $mid = mid_escape($mid);
        my @append = (
@@ -125,7 +127,9 @@ sub msg_hdr ($$;$) {
 
 sub msg_body ($) {
        # mboxrd quoting style
-       # ref: http://www.qmail.org/man/man5/mbox.html
+       # https://en.wikipedia.org/wiki/Mbox#Modified_mbox
+       # https://www.loc.gov/preservation/digital/formats/fdd/fdd000385.shtml
+       # https://web.archive.org/http://www.qmail.org/man/man5/mbox.html
        $_[0] =~ s/^(>*From )/>$1/gm;
        $_[0] .= "\n";
 }
@@ -244,6 +248,7 @@ use PublicInbox::Hval qw/to_filename/;
 sub new {
        my ($class, $ctx, $cb) = @_;
        my $buf = '';
+       $ctx->{base_url} = $ctx->{-inbox}->base_url($ctx->{env});
        bless {
                buf => \$buf,
                gz => IO::Compress::Gzip->new(\$buf, Time => 0),