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;
5 require_mods(qw(lei -httpd));
7 my ($ro_home, $cfg_path) = setup_public_inboxes;
8 my ($tmpdir, $for_destroy) = tmpdir;
10 my $cmd = [ '-httpd', '-W0', "--stdout=$tmpdir/1", "--stderr=$tmpdir/2" ];
11 my $env = { PI_CONFIG => $cfg_path };
12 my $td = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT("-httpd $?");
13 my $host_port = tcp_host_port($sock);
15 test_lei({ tmpdir => $tmpdir }, sub {
16 my $url = "http://$host_port/t2";
17 for my $p (qw(bogus@x/t.mbox.gz bogus@x/raw ?q=noresultever)) {
18 ok(!lei('import', "$url/$p"), "/$p fails properly");
19 like($lei_err, qr/curl.*404/, 'got curl 404');
21 for my $p (qw(/ /T/ /t/ /t.atom)) {
22 ok(!lei('import', "$url/m\@example$p"), "/$p fails");
23 like($lei_err, qr/did you mean/, "gave hint for $p");
25 lei_ok 'import', "$url/testmessage\@example.com/raw";
26 lei_ok 'q', 'm:testmessage@example.com';
27 my $res = json_utf8->decode($lei_out);
28 is($res->[0]->{'m'}, 'testmessage@example.com', 'imported raw')
29 or diag explain($res);
31 lei_ok 'import', "$url/qp\@example.com/t.mbox.gz";
32 lei_ok 'q', 'm:qp@example.com';
33 $res = json_utf8->decode($lei_out);
34 is($res->[0]->{'m'}, 'qp@example.com', 'imported t.mbox.gz')
35 or diag explain($res);
37 lei_ok 'import', "$url/?q=s:boolean";
38 lei_ok 'q', 'm:20180720072141.GA15957@example';
39 $res = json_utf8->decode($lei_out);
40 is($res->[0]->{'m'}, '20180720072141.GA15957@example',
41 'imported search result') or diag explain($res);
43 ok(!lei(qw(import --mail-sync), "$url/x\@example.com/raw"),
44 '--mail-sync fails on HTTP');
45 like($lei_err, qr/--mail-sync/, 'error message notes --mail-sync');