user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 5/6] mbox: support uncompressed mbox
  @ 2015-08-22 11:41  7% ` Eric Wong
  0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2015-08-22 11:41 UTC (permalink / raw)
  To: meta

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


^ permalink raw reply related	[relevance 7%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2015-08-22 11:41     [PATCH 1/6] search: split search indexing to a separate file Eric Wong
2015-08-22 11:41  7% ` [PATCH 5/6] mbox: support uncompressed mbox Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).