From 8600c999da4786d2297ebbf44aa0618461c2f3cf Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 8 Feb 2021 05:06:51 -0100 Subject: lei import: support Maildirs It seems to be working trivially, though I'm probably going to split out Maildir reading into a separate package rather than using LeiToMail. --- t/lei-import-maildir.t | 33 +++++++++++++++++++++++++++++++++ t/lei_to_mail.t | 6 +++--- 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 t/lei-import-maildir.t (limited to 't') diff --git a/t/lei-import-maildir.t b/t/lei-import-maildir.t new file mode 100644 index 00000000..5842e19e --- /dev/null +++ b/t/lei-import-maildir.t @@ -0,0 +1,33 @@ +#!perl -w +# Copyright (C) 2020-2021 all contributors +# License: AGPL-3.0+ +use strict; use v5.10.1; use PublicInbox::TestCommon; +use Cwd qw(abs_path); +test_lei(sub { + my $md = "$ENV{HOME}/md"; + for ($md, "$md/new", "$md/cur", "$md/tmp") { + mkdir($_) or BAIL_OUT("mkdir $_: $!"); + } + symlink(abs_path('t/data/0001.patch'), "$md/cur/x:2,S") or + BAIL_OUT "symlink $md $!"; + ok($lei->(qw(import), $md), 'import Maildir'); + ok($lei->(qw(q s:boolean)), 'lei q'); + my $res = json_utf8->decode($lei_out); + like($res->[0]->{'s'}, qr/use boolean/, 'got expected result'); + is_deeply($res->[0]->{kw}, ['seen'], 'keyword set'); + is($res->[1], undef, 'only got one result'); + + ok($lei->(qw(import), $md), 'import Maildir again'); + ok($lei->(qw(q -d none s:boolean)), 'lei q w/o dedupe'); + my $r2 = json_utf8->decode($lei_out); + is_deeply($r2, $res, 'idempotent import'); + + rename("$md/cur/x:2,S", "$md/cur/x:2,SR") or BAIL_OUT "rename: $!"; + ok($lei->(qw(import), $md), 'import Maildir after +answered'); + ok($lei->(qw(q -d none s:boolean)), 'lei q after +answered'); + $res = json_utf8->decode($lei_out); + like($res->[0]->{'s'}, qr/use boolean/, 'got expected result'); + is_deeply($res->[0]->{kw}, ['answered', 'seen'], 'keywords set'); + is($res->[1], undef, 'only got one result'); +}); +done_testing; diff --git a/t/lei_to_mail.t b/t/lei_to_mail.t index f7535687..a25795ca 100644 --- a/t/lei_to_mail.t +++ b/t/lei_to_mail.t @@ -237,7 +237,7 @@ SKIP: { # FIFO support $wcb->(\(my $x = $buf), $b4dc0ffee); my @f; - PublicInbox::LeiToMail::_maildir_each_file($md, sub { push @f, shift }); + PublicInbox::LeiToMail::maildir_each_file($md, sub { push @f, shift }); open my $fh, $f[0] or BAIL_OUT $!; is(do { local $/; <$fh> }, $buf, 'wrote to Maildir'); @@ -246,7 +246,7 @@ SKIP: { # FIFO support $wcb->(\($x = $buf."\nx\n"), $deadcafe); my @x = (); - PublicInbox::LeiToMail::_maildir_each_file($md, sub { push @x, shift }); + PublicInbox::LeiToMail::maildir_each_file($md, sub { push @x, shift }); is(scalar(@x), 1, 'wrote one new file'); ok(!-f $f[0], 'old file clobbered'); open $fh, $x[0] or BAIL_OUT $!; @@ -257,7 +257,7 @@ SKIP: { # FIFO support $wcb->(\($x = $buf."\ny\n"), $deadcafe); $wcb->(\($x = $buf."\ny\n"), $b4dc0ffee); # skipped by dedupe @f = (); - PublicInbox::LeiToMail::_maildir_each_file($md, sub { push @f, shift }); + PublicInbox::LeiToMail::maildir_each_file($md, sub { push @f, shift }); is(scalar grep(/\A\Q$x[0]\E\z/, @f), 1, 'old file still there'); my @new = grep(!/\A\Q$x[0]\E\z/, @f); is(scalar @new, 1, '1 new file written (b4dc0ffee skipped)'); -- cgit v1.2.3-24-ge0c7