diff options
author | Eric Wong <e@80x24.org> | 2021-05-23 01:38:28 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-05-23 19:35:07 +0000 |
commit | 4dea62be127c79cafcbda6ded7988fd8db3439f0 (patch) | |
tree | 4662158a9582876dd7a36f0be59f8753ef6e2ea5 /lib/PublicInbox | |
parent | ec6d2dc31406378f77aa681017083fe8e98b4df9 (diff) | |
download | public-inbox-4dea62be127c79cafcbda6ded7988fd8db3439f0.tar.gz |
It's unreasonable to expect UIDVALIDITY= to be specified in command-line arguments. We'll also check for cases without "$USER@" or ";AUTH=", since we accept those forms on the command-line.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r-- | lib/PublicInbox/LeiExportKw.pm | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/PublicInbox/LeiExportKw.pm b/lib/PublicInbox/LeiExportKw.pm index 5ad33959..82a4db04 100644 --- a/lib/PublicInbox/LeiExportKw.pm +++ b/lib/PublicInbox/LeiExportKw.pm @@ -84,6 +84,37 @@ sub input_path_url { $lms->lms_commit; } +sub match_imap_url ($$) { + my ($all, $url) = @_; # $all = [ $lms->folders ]; + require PublicInbox::URIimap; + my $cli = PublicInbox::URIimap->new($url)->canonical; + my ($s, $h, $mb) = ($cli->scheme, $cli->host, $cli->mailbox); + my @uri = map { PublicInbox::URIimap->new($_)->canonical } + grep(m!\A\Q$s\E://.*?\Q$h\E\b.*?/\Q$mb\E\b!, @$all); + my @match; + for my $x (@uri) { + next if $x->mailbox ne $cli->mailbox; + next if $x->host ne $cli->host; + next if $x->port != $cli->port; + my $x_uidval = $x->uidvalidity; + next if ($cli->uidvalidity // $x_uidval) != $x_uidval; + + # allow nothing in CLI to possibly match ";AUTH=ANONYMOUS" + if (defined($x->auth) && !defined($cli->auth) && + !defined($cli->user)) { + push @match, $x; + # or maybe user was forgotten on CLI: + } elsif (defined($x->user) && !defined($cli->user)) { + push @match, $x; + } elsif (($x->user//"\0") eq ($cli->user//"\0")) { + push @match, $x; + } + } + return $match[0] if scalar(@match) <= 1; + warn "E: `$url' is ambiguous:\n\t", join("\n\t", @match), "\n"; + undef; +} + sub lei_export_kw { my ($lei, @folders) = @_; my $sto = $lei->_lei_store or return $lei->fail(<<EOM); @@ -133,6 +164,16 @@ EOM my $d = 'maildir:'.$lei->rel2abs($_); push(@no, $_) unless $all{$d}; $_ = $d; + } elsif (m!\Aimaps?://!i) { + my $orig = $_; + if (my $canon = match_imap_url(\@all, $orig)) { + $lei->qerr(<<EOM); +# using `$canon' instead of `$orig' +EOM + $_ = $canon; + } else { + push @no, $orig; + } } else { push @no, $_; } |