* [PATCH 2/7] lei export-kw: skip read-only IMAP folders
2021-10-24 0:20 7% [PATCH 0/7] misc tweaks and fixes Eric Wong
@ 2021-10-24 0:20 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-10-24 0:20 UTC (permalink / raw)
To: meta
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 | 12 +++++++++++-
lib/PublicInbox/NetWriter.pm | 9 +++++++++
t/lei-export-kw.t | 2 +-
t/lei-import-imap.t | 3 +++
4 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/lib/PublicInbox/LeiExportKw.pm b/lib/PublicInbox/LeiExportKw.pm
index 756d0e9c..0ecfb782 100644
--- a/lib/PublicInbox/LeiExportKw.pm
+++ b/lib/PublicInbox/LeiExportKw.pm
@@ -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;
diff --git a/lib/PublicInbox/NetWriter.pm b/lib/PublicInbox/NetWriter.pm
index 629a752a..4a1f34f6 100644
--- a/lib/PublicInbox/NetWriter.pm
+++ b/lib/PublicInbox/NetWriter.pm
@@ -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;
diff --git a/t/lei-export-kw.t b/t/lei-export-kw.t
index 55730e87..88b2a80b 100644
--- a/t/lei-export-kw.t
+++ b/t/lei-export-kw.t
@@ -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;
diff --git a/t/lei-import-imap.t b/t/lei-import-imap.t
index 315567b3..3b6cb299 100644
--- a/t/lei-import-imap.t
+++ b/t/lei-import-imap.t
@@ -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;
^ permalink raw reply related [relevance 7%]
* [PATCH 0/7] misc tweaks and fixes
@ 2021-10-24 0:20 7% Eric Wong
2021-10-24 0:20 7% ` [PATCH 2/7] lei export-kw: skip read-only IMAP folders Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-10-24 0:20 UTC (permalink / raw)
To: meta
Patch 2 helps lei users avoid wasting bandwidth.
I've been running patches 6 and 7 on https://yhbt.net/lore/
for a while, now; and memory use seems far lower.
The rest are pretty minor things, I think.
Eric Wong (7):
lei: always pass $lei to LeiAuth->op_merge
lei export-kw: skip read-only IMAP folders
shared_kv: remove cache_size attribute support
http: use a larger buffer for ->getline responses
listener: emit warnings on EPERM
thread: avoid Perl5 internal scratchpad target cache
git: avoid Perl5 internal scratchpad target cache
lib/PublicInbox/Git.pm | 3 ++-
lib/PublicInbox/HTTP.pm | 2 +-
lib/PublicInbox/LeiExportKw.pm | 14 ++++++++++++--
lib/PublicInbox/LeiForgetSearch.pm | 2 +-
lib/PublicInbox/LeiImport.pm | 2 +-
lib/PublicInbox/LeiLsMailSource.pm | 2 +-
lib/PublicInbox/LeiMailDiff.pm | 2 +-
lib/PublicInbox/LeiRefreshMailSync.pm | 2 +-
lib/PublicInbox/LeiTag.pm | 2 +-
lib/PublicInbox/LeiXSearch.pm | 2 +-
lib/PublicInbox/Listener.pm | 8 ++------
lib/PublicInbox/NetWriter.pm | 9 +++++++++
lib/PublicInbox/SearchThread.pm | 22 +++++++++++-----------
lib/PublicInbox/SearchView.pm | 4 ++--
lib/PublicInbox/SharedKV.pm | 3 ---
lib/PublicInbox/View.pm | 4 ++--
t/lei-export-kw.t | 2 +-
t/lei-import-imap.t | 3 +++
t/thread-cycle.t | 4 ++--
19 files changed, 54 insertions(+), 38 deletions(-)
^ permalink raw reply [relevance 7%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-10-24 0:20 7% [PATCH 0/7] misc tweaks and fixes Eric Wong
2021-10-24 0:20 7% ` [PATCH 2/7] lei export-kw: skip read-only IMAP folders Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).