13 Commits

Author SHA1 Message Date
Tim Culverhouse
b77bd33d8a jmap: cache threads
Cache threads that we have fetched. Monitor threads for changes, and
fetch any email which we don't have for any thread that changes.

Changelog-added: The JMAP backend now supports full thread fetching
 and caching (limited within a single mailbox).
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2024-12-21 16:49:31 +01:00
Tim Culverhouse
64b3d96d2f jmap: correctly compare when FolderContents needs refresh
A folders contents need refreshing if we don't have any saved state, or
if the sort criteria is different than the cache, or if the filter is
different than the cache. The previous logic required a refresh if
the cached filter == nil. This is almost always the case: opening a
plain folder has a nil filter. The only filter criteria is added in the
parsing step (ie: inMailbox). This meant every directory change that
wasn't already filtered required a Refresh. The new logic fixes this.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2024-12-21 16:49:14 +01:00
Tristan Partin
e35c193db1 jmap: fix emailKey function name
This was just a simple typo.

Signed-off-by: Tristan Partin <tristan@partin.io>
Acked-by: Robin Jarry <robin@jarry.cc>
2024-08-20 09:29:31 +02:00
Tristan Partin
cd92da0e89 jmap: fetch entire threads
Fetch an email's entire thread in the JMAP backend.

Changelog-added: Fetch entire threads in the JMAP backend.
Signed-off-by: Tristan Partin <tristan@partin.io>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2024-08-03 20:16:01 +02:00
Robin Jarry
446d5303b9 jmap: revert fetch threads support
This reverts commits:

 9e93d9efdb ("jmap: fix go static check failure")
 0465509eed ("jmap: skip Email/get call if no emails to get")
 9f97c698e3 ("jmap: fetch entire threads")

Issues have been reported about disappearing sent messages.

Reported-by: Tristan Partin <tristan@partin.io>
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Tristan Partin <tristan@partin.io>
2024-06-29 00:18:18 +02:00
Tristan Partin
9f97c698e3 jmap: fetch entire threads
JMAP was missing good thread support, especially when compared to Gmail.
This will fetch entire threads when possible.

Signed-off-by: Tristan Partin <tristan@partin.io>
2024-05-28 23:52:39 +02:00
Robin Jarry
8edf7b0e4d log: move package to lib
This has nothing to do at the root of the source tree.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Bence Ferdinandy <bence@ferdinandy.com>
2024-02-14 23:04:38 +01:00
Robin Jarry
635f1fb499 jmap: avoid crash when server returns garbage
For some reason, a JMAP server may send message details with empty
blobId values. This is invalid but it should not cause a crash.

Error: runtime error: slice bounds out of range [-2:]

goroutine 16 [running]:
git.sr.ht/~rjarry/aerc/worker/jmap/cache.(*JMAPCache).blobPath()
	git.sr.ht/~rjarry/aerc/worker/jmap/cache/blob.go:43 +0x95
git.sr.ht/~rjarry/aerc/worker/jmap/cache.(*JMAPCache).GetBlob()
	git.sr.ht/~rjarry/aerc/worker/jmap/cache/blob.go:11 +0x18
git.sr.ht/~rjarry/aerc/worker/jmap.(*JMAPWorker).handleFetchMessageBodyPart()
	git.sr.ht/~rjarry/aerc/worker/jmap/fetch.go:116 +0x26f
git.sr.ht/~rjarry/aerc/worker/jmap.(*JMAPWorker).handleMessage()
	git.sr.ht/~rjarry/aerc/worker/jmap/worker.go:142 +0x25f
git.sr.ht/~rjarry/aerc/worker/jmap.(*JMAPWorker).Run()
	git.sr.ht/~rjarry/aerc/worker/jmap/worker.go:177 +0x105
git.sr.ht/~rjarry/aerc/app.NewAccountView.func3()
	git.sr.ht/~rjarry/aerc/app/account.go:105 +0x57
created by git.sr.ht/~rjarry/aerc/app.NewAccountView in goroutine 1
	git.sr.ht/~rjarry/aerc/app/account.go:98 +0x468

Ignore a blobId when it is an empty string.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Tristan Partin <tristan@partin.io>
2024-01-20 00:29:19 +01:00
Robin Jarry
8464b37385 search: use a common api for all workers
Define a SearchCriteria structure. Update the FetchDirectoryContents,
FetchDirectoryThreaded and SearchDirectory worker messages to include
this SearchCriteria structure instead of a []string slice.

Parse the search arguments in a single place into a SearchCriteria
structure and use it to search/filter via the message store.

Update all workers to use that new API. Clarify the man page indicating
that notmuch supports searching with aerc's syntax and also with notmuch
specific syntax.

getopt is no longer needed, remove it from go.mod.

NB: to support more complex search filters in JMAP, we need to use an
email.Filter interface. Since GOB does not support encoding/decoding
interfaces, store the raw SearchCriteria and []SortCriterion values in
the cached FolderContents. Translate them to JMAP API objects when
sending an email.Query request to the server.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Moritz Poldrack <moritz@poldrack.dev>
Tested-by: Inwit <inwit@sindominio.net>
2023-10-28 19:24:59 +02:00
Robin Jarry
a5bc7ccf0c xdg: get rid of deprecated dependencies
github.com/mitchellh/go-homedir has not received any update since 2019.
The last release of github.com/kyoh86/xdg was in 2020 and it has been
marked as deprecated by its author.

Replace these with internal functions.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Moritz Poldrack <moritz@poldrack.dev>
2023-08-27 18:44:12 +02:00
Tim Culverhouse
f6e3a21db5 jmap: cache session as json
The gob encoder requires registration of types used during encoding.
There are several types defined in the Session object that don't
directly or indirectly get registered with gob. As a result, the session
object never actually gets cached, requiring an authentication step
which is often unnecessary.

Use json encoding for this object to provide a simpler serialization
path.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Moritz Poldrack <moritz@poldrack.dev>
2023-08-24 14:14:44 +02:00
Robin Jarry
7a674312b6 jmap: fix crash when opening multiple instances
Fix the following error when opening another aerc instance with the same
jmap account:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x9a1ffd]

git.sr.ht/~rjarry/aerc/worker/jmap/cache.(*JMAPCache).get(0x99d08e?, {0xbc3c1a?, 0xc00003a160?})
	git.sr.ht/~rjarry/aerc/worker/jmap/cache/cache.go:47 +0x1d
git.sr.ht/~rjarry/aerc/worker/jmap/cache.(*JMAPCache).GetSession(0xc00052a030?)
	git.sr.ht/~rjarry/aerc/worker/jmap/cache/session.go:8 +0x29
git.sr.ht/~rjarry/aerc/worker/jmap.(*JMAPWorker).handleConnect(0xc00055e180, 0x0?)
	git.sr.ht/~rjarry/aerc/worker/jmap/connect.go:29 +0xd3
git.sr.ht/~rjarry/aerc/worker/jmap.(*JMAPWorker).handleMessage(0xc000311500?, {0xcc8b00?, 0xc0001fcff0?})
	git.sr.ht/~rjarry/aerc/worker/jmap/worker.go:114 +0x9f
git.sr.ht/~rjarry/aerc/worker/jmap.(*JMAPWorker).Run(0xc00055e180)
	git.sr.ht/~rjarry/aerc/worker/jmap/worker.go:177 +0x10c
git.sr.ht/~rjarry/aerc/widgets.NewAccountView.func3()
	git.sr.ht/~rjarry/aerc/widgets/account.go:110 +0x65
created by git.sr.ht/~rjarry/aerc/widgets.NewAccountView
	git.sr.ht/~rjarry/aerc/widgets/account.go:103 +0x518

Do not return an error if the leveldb cannot be opened, log a message
and fallback on the in-memory cache.

Fixes: be0bfc1ae2 ("worker: add jmap support")
Reported-by: Tim Culverhouse <tim@timculverhouse.com>
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
2023-07-15 17:09:49 +02:00
Robin Jarry
be0bfc1ae2 worker: add jmap support
Add support for JMAP backends. This is on par with IMAP features with
some additions specific to JMAP:

* tagging
* sending emails

This makes use of git.sr.ht/~rockorager/go-jmap for the low level
interaction with the JMAP server. The transport is JSON over HTTPS.

For now, only oauthbearer with token is supported. If this proves
useful, we may need to file for an official three-legged oauth support
at JMAP providers.

I have tested most features and this seems to be reliable. There are
some quirks with the use-labels option. Especially when moving and
deleting messages from the "All mail" virtual folder (see aerc-jmap(5)).

Overall, the user experience is nice and there are a lot less background
updates issues than with IMAP (damn IDLE mode hanging after restoring
from sleep).

I know that not everyone has access to a JMAP provider. For those
interested, there are at least these two commercial offerings:

  https://www.fastmail.com/
  https://www.topicbox.com/

And, if you host your own mail, you can use a JMAP capable server:

  https://stalw.art/jmap/
  https://www.cyrusimap.org/imap/download/installation/http/jmap.html

Link: https://www.rfc-editor.org/rfc/rfc8620.html
Link: https://www.rfc-editor.org/rfc/rfc8621.html
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
2023-06-21 17:29:21 +02:00