X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FMbox.pm;h=88daba752153385ed74656cae0699078a65139c3;hb=31c516e54a6fd9df6122aaf3383f95ce9fc06834;hp=63ec605f6b1ecf0dd47534352335d3c423f36e4b;hpb=4b313dc74bc9bb84a542b7ec920cdb92879e7523;p=public-inbox.git diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm index 63ec605f..88daba75 100644 --- a/lib/PublicInbox/Mbox.pm +++ b/lib/PublicInbox/Mbox.pm @@ -6,16 +6,18 @@ package PublicInbox::Mbox; use strict; use warnings; -use PublicInbox::MID qw/mid_clean/; -use URI::Escape qw/uri_escape_utf8/; -use Plack::Util; +use PublicInbox::MID qw/mid_clean mid_escape/; require Email::Simple; sub emit1 { my ($ctx, $msg) = @_; $msg = Email::Simple->new($msg); - # single message should be easily renderable in browsers - [200, ['Content-Type', 'text/plain'], [ msg_str($ctx, $msg)] ] + + # single message should be easily renderable in browsers, + # unless obfuscation is enabled :< + [ 200, [ 'Content-Type', + $ctx->{-inbox}->{obfuscate} ? 'application/mbox' : 'text/plain' ], + [ msg_str($ctx, $msg)] ] } sub msg_str { @@ -28,9 +30,9 @@ sub msg_str { $header_obj->header_set($d); } my $ibx = $ctx->{-inbox}; - my $base = $ibx->base_url($ctx->{cgi}); + my $base = $ibx->base_url($ctx->{env}); my $mid = mid_clean($header_obj->header('Message-ID')); - $mid = uri_escape_utf8($mid); + $mid = mid_escape($mid); my @append = ( 'Archived-At', "<$base$mid/>", 'List-Archive', "<$base>", @@ -110,39 +112,38 @@ use warnings; sub new { my ($class, $ctx, $cb) = @_; - my $buf; + my $buf = ''; bless { buf => \$buf, gz => IO::Compress::Gzip->new(\$buf, Time => 0), cb => $cb, ctx => $ctx, msgs => [], - opts => { asc => 1, offset => 0 }, + opts => { offset => 0 }, }, $class; } -sub _flush_buf { - my ($self) = @_; - my $ret = $self->{buf}; - $ret = $$ret; - ${$self->{buf}} = undef; - $ret; -} - # called by Plack::Util::foreach or similar sub getline { my ($self) = @_; + my $ctx = $self->{ctx} or return; my $res; - my $ctx = $self->{ctx}; my $ibx = $ctx->{-inbox}; my $gz = $self->{gz}; do { while (defined(my $smsg = shift @{$self->{msgs}})) { - my $msg = eval { $ibx->msg_by_mid($smsg->mid) } or next; + my $msg = eval { $ibx->msg_by_smsg($smsg) } or next; $msg = Email::Simple->new($msg); $gz->write(PublicInbox::Mbox::msg_str($ctx, $msg)); - my $ret = _flush_buf($self); - return $ret if $ret; + my $bref = $self->{buf}; + if (length($$bref) >= 8192) { + my $ret = $$bref; # copy :< + ${$self->{buf}} = ''; + return $ret; + } + + # be fair to other clients on public-inbox-httpd: + return ''; } $res = $self->{cb}->($self->{opts}); $self->{msgs} = $res->{msgs}; @@ -150,7 +151,8 @@ sub getline { $self->{opts}->{offset} += $res; } while ($res); $gz->close; - _flush_buf($self); + delete $self->{ctx}; + ${delete $self->{buf}}; } sub close {} # noop