if ($nr == 1) {
# $more cannot be true w/o $smsg being defined:
my $upfx = $more ? '../'.mid_escape($smsg->mid).'/' : '';
- $tip . multipart_text_as_html($mime, $upfx, $ibx) .
+ $tip . multipart_text_as_html($mime, $upfx, $ctx) .
'</pre><hr>'
} elsif ($more && @$more) {
++$end;
my $mime = $smsg->{mime};
my $upfx = '../' . mid_escape($smsg->mid) . '/';
_msg_html_prepare($mime->header_obj, $ctx, $more, $nr) .
- multipart_text_as_html($mime, $upfx, $ibx) .
+ multipart_text_as_html($mime, $upfx, $ctx) .
'</pre><hr>'
} else {
'';
# scan through all parts, looking for displayable text
my $ibx = $ctx->{-inbox};
- msg_iter($mime, sub { $rv .= add_text_body($mhref, $ibx, $_[0]) });
+ msg_iter($mime, sub { $rv .= add_text_body($mhref, $ctx, $_[0]) });
# add the footer
$rv .= "\n<a\nhref=#$id_m\nid=e$id>^</a> ".
}
sub multipart_text_as_html {
- my ($mime, $upfx, $ibx) = @_;
+ my ($mime, $upfx, $ctx) = @_;
my $rv = "";
# scan through all parts, looking for displayable text
- msg_iter($mime, sub { $rv .= add_text_body($upfx, $ibx, $_[0]) });
+ msg_iter($mime, sub { $rv .= add_text_body($upfx, $ctx, $_[0]) });
$rv;
}
}
sub add_text_body {
- my ($upfx, $ibx, $p) = @_;
+ my ($upfx, $ctx, $p) = @_;
+ my $ibx = $ctx->{-inbox};
my $obfs_ibx = $ibx->{obfuscate} ? $ibx : undef;
# $p - from msg_iter: [ Email::MIME, depth, @idx ]
- my ($part, $depth) = @$p; # attachment @idx is unused
+ my ($part, $depth, @idx) = @$p;
my $ct = $part->content_type || 'text/plain';
my $fn = $part->filename;
my ($s, $err) = msg_part_text($part, $ct);
# link generation in diffs with the extra '%0D'
$s =~ s/\r\n/\n/sg;
- my ($diff, $spfx);
+ # always support diff-highlighting, but we can't linkify hunk
+ # headers for solver unless some coderepo are configured:
+ my $diff;
if ($s =~ /^(?:diff|---|\+{3}) /ms) {
- $diff = [];
+ # diffstat anchors do not link across attachments or messages:
+ $idx[0] = $upfx . $idx[0] if $upfx ne '';
+ $ctx->{-apfx} = join('/', @idx);
+ $ctx->{-anchors} = {}; # attr => filename
+ $ctx->{-diff} = $diff = [];
+ my $spfx;
if ($ibx->{-repo_objs}) {
my $n_slash = $upfx =~ tr!/!/!;
if ($n_slash == 0) {
$spfx = '../../';
}
}
+ $ctx->{-spfx} = $spfx;
};
my @lines = split(/^/m, $s);
$s .= $l->linkify_2(ascii_html($cur));
}
} else {
- flush_diff(\$s, $spfx, $l, $diff) if $diff && @$diff;
+ flush_diff(\$s, $ctx, $l) if $diff && @$diff;
push @quot, $cur;
}
}
if (@quot) { # ugh, top posted
flush_quote(\$s, $l, \@quot);
- flush_diff(\$s, $spfx, $l, $diff) if $diff && @$diff;
+ flush_diff(\$s, $ctx, $l) if $diff && @$diff;
obfuscate_addrs($obfs_ibx, $s) if $obfs_ibx;
$s;
} else {
- flush_diff(\$s, $spfx, $l, $diff) if $diff && @$diff;
+ 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;
}
sub anchor0 ($$$$$) {
- my ($dst, $anchors, $linkify, $fn, $rest) = @_;
- if (my $attr = to_attr($fn)) {
- $anchors->{$attr} = 1;
- $$dst .= " <a\nhref=#$attr>" .
+ my ($dst, $ctx, $linkify, $fn, $rest) = @_;
+ if (my $attr = to_attr($ctx->{-apfx}.$fn)) {
+ $ctx->{-anchors}->{$attr} = 1;
+ $$dst .= " <a\nid=i$attr\nhref=#$attr>" .
ascii_html($fn) . '</a>'.
to_html($linkify, $rest);
return 1;
}
sub anchor1 ($$$$$) {
- my ($dst, $anchors, $linkify, $pb, $s) = @_;
- my $attr = to_attr($pb) or return;
+ my ($dst, $ctx, $linkify, $pb, $s) = @_;
+ my $attr = to_attr($ctx->{-apfx}.$pb) or return;
my $line = to_html($linkify, $s);
- if (delete $anchors->{$attr} && $line =~ s/^diff //) {
- $$dst .= "<a\nhref=#ds\nid=$attr>diff</a> ".$line;
+ if (delete $ctx->{-anchors}->{$attr} && $line =~ s/^diff //) {
+ $$dst .= "<a\nhref=#i$attr\nid=$attr>diff</a> ".$line;
return 1;
}
undef
}
-sub flush_diff ($$$$) {
- my ($dst, $spfx, $linkify, $diff) = @_;
+sub flush_diff ($$$) {
+ my ($dst, $ctx, $linkify) = @_;
+ my $diff = $ctx->{-diff};
+ my $spfx = $ctx->{-spfx};
my $state = DSTATE_INIT;
my $dctx = { Q => '' }; # {}, keys: oid_a, oid_b, path_a, path_b
- my $anchors = {}; # attr => filename
foreach my $s (@$diff) {
if ($s =~ /^---$/) {
to_state($dst, $state, DSTATE_STAT);
- $$dst .= "<span\nid=ds>" . $s . '</span>';
+ $$dst .= $s;
} elsif ($s =~ /^ /) {
# works for common cases, but not weird/long filenames
if ($state == DSTATE_STAT &&
$s =~ /^ (\S+)(\s+\|.*\z)/s) {
- anchor0($dst, $anchors, $linkify, $1, $2)
- and next;
+ anchor0($dst, $ctx, $linkify, $1, $2) and next;
} elsif ($state2class[$state]) {
to_state($dst, $state, DSTATE_CTX);
}
$dctx->{Q} .=
"&a=".uri_escape_utf8($pa, UNSAFE);
}
- anchor1($dst, $anchors, $linkify, $pb, $s)
- and next;
+ anchor1($dst, $ctx, $linkify, $pb, $s) and next;
}
$$dst .= to_html($linkify, $s);
} elsif ($s =~ s/^(index $OID_NULL\.\.)($OID_BLOB)\b//o) {