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