package PublicInbox::View;
use strict;
use warnings;
+use bytes (); # only for bytes::length
use PublicInbox::MsgTime qw(msg_datestamp);
use PublicInbox::Hval qw/ascii_html obfuscate_addrs/;
use PublicInbox::Linkify;
sub stream_thread ($$) {
my ($rootset, $ctx) = @_;
- my $inbox = $ctx->{-inbox};
+ my $ibx = $ctx->{-inbox};
my @q = map { (0, $_) } @$rootset;
my $level;
my $smsg;
my $node = shift @q or next;
my $cl = $level + 1;
unshift @q, map { ($cl, $_) } @{$node->{children}};
- $smsg = $inbox->smsg_mime($node->{smsg}) and last;
+ $smsg = $ibx->smsg_mime($node->{smsg}) and last;
}
return missing_thread($ctx) unless $smsg;
- $ctx->{-obfs_ibx} = $inbox->{obfuscate} ? $inbox : undef;
+ $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
$ctx->{-title_html} = ascii_html($smsg->subject);
$ctx->{-html_tip} = thread_index_entry($ctx, $level, $smsg);
$smsg = undef;
my $node = shift @q or next;
my $cl = $level + 1;
unshift @q, map { ($cl, $_) } @{$node->{children}};
- if ($smsg = $inbox->smsg_mime($node->{smsg})) {
+ if ($smsg = $ibx->smsg_mime($node->{smsg})) {
return thread_index_entry($ctx, $level, $smsg);
} else {
return ghost_index_entry($ctx, $level, $node);
my $rootset = thread_results($ctx, $msgs);
# reduce hash lookups in pre_thread->skel_dump
- my $inbox = $ctx->{-inbox};
- $ctx->{-obfs_ibx} = $inbox->{obfuscate} ? $inbox : undef;
+ my $ibx = $ctx->{-inbox};
+ $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
walk_thread($rootset, $ctx, *pre_thread);
$skel .= '</pre>';
# flat display: lazy load the full message from smsg
my $smsg;
while (my $m = shift @$msgs) {
- $smsg = $inbox->smsg_mime($m) and last;
+ $smsg = $ibx->smsg_mime($m) and last;
}
return missing_thread($ctx) unless $smsg;
$ctx->{-title_html} = ascii_html($smsg->subject);
return unless $msgs;
$smsg = undef;
while (my $m = shift @$msgs) {
- $smsg = $inbox->smsg_mime($m) and last;
+ $smsg = $ibx->smsg_mime($m) and last;
}
return index_entry($smsg, $ctx, scalar @$msgs) if $smsg;
$msgs = undef;
# show everything in the full version with anchor from
# short version (see above)
- my $rv = $l->linkify_1(join('', @$quot));
- @$quot = ();
+ my $rv = $l->linkify_1($$quot);
# we use a <span> here to allow users to specify their own
# color for quoted text
$rv = $l->linkify_2(ascii_html($rv));
+ $$quot = undef;
$$s .= qq(<span\nclass="q">) . $rv . '</span>'
}
$ctx->{-apfx} = join('/', @idx);
$ctx->{-anchors} = {}; # attr => filename
$ctx->{-diff} = $diff = [];
+ delete $ctx->{-long_path};
my $spfx;
if ($ibx->{-repo_objs}) {
if (index($upfx, '//') >= 0) { # absolute URL (Atom feeds)
$ctx->{-spfx} = $spfx;
};
- my @lines = split(/^/m, $s);
+ # some editors don't put trailing newlines at the end:
+ $s .= "\n" unless $s =~ /\n\z/s;
+
+ # split off quoted and unquoted blocks:
+ my @sections = split(/((?:^>[^\n]*\n)+)/sm, $s);
$s = '';
if (defined($fn) || $depth > 0 || $err) {
# badly-encoded message with $err? tell the world about it!
$s .= attach_link($upfx, $ct, $p, $fn, $err);
$s .= "\n";
}
- my @quot;
my $l = PublicInbox::Linkify->new;
- foreach my $cur (@lines) {
- if ($cur !~ /^>/) {
- # show the previously buffered quote inline
- flush_quote(\$s, $l, \@quot) if @quot;
-
- if ($diff) {
- push @$diff, $cur;
- } else {
- # regular line, OK
- $l->linkify_1($cur);
- $s .= $l->linkify_2(ascii_html($cur));
- }
+ foreach my $cur (@sections) {
+ if ($cur =~ /\A>/) {
+ flush_quote(\$s, $l, \$cur);
+ } elsif ($diff) {
+ @$diff = split(/^/m, $cur);
+ $cur = undef;
+ flush_diff(\$s, $ctx, $l);
} else {
- flush_diff(\$s, $ctx, $l) if $diff && @$diff;
- push @quot, $cur;
+ # regular lines, OK
+ $l->linkify_1($cur);
+ $s .= $l->linkify_2(ascii_html($cur));
+ $cur = undef;
}
}
- if (@quot) { # ugh, top posted
- flush_quote(\$s, $l, \@quot);
- flush_diff(\$s, $ctx, $l) if $diff && @$diff;
- obfuscate_addrs($obfs_ibx, $s) if $obfs_ibx;
- $s;
- } else {
- flush_diff(\$s, $ctx, $l) if $diff && @$diff;
- obfuscate_addrs($obfs_ibx, $s) if $obfs_ibx;
- if ($s =~ /\n\z/s) { # common, last line ends with a newline
- $s;
- } else { # some editors don't do newlines...
- $s .= "\n";
- }
- }
+ obfuscate_addrs($obfs_ibx, $s) if $obfs_ibx;
+ $s;
}
sub _msg_html_prepare {