about summary refs log tree commit homepage
path: root/xt/net_writer-imap.t
diff options
context:
space:
mode:
Diffstat (limited to 'xt/net_writer-imap.t')
-rw-r--r--xt/net_writer-imap.t32
1 files changed, 25 insertions, 7 deletions
diff --git a/xt/net_writer-imap.t b/xt/net_writer-imap.t
index 41438cf7..176502ba 100644
--- a/xt/net_writer-imap.t
+++ b/xt/net_writer-imap.t
@@ -1,5 +1,5 @@
 #!perl -w
-# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict; use v5.10.1; use PublicInbox::TestCommon;
 use Sys::Hostname qw(hostname);
@@ -82,14 +82,17 @@ my $mics = do {
         $nwr->imap_common_init;
 };
 my $mic = (values %$mics)[0];
-my $cleanup = PublicInbox::OnDestroy->new($$, sub {
-        my $mic = $nwr->mic_get($uri);
-        $mic->delete($folder) or fail "delete $folder <$folder_uri>: $@";
+my $cleanup = on_destroy sub {
+        if (defined($folder)) {
+                my $mic = $nwr->mic_get($uri);
+                $mic->delete($folder) or
+                        fail "delete $folder <$folder_uri>: $@";
+        }
         if ($tmpdir && -f "$tmpdir/.gitconfig") {
                 local $ENV{HOME} = $tmpdir;
                 system(qw(git credential-cache exit));
         }
-});
+};
 my $imap_append = $nwr->can('imap_append');
 my $smsg = bless { kw => [ 'seen' ] }, 'PublicInbox::Smsg';
 $imap_append->($mic, $folder, undef, $smsg, eml_load('t/plack-qp.eml'));
@@ -134,6 +137,13 @@ test_lei(sub {
         is_deeply($res->[0]->[1], $plack_qp_eml,
                         'lei q wrote expected result');
 
+        my $mdir = "$ENV{HOME}/t.mdir";
+        lei_ok 'convert', $folder_url, '-o', $mdir;
+        my @mdfiles = glob("$mdir/*/*");
+        is(scalar(@mdfiles), 1, '1 message from IMAP => Maildir conversion');
+        is_deeply(eml_load($mdfiles[0]), $plack_qp_eml,
+                'conversion from IMAP to Maildir');
+
         lei_ok qw(q f:matz -a -o), $folder_url;
         $nwr->imap_each($folder_uri, $imap_slurp_all, my $aug = []);
         is(scalar(@$aug), 2, '2 results after augment') or diag explain($aug);
@@ -223,12 +233,12 @@ EOM
         my $pub_cfg = PublicInbox::Config->new;
         PublicInbox::DS->Reset;
         my $ii = PublicInbox::InboxIdle->new($pub_cfg);
-        my $cb = sub { PublicInbox::DS->SetPostLoopCallback(sub {}) };
+        my $cb = sub { @PublicInbox::DS::post_loop_do = (sub {}) };
         my $obj = bless \$cb, 'PublicInbox::TestCommon::InboxWakeup';
         $pub_cfg->each_inbox(sub { $_[0]->subscribe_unlock('ident', $obj) });
         my $w = start_script(['-watch'], undef, { 2 => $err_wr });
         diag 'waiting for initial fetch...';
-        PublicInbox::DS->EventLoop;
+        PublicInbox::DS::event_loop();
         my $ibx = $pub_cfg->lookup_name('wtest');
         my $mm = $ibx->mm;
         ok(defined($mm->num_for('Seen@test.example.com')),
@@ -250,6 +260,14 @@ EOM
         lei_ok qw(q m:testmessage --no-external -o), $folder_url;
         lei_ok qw(up), $folder_url;
         lei_ok qw(up --all=remote);
+        $mic = $nwr->mic_get($uri);
+        $mic->delete($folder) or fail "delete $folder <$folder_uri>: $@";
+        $mic->expunge;
+        undef $mic;
+        undef $folder;
+        ok(!lei(qw(export-kw), $folder_url),
+                'export-kw fails w/ non-existent folder');
+
 });
 
 undef $cleanup; # remove temporary folder