diff options
author | Eric Wong <e@80x24.org> | 2021-05-30 11:45:44 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-05-30 22:36:57 +0000 |
commit | 525d14996e820e7bf2b5e035cf5826b6530f6d92 (patch) | |
tree | 89491a7ac57115e1e763d575771a05c24be57230 /lib/PublicInbox/LeiImport.pm | |
parent | 66b5829892cf0fcd5249e26be21d8b3f3ee35816 (diff) | |
download | public-inbox-525d14996e820e7bf2b5e035cf5826b6530f6d92.tar.gz |
This makes "lei import" behavior with IMAP folders more consistent with that with Maildir. Opening IMAP folders read-write with "SELECT" (instead of read-only with "EXAMINE") was necessary, since it lets an IMAP server communicate to us as to whether or not it's worth refetching IMAP flags of previously imported messages. Fetching UID+FLAGS only is one of the fastest IMAP operations with dovecot, our -imapd and presumably other common IMAP servers. It is issued by common MUAs such as mutt after every SELECT. Users may now rely on "lei import" exclusively to merge mail and keywords into lei/store, and "lei export-kw" to propagate keyword changes back to IMAP servers. A sticks-and-stones workflow for personal mailboxes is currently: lei import imaps://$MY_PERSONAL_INBOX lei q --mua=$MUA -o /tmp/results SEARCH TERMS... # do stuff from within $MUA to /tmp/results lei import /tmp/results # read keyword changes from MUA lei export-kw imaps://$MY_PERSONAL_INBOX # repeat when new stuff shows up in personal inbox The next goal is to automate repeated imports + export-kw commands with with inotify and IMAP IDLE.
Diffstat (limited to 'lib/PublicInbox/LeiImport.pm')
-rw-r--r-- | lib/PublicInbox/LeiImport.pm | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/PublicInbox/LeiImport.pm b/lib/PublicInbox/LeiImport.pm index 01e6c93c..f9a46ec5 100644 --- a/lib/PublicInbox/LeiImport.pm +++ b/lib/PublicInbox/LeiImport.pm @@ -45,7 +45,16 @@ sub input_net_cb { # imap_each / nntp_each my ($uri, $uid, $kw, $eml, $self) = @_; my $vmd = $self->{-import_kw} ? { kw => $kw } : undef; $vmd->{sync_info} = [ $$uri, $uid ] if $self->{-mail_sync}; - $self->input_eml_cb($eml, $vmd); + if (defined $eml) { + $self->input_eml_cb($eml, $vmd); + } elsif ($vmd) { # old message, kw only + my $oid = $self->{-lms_ro}->imap_oid2($uri, $uid) // return; + my @docids = $self->{lse}->over->blob_exists($oid) or return; + my $lei = $self->{lei}; + $lei->qerr("# $oid => @$kw\n") if $lei->{opt}->{verbose}; + $self->{lei}->{sto}->ipc_do('set_eml_vmd', undef, + $vmd, \@docids); + } } sub do_import_index ($$@) { @@ -65,7 +74,12 @@ sub do_import_index ($$@) { # $j = $net->net_concurrency($j); TODO if ($lei->{opt}->{incremental} // 1) { $net->{incremental} = 1; - $net->{-lms_ro} = $lei->_lei_store->search->lms // 0; + $net->{-lms_ro} = $sto->search->lms // 0; + if ($self->{-import_kw}) { + $net->{each_old} = 1; + $self->{-lms_ro} = $net->{-lms_ro}; + $self->{lse} = $sto->search; + } } } else { my $nproc = $self->detect_nproc; |