1 # Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use_ok('PublicInbox::SearchThread');
11 $Mail::Thread::nosubject = 1;
12 $Mail::Thread::noprune = 1;
21 $msg->{references} =~ s/\s+/ /sg if $msg->{references};
22 my $simple = Email::Simple->create(header => [
23 'Message-ID' => "<$msg->{mid}>",
24 'References' => $msg->{references},
26 push @simples, $simple;
27 bless $msg, 'PublicInbox::SearchMsg'
32 my ($simples, $smsgs) = make_objs(
33 # data from t/testbox-6 in Mail::Thread 2.55:
34 { mid => '20021124145312.GA1759@nlin.net' },
35 { mid => 'slrnau448m.7l4.markj+0111@cloaked.freeserve.co.uk',
36 references => '<20021124145312.GA1759@nlin.net>',
38 { mid => '15842.10677.577458.656565@jupiter.akutech-local.de',
39 references => '<20021124145312.GA1759@nlin.net>
40 <slrnau448m.7l4.markj+0111@cloaked.freeserve.co.uk>',
42 { mid => '20021125171807.GK8236@somanetworks.com',
43 references => '<20021124145312.GA1759@nlin.net>
44 <slrnau448m.7l4.markj+0111@cloaked.freeserve.co.uk>
45 <15842.10677.577458.656565@jupiter.akutech-local.de>',
47 { mid => '15843.12163.554914.469248@jupiter.akutech-local.de',
48 references => '<20021124145312.GA1759@nlin.net>
49 <slrnau448m.7l4.markj+0111@cloaked.freeserve.co.uk>
50 <15842.10677.577458.656565@jupiter.akutech-local.de>
51 <E18GPHf-0000zp-00@cloaked.freeserve.co.uk>',
53 { mid => 'E18GPHf-0000zp-00@cloaked.freeserve.co.uk',
54 references => '<20021124145312.GA1759@nlin.net>
55 <slrnau448m.7l4.markj+0111@cloaked.freeserve.co.uk>
56 <15842.10677.577458.656565@jupiter.akutech-local.de>'
60 my $st = thread_to_s($smsgs);
63 skip 'Mail::Thread missing', 1 unless $mt;
64 check_mt($st, $simples, 'Mail::Thread output matches');
68 { mid => 1, references => '<2> <3> <4>' },
69 { mid => 4, references => '<2> <3>' },
70 { mid => 5, references => '<6> <7> <8> <3> <2>' },
71 { mid => 9, references => '<6> <3>' },
72 { mid => 10, references => '<8> <7> <6>' },
73 { mid => 2, references => '<6> <7> <8> <3>' },
74 { mid => 3, references => '<6> <7> <8>' },
75 { mid => 6, references => '<8> <7>' },
76 { mid => 7, references => '<8>' },
77 { mid => 8, references => '' }
80 ($simples, $smsgs) = make_objs(@backwards);
81 my $backward = thread_to_s($smsgs);
83 skip 'Mail::Thread missing', 1 unless $mt;
84 check_mt($backward, $simples, 'matches Mail::Thread backwards');
86 ($simples, $smsgs) = make_objs(reverse @backwards);
87 my $forward = thread_to_s($smsgs);
88 unless ('Mail::Thread sorts by Date') {
90 skip 'Mail::Thread missing', 1 unless $mt;
91 check_mt($forward, $simples, 'matches Mail::Thread forwards');
94 if ('sorting by Date') {
95 is("\n".$backward, "\n".$forward, 'forward and backward matches');
102 my $rootset = PublicInbox::SearchThread::thread($msgs, sub {
103 [ sort { $a->{id} cmp $b->{id} } @{$_[0]} ] });
105 my @q = map { (0, $_) } @$rootset;
107 my $level = shift @q;
108 my $node = shift @q or next;
109 $st .= (" "x$level). "$node->{id}\n";
111 unshift @q, map { ($cl, $_) } @{$node->{children}};
117 my ($st, $simples, $msg) = @_;
118 my $mt = Mail::Thread->new(@$simples);
120 $mt->order(sub { sort { $a->messageid cmp $b->messageid } @_ });
122 my @q = map { (0, $_) } $mt->rootset;
124 my $level = shift @q;
125 my $node = shift @q or next;
126 $check .= (" "x$level) . $node->messageid . "\n";
127 unshift @q, $level + 1, $node->child, $level, $node->next;
129 is("\n".$check, "\n".$st, $msg);