about summary refs log tree commit homepage
path: root/t/lei-q-thread.t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-02-25 10:11:06 +0000
committerEric Wong <e@80x24.org>2021-02-26 02:35:50 +0000
commit232f8e376fe2856c8d34092e33a2c0750734c285 (patch)
tree63ff6bc73aad8c09cfaf15c3782f30d47764c056 /t/lei-q-thread.t
parentd3934150d6fef1ce90ac44298e58474913028d32 (diff)
downloadpublic-inbox-232f8e376fe2856c8d34092e33a2c0750734c285.tar.gz
This can be used to quickly distinguish messages which were
direct hits when doing thread expansion vs messages that
were merely part of the same thread.

This is NOT mairix-derived behavior, but I occasionally found
it useful when looking at results in an MUA to know whether
a message was a direct hit or not.

This makes "-t" consistent with non-"-t" cases as far as keyword
reading goes.
Diffstat (limited to 't/lei-q-thread.t')
-rw-r--r--t/lei-q-thread.t47
1 files changed, 47 insertions, 0 deletions
diff --git a/t/lei-q-thread.t b/t/lei-q-thread.t
new file mode 100644
index 00000000..66db28a9
--- /dev/null
+++ b/t/lei-q-thread.t
@@ -0,0 +1,47 @@
+#!perl -w
+# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict; use v5.10.1; use PublicInbox::TestCommon;
+require_git 2.6;
+require_mods(qw(json DBD::SQLite Search::Xapian));
+use PublicInbox::LeiToMail;
+my ($ro_home, $cfg_path) = setup_public_inboxes;
+test_lei(sub {
+        my $eml = eml_load('t/utf8.eml');
+        my $buf = PublicInbox::LeiToMail::eml2mboxrd($eml, { kw => ['seen'] });
+        lei_ok([qw(import -F mboxrd -)], undef, { 0 => $buf, %$lei_opt });
+
+        lei_ok qw(q -t m:testmessage@example.com);
+        my $res = json_utf8->decode($lei_out);
+        is_deeply($res->[0]->{kw}, [ 'seen' ], 'q -t sets keywords');
+
+        $eml = eml_load('t/utf8.eml');
+        $eml->header_set('References', $eml->header('Message-ID'));
+        $eml->header_set('Message-ID', '<a-reply@miss>');
+        $buf = PublicInbox::LeiToMail::eml2mboxrd($eml, { kw => ['draft'] });
+        lei_ok([qw(import -F mboxrd -)], undef, { 0 => $buf, %$lei_opt });
+
+        lei_ok qw(q -t m:testmessage@example.com);
+        $res = json_utf8->decode($lei_out);
+        is(scalar(@$res), 3, 'got 2 results');
+        pop @$res;
+        my %m = map { $_->{'m'} => $_ } @$res;
+        is_deeply($m{'<testmessage@example.com>'}->{kw}, ['seen'],
+                'flag set in direct hit');
+        'TODO' or is_deeply($m{'<a-reply@miss>'}->{kw}, ['draft'],
+                'flag set in thread hit');
+
+        lei_ok qw(q -t -t m:testmessage@example.com);
+        $res = json_utf8->decode($lei_out);
+        is(scalar(@$res), 3, 'got 2 results with -t -t');
+        pop @$res;
+        %m = map { $_->{'m'} => $_ } @$res;
+        is_deeply($m{'<testmessage@example.com>'}->{kw}, ['flagged', 'seen'],
+                'flagged set in direct hit');
+        'TODO' or is_deeply($m{'<testmessage@example.com>'}->{kw}, ['draft'],
+                'flagged set in direct hit');
+        lei_ok qw(q -t -t m:testmessage@example.com --only), "$ro_home/t2";
+        $res = json_utf8->decode($lei_out);
+        is_deeply($res->[0]->{kw}, [ 'flagged' ], 'flagged set on external');
+});
+done_testing;