From 525d14996e820e7bf2b5e035cf5826b6530f6d92 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 30 May 2021 11:45:44 +0000 Subject: lei import: import IMAP flag changes from old messages 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. --- lib/PublicInbox/LeiMailSync.pm | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'lib/PublicInbox/LeiMailSync.pm') diff --git a/lib/PublicInbox/LeiMailSync.pm b/lib/PublicInbox/LeiMailSync.pm index c7f78239..36cd564c 100644 --- a/lib/PublicInbox/LeiMailSync.pm +++ b/lib/PublicInbox/LeiMailSync.pm @@ -361,6 +361,17 @@ sub forget_folder { $dbh->do('DELETE FROM folders WHERE fid = ?', undef, $fid); } +sub imap_oid2 ($$$) { + my ($self, $uri, $uid) = @_; # $uri MUST have UIDVALIDITY + my $fid = $self->{fmap}->{"$uri"} //= fid_for($self, "$uri") // return; + my $sth = $self->{dbh}->prepare_cached(<execute($fid, $uid); + my ($oidbin) = $sth->fetchrow_array; + $oidbin ? unpack('H*', $oidbin) : undef; +} + sub imap_oid { my ($self, $lei, $uid_uri) = @_; my $mailbox_uri = $uid_uri->clone; @@ -373,16 +384,10 @@ sub imap_oid { } $lei->qerr(@{$err->{qerr}}) if $err->{qerr}; } - my $fid = $self->{fmap}->{$folders->[0]} //= - fid_for($self, $folders->[0]) // return; - my $sth = $self->{dbh}->prepare_cached(<execute($fid, $uid_uri->uid); - my ($oidbin) = $sth->fetchrow_array; - $oidbin ? unpack('H*', $oidbin) : undef; + imap_oid2($self, $folders->[0], $uid_uri->uid); } + # FIXME: something with "lei " is causing uncommitted transaction # warnings, not sure what... sub DESTROY { -- cgit v1.2.3-24-ge0c7