-# Copyright (C) 2014-2019 all contributors <meta@public-inbox.org>
+# Copyright (C) 2014-2020 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
#
# Used for displaying the HTML web interface.
use warnings;
use bytes (); # only for bytes::length
use PublicInbox::MsgTime qw(msg_datestamp);
-use PublicInbox::Hval qw(ascii_html obfuscate_addrs prurl);
+use PublicInbox::Hval qw(ascii_html obfuscate_addrs prurl mid_href);
use PublicInbox::Linkify;
-use PublicInbox::MID qw/id_compress mid_escape mids mids_for_index references/;
+use PublicInbox::MID qw/id_compress mids mids_for_index references/;
use PublicInbox::MsgIter;
use PublicInbox::Address;
use PublicInbox::WwwStream;
my $more = $ctx->{more};
if ($nr == 1) {
# $more cannot be true w/o $smsg being defined:
- my $upfx = $more ? '../'.mid_escape($ctx->{smsg}->mid).'/' : '';
- multipart_text_as_html(delete $ctx->{mime}, $upfx, $ctx);
+ $ctx->{mhref} = $more ? '../'.mid_href($ctx->{smsg}->{mid}).'/'
+ : '';
+ multipart_text_as_html(delete $ctx->{mime}, $ctx);
${delete $ctx->{obuf}} .= '</pre><hr>';
} elsif ($more) {
++$ctx->{end_nr};
my $next = $ibx->over->next_by_mid($ctx->{mid}, \$id, \$prev);
$ctx->{more} = $next ? [ $id, $prev, $next ] : undef;
return '' unless $smsg;
- my $upfx = '../' . mid_escape($smsg->mid) . '/';
+ $ctx->{mhref} = '../' . mid_href($smsg->{mid}) . '/';
my $mime = delete $smsg->{mime};
_msg_page_prepare_obuf($mime->header_obj, $ctx, $nr);
- multipart_text_as_html($mime, $upfx, $ctx);
+ multipart_text_as_html($mime, $ctx);
${delete $ctx->{obuf}} .= '</pre><hr>';
}
obfuscate_addrs($obfs_ibx, $from) if $obfs_ibx;
$rv .= "From: $from @ ".fmt_ts($ds)." UTC";
my $upfx = $ctx->{-upfx};
- my $mhref = $upfx . mid_escape($mid_raw) . '/';
+ my $mhref = $upfx . mid_href($mid_raw) . '/';
$rv .= qq{ (<a\nhref="$mhref">permalink</a> / };
$rv .= qq{<a\nhref="${mhref}raw">raw</a>)\n};
my $to = fold_addresses(_hdr_names_html($hdr, 'To'));
my $mapping = $ctx->{mapping};
if (!$mapping && (defined($irt) || defined($irt = in_reply_to($hdr)))) {
- my $mirt = PublicInbox::Hval->new_msgid($irt);
- my $href = $upfx . $mirt->{href}. '/';
- my $html = $mirt->as_html;
+ my $href = $upfx . mid_href($irt) . '/';
+ my $html = ascii_html($irt);
$rv .= qq(In-Reply-To: <<a\nhref="$href">$html</a>>\n)
}
$rv .= "\n";
return missing_thread($ctx) unless $smsg;
$ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
- $ctx->{-title_html} = ascii_html($smsg->subject);
+ $ctx->{-title_html} = ascii_html($smsg->{subject});
$ctx->{-html_tip} = thread_index_entry($ctx, $level, $smsg);
$ctx->{-queue} = \@q;
PublicInbox::WwwStream->response($ctx, 200, \&stream_thread_i);
$smsg = $ibx->smsg_mime($m) and last;
}
return missing_thread($ctx) unless $smsg;
- $ctx->{-title_html} = ascii_html($smsg->subject);
+ $ctx->{-title_html} = ascii_html($smsg->{subject});
$ctx->{-html_tip} = '<pre>'.index_entry($smsg, $ctx, scalar @$msgs);
$ctx->{msgs} = $msgs;
PublicInbox::WwwStream->response($ctx, 200, \&thread_html_i);
}
sub multipart_text_as_html {
- my (undef, $mhref, $ctx) = @_; # $mime = $_[0]
- $ctx->{mhref} = $mhref;
+ # ($mime, $ctx) = @_; # msg_iter will do "$_[0] = undef"
# scan through all parts, looking for displayable text
- msg_iter($_[0], \&add_text_body, $ctx, 1);
+ msg_iter($_[0], \&add_text_body, $_[1], 1);
}
sub flush_quote {
$idx[0] = $upfx . $idx[0] if $upfx ne '';
$ctx->{-apfx} = join('/', @idx);
$ctx->{-anchors} = {}; # attr => filename
- $ctx->{-diff} = $diff = [];
+ $diff = 1;
delete $ctx->{-long_path};
my $spfx;
if ($ibx->{-repo_objs}) {
attach_link($ctx, $ct, $p, $fn, $err);
$$rv .= "\n";
}
- my $l = PublicInbox::Linkify->new;
+ my $l = $ctx->{-linkify} //= PublicInbox::Linkify->new;
foreach my $cur (@sections) {
if ($cur =~ /\A>/) {
flush_quote($rv, $l, \$cur);
} elsif ($diff) {
- @$diff = split(/^/m, $cur);
- $cur = undef;
- flush_diff($rv, $ctx, $l);
+ flush_diff($rv, $ctx, \$cur);
} else {
# regular lines, OK
$$rv .= $l->to_html($cur);
}
my @title; # (Subject[0], From[0])
for my $v ($hdr->header('From')) {
- $v = PublicInbox::Hval->new($v);
- my @n = PublicInbox::Address::names($v->raw);
+ my @n = PublicInbox::Address::names($v);
+ $v = ascii_html($v);
$title[1] //= ascii_html(join(', ', @n));
- $v = $v->as_html;
if ($obfs_ibx) {
obfuscate_addrs($obfs_ibx, $v);
obfuscate_addrs($obfs_ibx, $title[1]);
}
my @subj = $hdr->header('Subject');
if (@subj) {
- for my $v (@subj) {
+ my $v = ascii_html(shift @subj);
+ obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
+ $rv .= 'Subject: ';
+ $rv .= $over ? qq(<a\nhref="#r"\nid=t>$v</a>\n) : "$v\n";
+ $title[0] = $v;
+ for $v (@subj) { # multi-Subject message :<
$v = ascii_html($v);
obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
- $rv .= 'Subject: ';
- if ($over) {
- $rv .= qq(<a\nhref="#r"\nid=t>$v</a>\n);
- } else {
- $rv .= "$v\n";
- }
- $title[0] //= $v;
+ $rv .= "Subject: $v\n";
}
} else { # dummy anchor for thread skeleton at bottom of page
$rv .= qq(<a\nhref="#r"\nid=t></a>) if $over;
}
$ctx->{-title_html} = join(' - ', @title);
if (scalar(@$mids) == 1) { # common case
- my $mid = PublicInbox::Hval->new_msgid($mids->[0]);
- my $mhtml = $mid->as_html;
+ my $mhtml = ascii_html($mids->[0]);
$rv .= "Message-ID: <$mhtml> ";
$rv .= "(<a\nhref=\"raw\">raw</a>)\n";
} else {
$refs = references($hdr);
my $irt = pop @$refs;
if (defined $irt) {
- my $v = PublicInbox::Hval->new_msgid($irt);
- my $html = $v->as_html;
- my $href = $v->{href};
+ my $html = ascii_html($irt);
+ my $href = mid_href($irt);
$rv .= "In-Reply-To: <";
$rv .= "<a\nhref=\"../$href/\">$html</a>>\n";
}
$next = $prev = ' ';
if (my $n = $ctx->{next_msg}) {
- $n = PublicInbox::Hval->new_msgid($n)->{href};
+ $n = mid_href($n);
$next = "<a\nhref=\"$upfx$n/\"\nrel=next>next</a>";
}
my $u;
my $par = $ctx->{parent_msg};
if ($par) {
- $u = PublicInbox::Hval->new_msgid($par)->{href};
+ $u = mid_href($par);
$u = "$upfx$u/";
}
if (my $p = $ctx->{prev_msg}) {
- $prev = PublicInbox::Hval->new_msgid($p)->{href};
+ $prev = mid_href($p);
if ($p && $par && $p eq $par) {
$prev = "<a\nhref=\"$upfx$prev/\"\n" .
'rel=prev>prev parent</a>';
}
sub linkify_ref_no_over {
- my $v = PublicInbox::Hval->new_msgid($_[0]);
- my $html = $v->as_html;
- my $href = $v->{href};
+ my ($mid) = @_;
+ my $href = mid_href($mid);
+ my $html = ascii_html($mid);
"<<a\nhref=\"../$href/\">$html</a>>";
}
sub ghost_parent {
my ($upfx, $mid) = @_;
- $mid = PublicInbox::Hval->new_msgid($mid);
- my $href = $mid->{href};
- my $html = $mid->as_html;
+ my $href = mid_href($mid);
+ my $html = ascii_html($mid);
qq{[parent not found: <<a\nhref="$upfx$href/">$html</a>>]};
}
$$skel .= delete($ctx->{sl_note}) || '';
}
- my $f = ascii_html($smsg->from_name);
+ my $f = ascii_html($smsg->{from_name});
my $obfs_ibx = $ctx->{-obfs_ibx};
obfuscate_addrs($obfs_ibx, $f) if $obfs_ibx;
# Subject is never undef, this mail was loaded from
# our Xapian which would've resulted in '' if it were
# really missing (and Filter rejects empty subjects)
- my @subj = split(/ /, subject_normalized($smsg->subject));
+ my @subj = split(/ /, subject_normalized($smsg->{subject}));
# remove common suffixes from the subject if it matches the previous,
# so we do not show redundant text at the end.
my $prev_subj = $ctx->{prev_subj} || [];
$map->[0] = "$d<a\nhref=\"$m\">$end";
$id = "\nid=r".$id;
} else {
- $m = $ctx->{-upfx}.mid_escape($mid).'/';
+ $m = $ctx->{-upfx}.mid_href($mid).'/';
}
$$skel .= $d . "<a\nhref=\"$m\"$id>" . $end;
1;
$d .= ' ' if exists $ctx->{searchview};
$d .= indent_for($level) . th_pfx($level);
my $upfx = $ctx->{-upfx};
- my $m = PublicInbox::Hval->new_msgid($mid);
- my $href = $upfx . $m->{href} . '/';
- my $html = $m->as_html;
+ my $href = $upfx . mid_href($mid) . '/';
+ my $html = ascii_html($mid);
my $mapping = $ctx->{mapping};
my $map = $mapping->{$mid} if $mapping;
sub sort_ds {
[ sort {
- (eval { $a->topmost->{smsg}->ds } || 0) <=>
- (eval { $b->topmost->{smsg}->ds } || 0)
+ (eval { $a->topmost->{smsg}->{ds} } || 0) <=>
+ (eval { $b->topmost->{smsg}->{ds} } || 0)
} @{$_[0]} ];
}
sub acc_topic { # walk_thread callback
my ($ctx, $level, $node) = @_;
my $mid = $node->{id};
- my $x = $node->{smsg} || $ctx->{-inbox}->smsg_by_mid($mid);
- my ($subj, $ds);
- my $topic;
- if ($x) {
- $subj = $x->subject;
- $subj = subject_normalized($subj);
+ my $smsg = $node->{smsg} // $ctx->{-inbox}->smsg_by_mid($mid);
+ if ($smsg) {
+ my $subj = subject_normalized($smsg->{subject});
$subj = '(no subject)' if $subj eq '';
- $ds = $x->ds;
- if ($level == 0) {
- $topic = [ $ds, 1, { $subj => $mid }, $subj ];
+ my $ds = $smsg->{ds};
+ if ($level == 0) { # new, top-level topic
+ my $topic = [ $ds, 1, { $subj => $mid }, $subj ];
$ctx->{-cur_topic} = $topic;
push @{$ctx->{order}}, $topic;
return 1;
}
- $topic = $ctx->{-cur_topic}; # should never be undef
+ # continue existing topic
+ my $topic = $ctx->{-cur_topic}; # should never be undef
$topic->[0] = $ds if $ds > $topic->[0];
- $topic->[1]++;
+ $topic->[1]++; # bump N+ message counter
my $seen = $topic->[2];
if (scalar(@$topic) == 3) { # parent was a ghost
push @$topic, $subj;
- } elsif (!$seen->{$subj}) {
- push @$topic, $level, $subj;
+ } elsif (!defined($seen->{$subj})) {
+ push @$topic, $level, $subj; # @extra messages
}
$seen->{$subj} = $mid; # latest for subject
} else { # ghost message
return 1 if $level != 0; # ignore child ghosts
- $topic = [ -666, 0, {} ];
- $ctx->{-cur_topic} = $topic;
+ my $topic = $ctx->{-cur_topic} = [ -666, 0, {} ];
push @{$ctx->{order}}, $topic;
}
1;
# sort by recency, this allows new posts to "bump" old topics...
foreach my $topic (sort { $b->[0] <=> $a->[0] } @$order) {
- my ($ds, $n, $seen, $top, @ex) = @$topic;
+ my ($ds, $n, $seen, $top_subj, @extra) = @$topic;
@$topic = ();
- next unless defined $top; # ghost topic
- my $mid = delete $seen->{$top};
- my $href = mid_escape($mid);
- my $prev_subj = [ split(/ /, $top) ];
- $top = PublicInbox::Hval->new($top)->as_html;
+ next unless defined $top_subj; # ghost topic
+ my $mid = delete $seen->{$top_subj};
+ my $href = mid_href($mid);
+ my $prev_subj = [ split(/ /, $top_subj) ];
+ $top_subj = ascii_html($top_subj);
$ds = fmt_ts($ds);
# $n isn't the total number of posts on the topic,
my $mbox = qq(<a\nhref="$href/t.mbox.gz">mbox.gz</a>);
my $atom = qq(<a\nhref="$href/t.atom">Atom</a>);
- my $s = "<a\nhref=\"$href/T/$anchor\">$top</a>\n" .
+ my $s = "<a\nhref=\"$href/T/$anchor\">$top_subj</a>\n" .
" $ds UTC $n - $mbox / $atom\n";
- for (my $i = 0; $i < scalar(@ex); $i += 2) {
- my $level = $ex[$i];
- my $subj = $ex[$i + 1];
+ for (my $i = 0; $i < scalar(@extra); $i += 2) {
+ my $level = $extra[$i];
+ my $subj = $extra[$i + 1]; # already normalized
$mid = delete $seen->{$subj};
- my @subj = split(/ /, subject_normalized($subj));
+ my @subj = split(/ /, $subj);
my @next_prev = @subj; # full copy
my $omit = dedupe_subject($prev_subj, \@subj, ' "');
$prev_subj = \@next_prev;
- $subj = ascii_html(join(' ', @subj));
+ $subj = ascii_html($subj);
obfuscate_addrs($obfs_ibx, $subj) if $obfs_ibx;
- $href = mid_escape($mid);
+ $href = mid_href($mid);
$s .= indent_for($level) . TCHILD;
- $s .= "<a\nhref=\"$href/T/#u\">$subj</a>$omit\n";
+ $s .= qq(<a\nhref="$href/T/#u">$subj</a>$omit\n);
}
push @out, $s;
}