-sub _import_maildir { # maildir_each_file cb
- my ($f, $sto, $set_kw) = @_;
- $sto->ipc_do('set_eml_from_maildir', $f, $set_kw);
-}
-
-sub _import_imap { # imap_each cb
- my ($url, $uid, $kw, $eml, $sto, $set_kw) = @_;
- warn "$url $uid";
- $sto->ipc_do('set_eml', $eml, $set_kw ? @$kw : ());
-}
-
-sub import_path_url {
- my ($self, $input) = @_;
- my $lei = $self->{lei};
- my $ifmt = lc($lei->{opt}->{'format'} // '');
- # TODO auto-detect?
- if ($input =~ m!\A(imap|nntp)s?://!i) {
- $lei->{nrd}->imap_each($input, \&_import_imap, $lei->{sto},
- $lei->{opt}->{kw});
- return;
- } elsif ($input =~ s!\A([a-z0-9]+):!!i) {
- $ifmt = lc $1;
- }
- if (-f $input) {
- open my $fh, '<', $input or return $lei->child_error(1 << 8, <<"");
-unable to open $input: $!
-
- _import_fh($lei, $fh, $input, $ifmt);
- } elsif (-d _ && (-d "$input/cur" || -d "$input/new")) {
- return $lei->fail(<<EOM) if $ifmt && $ifmt ne 'maildir';
-$input appears to a be a maildir, not $ifmt
-EOM
- PublicInbox::MdirReader::maildir_each_file($input,
- \&_import_maildir,
- $lei->{sto}, $lei->{opt}->{kw});
- } else {
- $lei->fail("$input unsupported (TODO)");
+sub _complete_import {
+ my ($lei, @argv) = @_;
+ my $match_cb = $lei->complete_url_prepare(\@argv);
+ my @m = map { $match_cb->($_) } $lei->url_folder_cache->keys;
+ my %f = map { $_ => 1 } @m;
+ if (my $lms = $lei->lms) {
+ @m = map { $match_cb->($_) } $lms->folders;
+ @f{@m} = @m;