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/LeiMailSync.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/LeiMailSync.pm')
-rw-r--r-- | lib/PublicInbox/LeiMailSync.pm | 21 |
1 files changed, 13 insertions, 8 deletions
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(<<EOM, undef, 1); +SELECT oidbin FROM blob2num WHERE fid = ? AND uid = ? +EOM + $sth->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(<<EOM, undef, 1); -SELECT oidbin FROM blob2num WHERE fid = ? AND uid = ? -EOM - $sth->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 <up|q>" is causing uncommitted transaction # warnings, not sure what... sub DESTROY { |