2 # Copyright (C) 2020-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 ok(!lei(qw(import -F bogus), 't/plack-qp.eml'), 'fails with bogus format');
7 like($lei_err, qr/\bbogus unrecognized/, 'gave error message');
9 lei_ok(qw(q s:boolean), \'search miss before import');
10 unlike($lei_out, qr/boolean/i, 'no results, yet');
11 open my $fh, '<', 't/data/0001.patch' or BAIL_OUT $!;
12 lei_ok([qw(import -F eml -)], undef, { %$lei_opt, 0 => $fh },
13 \'import single file from stdin') or diag $lei_err;
15 lei_ok(qw(q s:boolean), \'search hit after import');
16 lei_ok(qw(q s:boolean -f mboxrd), \'blob accessible after import');
18 my $expect = [ eml_load('t/data/0001.patch') ];
19 require PublicInbox::MboxReader;
21 open my $fh, '<', \$lei_out or BAIL_OUT "open :scalar: $!";
22 PublicInbox::MboxReader->mboxrd($fh, sub {
24 $eml->header_set('Status');
27 is_deeply(\@cmp, $expect, 'got expected message in mboxrd');
29 lei_ok(qw(import -F eml), 't/data/message_embed.eml',
30 \'import single file by path');
37 my $opt = { %$lei_opt, 0 => \$str };
38 lei_ok([qw(import -F eml -)], undef, $opt,
39 \'import single file with keywords from stdin');
41 my $res = json_utf8->decode($lei_out);
42 is($res->[1], undef, 'only one result');
43 is_deeply($res->[0]->{kw}, ['seen'], "message `seen' keyword set");
45 $str =~ tr/x/v/; # v@y
46 lei_ok([qw(import --no-kw -F eml -)], undef, $opt,
47 \'import single file with --no-kw from stdin');
49 $res = json_utf8->decode($lei_out);
50 is($res->[1], undef, 'only one result');
51 is_deeply($res->[0]->{kw}, [], 'no keywords set');
53 # see t/lei_to_mail.t for "import -F mbox*"