]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
view: reduce indentation for skeleton generation
[public-inbox.git] / lib / PublicInbox / View.pm
index 5d5808fad5b2176307e579d5108ad4e7284fd2db..c2e1ae76a400aef4395fc77641c23fe37668e3a1 100644 (file)
@@ -127,13 +127,13 @@ sub index_entry {
        my $id_m = 'm'.$id;
 
        my $root_anchor = $ctx->{root_anchor} || '';
-       my $irt = in_reply_to($hdr);
+       my $irt;
 
        my $rv = "<a\nhref=#e$id\nid=m$id>*</a> ";
        $subj = '<b>'.ascii_html($subj).'</b>';
        $subj = "<u\nid=u>$subj</u>" if $root_anchor eq $id_m;
        $rv .= $subj . "\n";
-       $rv .= _th_index_lite($mid_raw, $irt, $id, $ctx);
+       $rv .= _th_index_lite($mid_raw, \$irt, $id, $ctx);
        my @tocc;
        foreach my $f (qw(To Cc)) {
                my $dst = _hdr_names($hdr, $f);
@@ -147,7 +147,7 @@ sub index_entry {
        $rv .= '  '.join('; +', @tocc) . "\n" if @tocc;
 
        my $mapping = $ctx->{mapping};
-       if (!$mapping && $irt) {
+       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;
@@ -206,7 +206,10 @@ sub _th_index_lite {
        my $nr_c = scalar @$children;
        my $nr_s = 0;
        my $siblings;
-       my $irt_map = $mapping->{$irt} if defined $irt;
+       if (my $smsg = $node->{smsg}) {
+               ($$irt) = (($smsg->{references} || '') =~ m/<([^>]+)>\z/);
+       }
+       my $irt_map = $mapping->{$$irt} if defined $$irt;
        if (defined $irt_map) {
                $siblings = $irt_map->[1]->{children};
                $nr_s = scalar(@$siblings) - 1;
@@ -651,7 +654,6 @@ sub mailto_arg_link {
        push(@arg, map { "--cc=$_" } @cc);
        my $cc = uri_escape_utf8(join(',', @cc));
        my $href = "mailto:$to?In-Reply-To=$irt&Cc=${cc}&Subject=$subj";
-       $href =~ s/%20/+/g;
 
        (\@arg, ascii_html($href));
 }
@@ -765,8 +767,9 @@ sub _msg_date {
 
 sub fmt_ts { POSIX::strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
 
-sub _skel_header {
-       my ($ctx, $smsg, $level) = @_;
+sub skel_dump {
+       my ($ctx, $level, $node) = @_;
+       my $smsg = $node->{smsg} or return _skel_ghost($ctx, $level, $node);
 
        my $dst = $ctx->{dst};
        my $cur = $ctx->{cur};
@@ -822,32 +825,29 @@ sub _skel_header {
        $$dst .=  $d . "<a\nhref=\"$m\"$id>" . $end;
 }
 
-sub skel_dump {
+sub _skel_ghost {
        my ($ctx, $level, $node) = @_;
-       if (my $smsg = $node->{smsg}) {
-               _skel_header($ctx, $smsg, $level);
+
+       my $mid = $node->{id};
+       my $d = $ctx->{pct} ? '    [irrelevant] ' # search result
+                           : '     [not found] ';
+       $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 $mapping = $ctx->{mapping};
+       my $map = $mapping->{$mid} if $mapping;
+       if ($map) {
+               my $id = id_compress($mid, 1);
+               $map->[0] = $d . qq{&lt;<a\nhref=#r$id>$html</a>&gt;\n};
+               $d .= qq{&lt;<a\nhref="$href"\nid=r$id>$html</a>&gt;\n};
        } else {
-               my $mid = $node->{id};
-               my $dst = $ctx->{dst};
-               my $d = $ctx->{pct} ? '    [irrelevant] ' # search result
-                                   : '     [not found] ';
-               $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 $mapping = $ctx->{mapping};
-               my $map = $mapping->{$mid} if $mapping;
-               if ($map) {
-                       my $id = id_compress($mid, 1);
-                       $map->[0] = $d . qq{&lt;<a\nhref=#r$id>$html</a>&gt;\n};
-                       $d .= qq{&lt;<a\nhref="$href"\nid=r$id>$html</a>&gt;\n};
-               } else {
-                       $d .= qq{&lt;<a\nhref="$href">$html</a>&gt;\n};
-               }
-               $$dst .= $d;
+               $d .= qq{&lt;<a\nhref="$href">$html</a>&gt;\n};
        }
+       my $dst = $ctx->{dst};
+       $$dst .= $d;
 }
 
 sub sort_ts {