diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2022-06-15 07:23:51 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-06-22 11:26:13 +0200 |
commit | 7aa71d334b2755cc5e92fcf83398ce65ede45b40 (patch) | |
tree | f9fa3a1d3e29c74d7c70ddc0195a13b5babbfaaf /worker/imap/worker.go | |
parent | e1d8bc4d17cb7bd79e19fdf866d1da2fedda4de5 (diff) | |
download | aerc-7aa71d334b2755cc5e92fcf83398ce65ede45b40.tar.gz |
imap: add option to cache headers
Add option to cache headers for imap accounts. Cache db is located at
$XDG_CACHE_DIR/aerc/{account name}. The cache is cleaned of stale
entries when aerc is first opened.
Two new account level configuration options are introduced:
* cache-headers (Default: false)
* cache-max-age (Default: 30 days (720 hours))
The change in worker/imap/open.go is to set the selected directory. This
is required to access the UIDVALIDITY field, which is used in
combination with the message ID to form the key for use in the cache db.
The key structure is: "header.{UIDVALIDITY}.{UID}"
Where reasonable, cache does not stop aerc from running. In general, if
there is an error in the cache, aerc should continue working as usual.
Errors are either displayed to the user or logged.
All messages are stored without flags, and when retrieved have the flags
set to SEEN. This is to prevent UI flashes. A new method to
FetchMessageFlags is introduced to update flags of cached headers. This
is done asynchronously, and the user will see their messages appear and
then any flags updated. The message will initially show as SEEN, but
will update to unread. I considered updating the cache with the
last-known flag state, however it seems prudent to spare the R/W cycle
and assume that - eventually - all messages will end up read, and if it
isn't the update will occur rather quickly.
Note that leveldb puts a lock on the database, preventing multiple
instances of aerc from accessing the cache at the same time.
Much of this work is based on previous efforts by Vladimír Magyar.
Implements: https://todo.sr.ht/~rjarry/aerc/2
Thanks: Vladimír Magyar <vladimir@mgyar.me>
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: inwit <inwit@sindominio.net>
Reviewed-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker/imap/worker.go')
-rw-r--r-- | worker/imap/worker.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/worker/imap/worker.go b/worker/imap/worker.go index da0716e1..e890bb8d 100644 --- a/worker/imap/worker.go +++ b/worker/imap/worker.go @@ -9,6 +9,7 @@ import ( sortthread "github.com/emersion/go-imap-sortthread" "github.com/emersion/go-imap/client" "github.com/pkg/errors" + "github.com/syndtr/goleveldb/leveldb" "git.sr.ht/~rjarry/aerc/lib" "git.sr.ht/~rjarry/aerc/models" @@ -49,6 +50,8 @@ type imapConfig struct { keepalive_period time.Duration keepalive_probes int keepalive_interval int + cacheEnabled bool + cacheMaxAge time.Duration } type IMAPWorker struct { @@ -63,6 +66,7 @@ type IMAPWorker struct { idler *idler observer *observer + cache *leveldb.DB } func NewIMAPWorker(worker *types.Worker) (types.Backend, error) { @@ -178,6 +182,8 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error { w.handleFetchMessageBodyPart(msg) case *types.FetchFullMessages: w.handleFetchFullMessages(msg) + case *types.FetchMessageFlags: + w.handleFetchMessageFlags(msg) case *types.DeleteMessages: w.handleDeleteMessages(msg) case *types.FlagMessages: |