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(lei -nntpd));
7 my ($ro_home, $cfg_path) = setup_public_inboxes;
8 my ($tmpdir, $for_destroy) = tmpdir;
9 my $env = { PI_CONFIG => $cfg_path };
11 my $sock = tcp_server;
12 my $cmd = [ '-nntpd', '-W0', "--stdout=$tmpdir/n1", "--stderr=$tmpdir/n2" ];
13 my $nntpd = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT("-nntpd $?");
14 my $nntp_host_port = tcp_host_port($sock);
17 $cmd = [ '-imapd', '-W0', "--stdout=$tmpdir/i1", "--stderr=$tmpdir/i2" ];
18 my $imapd = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT("-imapd $?");
19 my $imap_host_port = tcp_host_port($sock);
21 for ('', qw(cur new)) {
22 mkdir "$tmpdir/md/$_" or xbail "mkdir: $!";
24 symlink(File::Spec->rel2abs('t/plack-qp.eml'), "$tmpdir/md/cur/x:2,");
26 open my $fh, '<', 't/plack-qp.eml' or xbail $!;
31 # mbsync and offlineimap both put ":2," in "new/" files:
32 symlink(File::Spec->rel2abs('t/utf8.eml'), "$tmpdir/md/new/u:2,") or
35 test_lei({ tmpdir => $tmpdir }, sub {
36 my $store_path = "$ENV{HOME}/.local/share/lei/store/";
38 lei_ok('index', "$tmpdir/md");
39 lei_ok(qw(q mid:qp@example.com));
40 my $res_a = json_utf8->decode($lei_out);
41 my $blob = $res_a->[0]->{'blob'};
42 like($blob, qr/\A[0-9a-f]{40,}\z/, 'got blob from qp@example');
43 lei_ok(qw(-C / blob), $blob);
44 is($lei_out, $expect, 'got expected blob via Maildir');
45 lei_ok(qw(q mid:qp@example.com -f text));
46 like($lei_out, qr/^hi = bye/sm, 'lei2mail fallback');
48 lei_ok(qw(q mid:testmessage@example.com -f text));
49 lei_ok(qw(-C / blob --mail 9bf1002c49eb075df47247b74d69bcd555e23422));
51 my $all_obj = ['git', "--git-dir=$store_path/ALL.git",
52 qw(cat-file --batch-check --batch-all-objects)];
53 is_deeply([xqx($all_obj)], [], 'no git objects');
54 lei_ok('import', 't/plack-qp.eml');
55 ok(grep(/\A$blob blob /, my @objs = xqx($all_obj)),
57 lei_ok(qw(q m:qp@example.com --dedupe=none));
58 my $res_b = json_utf8->decode($lei_out);
59 is_deeply($res_b, $res_a, 'no extra DB entries');
61 # ensure tag works on index-only messages:
62 lei_ok(qw(tag +kw:seen t/utf8.eml));
63 lei_ok(qw(q mid:testmessage@example.com));
64 is_deeply(json_utf8->decode($lei_out)->[0]->{kw},
65 ['seen'], 'seen kw can be set on index-only message');
67 lei_ok(qw(q z:0.. -o), "$tmpdir/all-results") for (1..2);
68 is_deeply([xqx($all_obj)], \@objs,
69 'no new objects after 2x q to trigger implicit import');
71 lei_ok('index', "nntp://$nntp_host_port/t.v2");
72 lei_ok('index', "imap://$imap_host_port/t.v2.0");
73 is_deeply([xqx($all_obj)], \@objs, 'no new objects from NNTP+IMAP');