From 38c481a5438593cff686709493a70b8a6b3033d1 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 3 Oct 2017 19:43:30 +0000 Subject: search: try to fill in ghosts when generating thread skeleton Since we attempt to fill in threads by Subject, our thread skeletons can cross actual thread IDs, leading to the possibility of false ghosts showing up in the skeleton. Try to fill in the ghosts as well as possible by performing a message lookup. --- lib/PublicInbox/SearchThread.pm | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'lib/PublicInbox/SearchThread.pm') diff --git a/lib/PublicInbox/SearchThread.pm b/lib/PublicInbox/SearchThread.pm index 2966907a..6fbce15c 100644 --- a/lib/PublicInbox/SearchThread.pm +++ b/lib/PublicInbox/SearchThread.pm @@ -22,14 +22,15 @@ use strict; use warnings; sub thread { - my ($messages, $ordersub) = @_; + my ($messages, $ordersub, $srch) = @_; my $id_table = {}; _add_message($id_table, $_) foreach @$messages; my $rootset = [ grep { - !delete($_->{parent}) && $_->visible } values %$id_table ]; + !delete($_->{parent}) && $_->visible($srch) + } values %$id_table ]; $id_table = undef; $rootset = $ordersub->($rootset); - $_->order_children($ordersub) for @$rootset; + $_->order_children($ordersub, $srch) for @$rootset; $rootset; } @@ -129,20 +130,21 @@ sub has_descendent { # Do not show/keep ghosts iff they have no children. Sometimes # a ghost Message-ID is the result of a long header line # being folded/mangled by a MUA, and not a missing message. -sub visible ($) { - my ($self) = @_; - $self->{smsg} || scalar values %{$self->{children}}; +sub visible ($$) { + my ($self, $srch) = @_; + ($self->{smsg} ||= eval { $srch->lookup_mail($self->{id}) }) || + (scalar values %{$self->{children}}); } sub order_children { - my ($cur, $ordersub) = @_; + my ($cur, $ordersub, $srch) = @_; my %seen = ($cur => 1); # self-referential loop prevention my @q = ($cur); while (defined($cur = shift @q)) { my $c = $cur->{children}; # The hashref here... - $c = [ grep { !$seen{$_}++ && visible($_) } values %$c ]; + $c = [ grep { !$seen{$_}++ && visible($_, $srch) } values %$c ]; $c = $ordersub->($c) if scalar @$c > 1; $cur->{children} = $c; # ...becomes an arrayref push @q, @$c; -- cgit v1.2.3-24-ge0c7