From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 5/6] mbox: support uncompressed mbox
Date: Sat, 22 Aug 2015 11:41:23 +0000 [thread overview]
Message-ID: <1440243684-2205-5-git-send-email-e@80x24.org> (raw)
In-Reply-To: <1440243684-2205-1-git-send-email-e@80x24.org>
Some folks may want to view the mbox inline as a string of raw text,
when guessing URLs. Let them do this...
---
lib/PublicInbox/Mbox.pm | 18 +++++++++++-------
lib/PublicInbox/WWW.pm | 12 +++++++-----
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index 5f5612a..d49e9b3 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -7,10 +7,10 @@ use warnings;
use PublicInbox::MID qw/mid_compressed mid2path/;
sub thread_mbox {
- my ($ctx, $srch) = @_;
+ my ($ctx, $srch, $sfx) = @_;
sub {
my ($response) = @_; # Plack callback
- emit_mbox($response, $ctx, $srch);
+ emit_mbox($response, $ctx, $srch, $sfx);
}
}
@@ -38,14 +38,18 @@ sub emit_msg {
}
sub emit_mbox {
- my ($response, $ctx, $srch) = @_;
- eval { require IO::Compress::Gzip };
- return need_gzip($response) if $@;
+ my ($response, $ctx, $srch, $sfx) = @_;
+ my $type = 'mbox';
+ if ($sfx) {
+ eval { require IO::Compress::Gzip };
+ return need_gzip($response) if $@;
+ $type = 'gzip';
+ }
# http://www.iana.org/assignments/media-types/application/gzip
# http://www.iana.org/assignments/media-types/application/mbox
- my $fh = $response->([200, ['Content-Type' => 'application/gzip']]);
- $fh = PublicInbox::MboxGz->new($fh);
+ my $fh = $response->([200, ['Content-Type' => "application/$type"]]);
+ $fh = PublicInbox::MboxGz->new($fh) if $sfx;
require PublicInbox::GitCatFile;
require Email::Simple;
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 30a7a43..33c7110 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -53,9 +53,10 @@ sub run {
} elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)\.html\z!o) {
invalid_list_mid(\%ctx, $1, $2) || get_thread(\%ctx, $cgi);
- } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)\.mbox\.gz!o) {
+ } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)\.mbox(\.gz)?\z!o) {
my $sfx = $3;
- invalid_list_mid(\%ctx, $1, $2) || get_thread_mbox(\%ctx, $cgi);
+ invalid_list_mid(\%ctx, $1, $2) ||
+ get_thread_mbox(\%ctx, $cgi, $sfx);
} elsif ($path_info =~ m!$LISTNAME_RE/f/\S+\.txt\z!o) {
invalid_list_mid(\%ctx, $1, $2) ||
@@ -331,15 +332,16 @@ sub msg_pfx {
"../f/$href.html";
}
-# /$LISTNAME/t/$MESSAGE_ID.mbox.gz -> search results as gzipped mbox
+# /$LISTNAME/t/$MESSAGE_ID.mbox -> thread as mbox
+# /$LISTNAME/t/$MESSAGE_ID.mbox.gz -> thread as gzipped mbox
# note: I'm not a big fan of other compression formats since they're
# significantly more expensive on CPU than gzip and less-widely available,
# especially on older systems. Stick to zlib since that's what git uses.
sub get_thread_mbox {
- my ($ctx, $cgi) = @_;
+ my ($ctx, $cgi, $sfx) = @_;
my $srch = searcher($ctx) or return need_search($ctx);
require PublicInbox::Mbox;
- PublicInbox::Mbox::thread_mbox($ctx, $srch);
+ PublicInbox::Mbox::thread_mbox($ctx, $srch, $sfx);
}
1;
--
EW
next prev parent reply other threads:[~2015-08-22 11:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-22 11:41 [PATCH 1/6] search: split search indexing to a separate file Eric Wong
2015-08-22 11:41 ` [PATCH 2/6] view: misc cleanups and simplifications Eric Wong
2015-08-22 11:41 ` [PATCH 3/6] view: reference total followups Eric Wong
2015-08-22 11:41 ` [PATCH 4/6] search: consistently pass options and flags Eric Wong
2015-08-22 11:41 ` Eric Wong [this message]
2015-08-22 11:41 ` [PATCH 6/6] view: wire up mbox.gz links Eric Wong
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=1440243684-2205-5-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).