]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei export-kw: skip read-only IMAP folders
authorEric Wong <e@80x24.org>
Sun, 24 Oct 2021 00:20:40 +0000 (18:20 -0600)
committerEric Wong <e@80x24.org>
Sun, 24 Oct 2021 02:20:33 +0000 (02:20 +0000)
Since we want to store IMAP flags asynchronously and not wait
for results, we can't check for IMAP errors this way and end up
wasting bandwidth on public-inbox-imapd.  Now, we just check
PERMANENTFLAGS up front to ensure a folder can handle IMAP flag
storage before proceeding.

lib/PublicInbox/LeiExportKw.pm
lib/PublicInbox/NetWriter.pm
t/lei-export-kw.t
t/lei-import-imap.t

index 756d0e9c0a4d0d5831ad761cd046ea041394e37b..0ecfb7829772b68875c579c6c9901ba1d34b2610 100644 (file)
@@ -67,7 +67,17 @@ sub input_path_url {
                $self->{lms}->each_src($input, \&export_kw_md, $self, $mdir);
        } elsif ($input =~ m!\Aimaps?://!i) {
                my $uri = PublicInbox::URIimap->new($input);
-               if (my $mic = $self->{nwr}->mic_for_folder($uri)) {
+               my $mic = $self->{nwr}->mic_for_folder($uri);
+               if ($mic && !$self->{nwr}->can_store_flags($mic)) {
+                       my $m = "$input does not support PERMANENTFLAGS";
+                       if (defined $self->{lei}->{opt}->{all}) {
+                               $self->{lei}->qerr("# $m");
+                       } else { # set error code if user explicitly requested
+                               $self->{lei}->child_error(0, "E: $m");
+                       }
+                       return;
+               }
+               if ($mic) {
                        $self->{lms}->each_src($$uri, \&export_kw_imap,
                                                $self, $mic);
                        $mic->expunge;
index 629a752ae79a3b3b1c1ea8ed91e029f925801268..4a1f34f63c458a5733d58569c8b0c6a945678adf 100644 (file)
@@ -56,4 +56,13 @@ sub imap_set_kw {
        $mic; # caller must ->expunge
 }
 
+sub can_store_flags {
+       my ($self, $mic) = @_;
+       for ($mic->Results) {
+               /^\* OK \[PERMANENTFLAGS \(([^\)]*)\)\].*/ and
+                       return $self->can('perm_fl_ok')->($1);
+       }
+       undef;
+}
+
 1;
index 55730e87c050c45e167b9edda3c92da44929264c..88b2a80b9904c222dde88a130baa79bfbcbae989 100644 (file)
@@ -4,7 +4,7 @@
 use strict; use v5.10.1; use PublicInbox::TestCommon;
 use File::Copy qw(cp);
 use File::Path qw(make_path);
-require_mods(qw(lei -imapd Mail::IMAPClient));
+require_mods(qw(lei)); # see lei-import-imap.t for IMAP tests
 my ($tmpdir, $for_destroy) = tmpdir;
 my $expect = eml_load('t/data/0001.patch');
 my $do_export_kw = 1;
index 315567b3b8d4fea66bd2211e11cf377aaee603ea..3b6cb29926eee322355365631ff636c3d261eb3b 100644 (file)
@@ -110,6 +110,9 @@ test_lei({ tmpdir => $tmpdir }, sub {
        is(scalar(@$out), 2, 'got JSON') or diag explain($out);
        lei_ok qw(lcat), $url_orig;
        is($lei_out, $orig, 'lcat w/o UID works');
+
+       ok(!lei(qw(export-kw), $url_orig), 'export-kw fails on read-only IMAP');
+       like($lei_err, qr/does not support/, 'error noted in failure');
 });
 
 done_testing;