2 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict; use v5.10.1; use PublicInbox::TestCommon;
6 require_mods(qw(json DBD::SQLite Search::Xapian));
7 use PublicInbox::LeiToMail;
8 my ($ro_home, $cfg_path) = setup_public_inboxes;
10 my $eml = eml_load('t/utf8.eml');
11 my $buf = PublicInbox::LeiToMail::eml2mboxrd($eml, { kw => ['seen'] });
12 lei_ok([qw(import -F mboxrd -)], undef, { 0 => $buf, %$lei_opt });
14 lei_ok qw(q -t m:testmessage@example.com);
15 my $res = json_utf8->decode($lei_out);
16 is_deeply($res->[0]->{kw}, [ 'seen' ], 'q -t sets keywords') or
19 $eml = eml_load('t/utf8.eml');
20 $eml->header_set('References', $eml->header('Message-ID'));
21 $eml->header_set('Message-ID', '<a-reply@miss>');
22 $buf = PublicInbox::LeiToMail::eml2mboxrd($eml, { kw => ['draft'] });
23 lei_ok([qw(import -F mboxrd -)], undef, { 0 => $buf, %$lei_opt });
25 lei_ok([qw(q - -t)], undef,
26 { 0 => \'m:testmessage@example.com', %$lei_opt });
27 $res = json_utf8->decode($lei_out);
28 is(scalar(@$res), 3, 'got 2 results');
30 my %m = map { $_->{'m'} => $_ } @$res;
31 is_deeply($m{'testmessage@example.com'}->{kw}, ['seen'],
32 'flag set in direct hit') or diag explain($res);
33 is_deeply($m{'a-reply@miss'}->{kw}, ['draft'],
34 'flag set in thread hit') or diag explain($res);
36 lei_ok qw(q -t -t m:testmessage@example.com);
37 $res = json_utf8->decode($lei_out);
38 is(scalar(@$res), 3, 'got 2 results with -t -t');
40 %m = map { $_->{'m'} => $_ } @$res;
41 is_deeply($m{'testmessage@example.com'}->{kw}, ['flagged', 'seen'],
42 'flagged set in direct hit') or diag explain($res);
43 is_deeply($m{'a-reply@miss'}->{kw}, ['draft'],
44 'set in thread hit') or diag explain($res);
45 lei_ok qw(q -tt m:testmessage@example.com --only), "$ro_home/t2";
46 $res = json_utf8->decode($lei_out);
47 is_deeply($res->[0]->{kw}, [ qw(flagged seen) ],
48 'flagged set on external with -tt') or diag explain($res);
49 lei_ok qw(q -t m:testmessage@example.com --only), "$ro_home/t2";
50 $res = json_utf8->decode($lei_out);
51 is_deeply($res->[0]->{kw}, [ 'seen' ],
52 'flagged not set on external with 1 -t') or diag explain($res);