{obuf} will eventually go away and we'll write directly to
{zbuf}, but as an intermediate step we'll make some changes
to rely less on return values.
While we're in the area, reuse Linkify objects in more places
where possible to save some allocations.
: $ctx->gone('over');
$ctx->{mhref} = ($ctx->{nr} || $ctx->{smsg}) ?
"../${\mid_href($smsg->{mid})}/" : '';
: $ctx->gone('over');
$ctx->{mhref} = ($ctx->{nr} || $ctx->{smsg}) ?
"../${\mid_href($smsg->{mid})}/" : '';
- my $obuf = $ctx->{obuf} = _msg_page_prepare_obuf($eml, $ctx);
+ my $obuf = _msg_page_prepare_obuf($eml, $ctx);
if (length($$obuf)) {
multipart_text_as_html($eml, $ctx);
$$obuf .= '</pre><hr>';
if (length($$obuf)) {
multipart_text_as_html($eml, $ctx);
$$obuf .= '</pre><hr>';
my $eml = PublicInbox::Eml->new($bref);
$ctx->{mhref} = '';
PublicInbox::WwwStream::init($ctx);
my $eml = PublicInbox::Eml->new($bref);
$ctx->{mhref} = '';
PublicInbox::WwwStream::init($ctx);
- my $obuf = $ctx->{obuf} = _msg_page_prepare_obuf($eml, $ctx);
+ my $obuf = _msg_page_prepare_obuf($eml, $ctx);
if (length($$obuf)) {
multipart_text_as_html($eml, $ctx);
$$obuf .= '</pre><hr>';
if (length($$obuf)) {
multipart_text_as_html($eml, $ctx);
$$obuf .= '</pre><hr>';
sub _msg_page_prepare_obuf {
my ($eml, $ctx) = @_;
sub _msg_page_prepare_obuf {
my ($eml, $ctx) = @_;
- my $over = $ctx->{ibx}->over;
+ my $have_over = !!$ctx->{ibx}->over;
my $obfs_ibx = $ctx->{-obfs_ibx};
my $obfs_ibx = $ctx->{-obfs_ibx};
+ $ctx->{obuf} = \(my $rv = '');
my $mids = mids_for_index($eml);
my $nr = $ctx->{nr}++;
if ($nr) { # unlikely
my $mids = mids_for_index($eml);
my $nr = $ctx->{nr}++;
if ($nr) { # unlikely
-"<pre>WARNING: multiple messages have this Message-ID\n</pre>";
- $rv .= '<pre>';
+"<pre>WARNING: multiple messages have this Message-ID\n</pre><pre>";
} else {
$ctx->{first_hdr} = $eml->header_obj;
$ctx->{chash} = content_hash($eml) if $ctx->{smsg}; # reused MID
$rv .= "<pre\nid=b>"; # anchor for body start
}
} else {
$ctx->{first_hdr} = $eml->header_obj;
$ctx->{chash} = content_hash($eml) if $ctx->{smsg}; # reused MID
$rv .= "<pre\nid=b>"; # anchor for body start
}
- $ctx->{-upfx} = '../' if $over;
+ $ctx->{-upfx} = '../' if $have_over;
my @title; # (Subject[0], From[0])
for my $v ($eml->header('From')) {
my @n = PublicInbox::Address::names($v);
my @title; # (Subject[0], From[0])
for my $v ($eml->header('From')) {
my @n = PublicInbox::Address::names($v);
my $v = ascii_html(shift @subj);
obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
$rv .= 'Subject: ';
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";
+ $rv .= $have_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);
$title[0] = $v;
for $v (@subj) { # multi-Subject message :<
$v = ascii_html($v);
$rv .= "Subject: $v\n";
}
} else { # dummy anchor for thread skeleton at bottom of page
$rv .= "Subject: $v\n";
}
} else { # dummy anchor for thread skeleton at bottom of page
- $rv .= qq(<a\nhref="#r"\nid=t></a>) if $over;
+ $rv .= qq(<a\nhref="#r"\nid=t></a>) if $have_over;
$title[0] = '(no subject)';
}
for my $v ($eml->header('Date')) {
$title[0] = '(no subject)';
}
for my $v ($eml->header('Date')) {
$ctx->{-title_html} = join(' - ', @title);
$rv = $ctx->html_top . $rv;
}
$ctx->{-title_html} = join(' - ', @title);
$rv = $ctx->html_top . $rv;
}
+
+ $ctx->{-linkify} //= PublicInbox::Linkify->new;
if (scalar(@$mids) == 1) { # common case
my $mhtml = ascii_html($mids->[0]);
if (scalar(@$mids) == 1) { # common case
my $mhtml = ascii_html($mids->[0]);
- $rv .= "Message-ID: <$mhtml> ";
- $rv .= "(<a\nhref=\"raw\">raw</a>)\n";
+ $rv .= qq[Message-ID: <$mhtml> (<a href="raw">raw</a>)\n];
} else {
# X-Alt-Message-ID can happen if a message is injected from
# public-inbox-nntpd because of multiple Message-ID headers.
} else {
# X-Alt-Message-ID can happen if a message is injected from
# public-inbox-nntpd because of multiple Message-ID headers.
- my $lnk = PublicInbox::Linkify->new;
my $s = '';
for my $h (qw(Message-ID X-Alt-Message-ID)) {
$s .= "$h: $_\n" for ($eml->header_raw($h));
}
my $s = '';
for my $h (qw(Message-ID X-Alt-Message-ID)) {
$s .= "$h: $_\n" for ($eml->header_raw($h));
}
- $lnk->linkify_mids('..', \$s, 1);
+ $ctx->{-linkify}->linkify_mids('..', \$s, 1);
- $rv .= _parent_headers($eml, $over);
+ _parent_headers($ctx, $eml);
- my ($hdr, $over) = @_;
- my $rv = '';
my @irt = $hdr->header_raw('In-Reply-To');
my $refs;
if (@irt) {
my @irt = $hdr->header_raw('In-Reply-To');
my $refs;
if (@irt) {
- my $lnk = PublicInbox::Linkify->new;
- $rv .= "In-Reply-To: $_\n" for @irt;
- $lnk->linkify_mids('..', \$rv);
+ my $s = '';
+ $s .= "In-Reply-To: $_\n" for @irt;
+ $ctx->{-linkify}->linkify_mids('..', \$s);
+ ${$ctx->{obuf}} .= $s;
} else {
$refs = references($hdr);
my $irt = pop @$refs;
if (defined $irt) {
my $html = ascii_html($irt);
my $href = mid_href($irt);
} else {
$refs = references($hdr);
my $irt = pop @$refs;
if (defined $irt) {
my $html = ascii_html($irt);
my $href = mid_href($irt);
- $rv .= "In-Reply-To: <";
- $rv .= "<a\nhref=\"../$href/\">$html</a>>\n";
+ ${$ctx->{obuf}} .= <<EOM;
+In-Reply-To: <<a\nhref="../$href/">$html</a>>
+EOM
}
}
# do not display References: if search is present,
# we show the thread skeleton at the bottom, instead.
}
}
# do not display References: if search is present,
# we show the thread skeleton at the bottom, instead.
+ return if $ctx->{ibx}->over;
$refs //= references($hdr);
if (@$refs) {
$refs //= references($hdr);
if (@$refs) {
- @$refs = map { linkify_ref_no_over($_) } @$refs;
- $rv .= 'References: '. join("\n\t", @$refs) . "\n";
+ $_ = linkify_ref_no_over($_) for @$refs;
+ ${$ctx->{obuf}} .= 'References: '. join("\n\t", @$refs) . "\n";
}
# returns a string buffer
}
# returns a string buffer
is(200, $res->code, "success for $path");
my $html = $res->content;
like($html, qr!<title>hihi - Me</title>!, 'HTML returned');
is(200, $res->code, "success for $path");
my $html = $res->content;
like($html, qr!<title>hihi - Me</title>!, 'HTML returned');
- like($html, qr!<a\nhref="raw"!s, 'raw link present');
+ like($html, qr!<a\nhref=raw!s, 'raw link present');
like($html, qr!> quoted text!s, 'quoted text inline');
$path .= 'f/';
like($html, qr!> quoted text!s, 'quoted text inline');
$path .= 'f/';