X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Flei-import-imap.t;h=3a1fff4c32162aecacddf427312e5d0baae96f63;hb=cb0e9d42b799c7489c3b8328cfcae1e1500bc7a0;hp=ee308723069a96a9a0336483285d83cfad31378d;hpb=46eac797d44b068a5e144ecc8269e9dbe878f495;p=public-inbox.git
diff --git a/t/lei-import-imap.t b/t/lei-import-imap.t
index ee308723..3a1fff4c 100644
--- a/t/lei-import-imap.t
+++ b/t/lei-import-imap.t
@@ -2,8 +2,7 @@
# Copyright (C) 2021 all contributors
# License: AGPL-3.0+
use strict; use v5.10.1; use PublicInbox::TestCommon;
-require_git 2.6;
-require_mods(qw(DBD::SQLite Search::Xapian));
+require_mods(qw(lei -imapd Mail::IMAPClient));
my ($ro_home, $cfg_path) = setup_public_inboxes;
my ($tmpdir, $for_destroy) = tmpdir;
my $sock = tcp_server;
@@ -13,16 +12,55 @@ my $td = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT("-imapd: $?");
my $host_port = tcp_host_port($sock);
undef $sock;
test_lei({ tmpdir => $tmpdir }, sub {
- lei_ok(qw(q bytes:1..));
+ my $url = "imap://$host_port/t.v2.0";
+
+ lei_ok(qw(q z:1..));
my $out = json_utf8->decode($lei_out);
is_deeply($out, [ undef ], 'nothing imported, yet');
- lei_ok('import', "imap://$host_port/t.v2.0");
- lei_ok(qw(q bytes:1..));
+
+ lei_ok('inspect', $url);
+ is_deeply(json_utf8->decode($lei_out), {}, 'no inspect stats, yet');
+
+ lei_ok('import', $url);
+ lei_ok 'ls-mail-sync';
+ like($lei_out, qr!\A\Q$url\E;UIDVALIDITY=\d+\n\z!, 'ls-mail-sync');
+ chomp(my $u = $lei_out);
+ lei_ok('import', $u, \'UIDVALIDITY match in URL');
+ $u =~ s/;UIDVALIDITY=(\d+)\s*/;UIDVALIDITY=9$1/s;
+ ok(!lei('import', $u), 'UIDVALIDITY mismatch in URL rejected');
+
+ lei_ok('inspect', $url);
+ my $inspect = json_utf8->decode($lei_out);
+ my @k = keys %$inspect;
+ is(scalar(@k), 1, 'one URL resolved');
+ like($k[0], qr!\A\Q$url\E;UIDVALIDITY=\d+\z!, 'inspect URL matches');
+ my $stats = $inspect->{$k[0]};
+ is_deeply([ sort keys %$stats ],
+ [ qw(uid.count uid.max uid.min) ], 'keys match');
+ ok($stats->{'uid.min'} < $stats->{'uid.max'}, 'min < max');
+ ok($stats->{'uid.count'} > 0, 'count > 0');
+
+ lei_ok(qw(q z:1..));
$out = json_utf8->decode($lei_out);
ok(scalar(@$out) > 1, 'got imported messages');
is(pop @$out, undef, 'trailing JSON null element was null');
my %r;
for (@$out) { $r{ref($_)}++ }
is_deeply(\%r, { 'HASH' => scalar(@$out) }, 'all hashes');
+ lei_ok([qw(tag +kw:seen), $url], undef, undef);
+
+ my $f = "$ENV{HOME}/.local/share/lei/store/mail_sync.sqlite3";
+ ok(-s $f, 'mail_sync tracked for redundant imports');
+ lei_ok('inspect', "blob:$out->[5]->{blob}");
+ my $x = json_utf8->decode($lei_out);
+ is(ref($x->{'lei/store'}), 'ARRAY', 'lei/store in inspect');
+ is(ref($x->{sync}), 'HASH', 'sync in inspect');
+ is(ref($x->{sync}->{$k[0]}), 'ARRAY', 'UID arrays in inspect');
+
+ my $psgi_attach = 'cfa3622cbeffc9bd6b0fc66c4d60d420ba74f60d';
+ lei_ok('blob', $psgi_attach);
+ like($lei_out, qr!^Content-Type: multipart/mixed;!sm, 'got full blob');
+ lei_ok('blob', "$psgi_attach:2");
+ is($lei_out, "b64\xde\xad\xbe\xef\n", 'got attachment');
});
done_testing;