about summary refs log tree commit homepage
path: root/t/thread-cycle.t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-10-05 23:47:31 +0000
committerEric Wong <e@80x24.org>2016-10-05 23:53:37 +0000
commitfdd089ee175bf458d2674893e19b4af2edd82b4e (patch)
tree854d5e6b560d752937f529be0ec302739b565756 /t/thread-cycle.t
parent88f66c819dc9e27169fa8f0cf5c9c67111ba668f (diff)
downloadpublic-inbox-fdd089ee175bf458d2674893e19b4af2edd82b4e.tar.gz
Some broken (or malicious) mailers may include a generated
Message-ID in its References header, so be prepared for it.
Diffstat (limited to 't/thread-cycle.t')
-rw-r--r--t/thread-cycle.t39
1 files changed, 25 insertions, 14 deletions
diff --git a/t/thread-cycle.t b/t/thread-cycle.t
index 4d60f7e3..0e1ecfe2 100644
--- a/t/thread-cycle.t
+++ b/t/thread-cycle.t
@@ -51,18 +51,7 @@ my @msgs = map {
         }
 );
 
-my $th = PublicInbox::SearchThread->new(\@msgs);
-$th->thread;
-$th->order(sub { [ sort { $a->{id} cmp $b->{id} } @{$_[0]} ] });
-my $st = '';
-my @q = map { (0, $_) } @{$th->{rootset}};
-while (@q) {
-        my $level = shift @q;
-        my $node = shift @q or next;
-        $st .= (" "x$level). "$node->{id}\n";
-        my $cl = $level + 1;
-        unshift @q, map { ($cl, $_) } @{$node->{children}}
-}
+my $st = thread_to_s(\@msgs);
 
 SKIP: {
         skip 'Mail::Thread missing', 1 unless $mt;
@@ -71,7 +60,7 @@ SKIP: {
         $mt->order(sub { sort { $a->messageid cmp $b->messageid } @_ });
         my $check = '';
 
-        @q = map { (0, $_) } $mt->rootset;
+        my @q = map { (0, $_) } $mt->rootset;
         while (@q) {
                 my $level = shift @q;
                 my $node = shift @q or next;
@@ -81,6 +70,28 @@ SKIP: {
         is($check, $st, 'Mail::Thread output matches');
 }
 
+@msgs = map { bless $_, 'PublicInbox::SearchMsg' } (
+        { mid => 'a@b' },
+        { mid => 'b@c', references => '<a@b> <b@c>' },
+        { mid => 'd@e', references => '<d@e>' },
+);
+
+is(thread_to_s(\@msgs), "a\@b\n b\@c\nd\@e\n", 'ok with self-references');
+
 done_testing();
 
-1;
+sub thread_to_s {
+        my $th = PublicInbox::SearchThread->new(shift);
+        $th->thread;
+        $th->order(sub { [ sort { $a->{id} cmp $b->{id} } @{$_[0]} ] });
+        my $st = '';
+        my @q = map { (0, $_) } @{$th->{rootset}};
+        while (@q) {
+                my $level = shift @q;
+                my $node = shift @q or next;
+                $st .= (" "x$level). "$node->{id}\n";
+                my $cl = $level + 1;
+                unshift @q, map { ($cl, $_) } @{$node->{children}};
+        }
+        $st;
+}