]> Sergey Matveev's repositories - public-inbox.git/blob - t/lei-import.t
lei_input: drop "From " line on single "eml" (message/rfc822)
[public-inbox.git] / t / lei-import.t
1 #!perl -w
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;
5 test_lei(sub {
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');
8
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;
14 close $fh;
15 lei_ok(qw(q s:boolean), \'search hit after import');
16 lei_ok(qw(q s:boolean -f mboxrd), \'blob accessible after import');
17 {
18         my $expect = [ eml_load('t/data/0001.patch') ];
19         require PublicInbox::MboxReader;
20         my @cmp;
21         open my $fh, '<', \$lei_out or BAIL_OUT "open :scalar: $!";
22         PublicInbox::MboxReader->mboxrd($fh, sub {
23                 my ($eml) = @_;
24                 $eml->header_set('Status');
25                 push @cmp, $eml;
26         });
27         is_deeply(\@cmp, $expect, 'got expected message in mboxrd');
28 }
29 lei_ok(qw(import -F eml), 't/data/message_embed.eml',
30         \'import single file by path');
31
32 lei_ok(qw(q m:testmessage@example.com));
33 is($lei_out, "[null]\n", 'no results, yet');
34 my $oid = '9bf1002c49eb075df47247b74d69bcd555e23422';
35 my $eml = eml_load('t/utf8.eml');
36 my $in = 'From x@y Fri Oct  2 00:00:00 1993'."\n".$eml->as_string;
37 lei_ok([qw(import -F eml -)], undef, { %$lei_opt, 0 => \$in });
38 lei_ok(qw(q m:testmessage@example.com));
39 is(json_utf8->decode($lei_out)->[0]->{'blob'}, $oid,
40         'got expected OID w/o From');
41
42 my $str = <<'';
43 From: a@b
44 Message-ID: <x@y>
45 Status: RO
46
47 my $opt = { %$lei_opt, 0 => \$str };
48 lei_ok([qw(import -F eml -)], undef, $opt,
49         \'import single file with keywords from stdin');
50 lei_ok(qw(q m:x@y));
51 my $res = json_utf8->decode($lei_out);
52 is($res->[1], undef, 'only one result');
53 is_deeply($res->[0]->{kw}, ['seen'], "message `seen' keyword set");
54
55 $str =~ tr/x/v/; # v@y
56 lei_ok([qw(import --no-kw -F eml -)], undef, $opt,
57         \'import single file with --no-kw from stdin');
58 lei(qw(q m:v@y));
59 $res = json_utf8->decode($lei_out);
60 is($res->[1], undef, 'only one result');
61 is($res->[0]->{kw}, undef, 'no keywords set');
62
63 # see t/lei_to_mail.t for "import -F mbox*"
64 });
65 done_testing;