aboutsummaryrefslogtreecommitdiffstats
path: root/worker/imap
Commit message (Collapse)AuthorAgeFilesLines
* lint: update golangci-lint to 1.61.0Tristan Partin2024-09-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | golangci-lint 1.56 does not work with go 1.23. It causes obscure errors: [linters_context/goanalysis] buildir: panic during analysis: Cannot range over: func(yield func(K, V) bool), goroutine 4743 [running]: runtime/debug.Stack() /usr/lib/go/src/runtime/debug/stack.go:26 +0x5e github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1() /home/build/go/pkg/mod/github.com/golangci/golangci-lint@v1.56.1/pkg/golinters/goanalysis/runner_action.go:104 +0x5a panic({0x164b260?, 0xc00669b4a0?}) /usr/lib/go/src/runtime/panic.go:785 +0x132 honnef.co/go/tools/go/ir.(*builder).rangeStmt(0xc000051910, 0xc00a29cf00, 0xc009bf55c0, 0x0, {0x1af1960, 0xc009bf55c0}) /home/build/go/pkg/mod/honnef.co/go/tools@v0.4.6/go/ir/builder.go:2214 +0x894 honnef.co/go/tools/go/ir.(*builder).stmt(0xc000051910, 0xc00a29cf00, {0x1af6970?, 0xc009bf55c0?}) /home/build/go/pkg/mod/honnef.co/go/tools@v0.4.6/go/ir/builder.go:2427 +0x20a honnef.co/go/tools/go/ir.(*builder).stmtList(...) /home/build/go/pkg/mod/honnef.co/go/tools@v0.4.6/go/ir/builder.go:847 honnef.co/go/tools/go/ir.(*builder).stmt(0xc000051910, 0xc00a29cf00, {0x1af6880?, 0xc004f52ed0?}) /home/build/go/pkg/mod/honnef.co/go/tools@v0.4.6/go/ir/builder.go:2385 +0x1415 honnef.co/go/tools/go/ir.(*builder).buildFunction(0xc000051910, 0xc00a29cf00) /home/build/go/pkg/mod/honnef.co/go/tools@v0.4.6/go/ir/builder.go:2497 +0x417 honnef.co/go/tools/go/ir.(*builder).buildFuncDecl(0xc000051910, 0xc00622eea0, 0xc004f52f00) /home/build/go/pkg/mod/honnef.co/go/tools@v0.4.6/go/ir/builder.go:2534 +0x189 honnef.co/go/tools/go/ir.(*Package).build(0xc00622eea0) /home/build/go/pkg/mod/honnef.co/go/tools@v0.4.6/go/ir/builder.go:2638 +0xb46 sync.(*Once).doSlow(0xc009b81260?, 0xc009bf5bc0?) /usr/lib/go/src/sync/once.go:76 +0xb4 sync.(*Once).Do(...) /usr/lib/go/src/sync/once.go:67 honnef.co/go/tools/go/ir.(*Package).Build(...) /home/build/go/pkg/mod/honnef.co/go/tools@v0.4.6/go/ir/builder.go:2556 honnef.co/go/tools/internal/passes/buildir.run(0xc000cf61a0) /home/build/go/pkg/mod/honnef.co/go/tools@v0.4.6/internal/passes/buildir/buildir.go:86 +0x18b github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc002d77d70) /home/build/go/pkg/mod/github.com/golangci/golangci-lint@v1.56.1/pkg/golinters/goanalysis/runner_action.go:190 +0x9cd github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2() /home/build/go/pkg/mod/github.com/golangci/golangci-lint@v1.56.1/pkg/golinters/goanalysis/runner_action.go:112 +0x17 github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc0007a5c70, {0x1859190, 0x7}, 0xc001c28f48) /home/build/go/pkg/mod/github.com/golangci/golangci-lint@v1.56.1/pkg/timeutils/stopwatch.go:111 +0x44 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc00212f680?) /home/build/go/pkg/mod/github.com/golangci/golangci-lint@v1.56.1/pkg/golinters/goanalysis/runner_action.go:111 +0x6e github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc002d77d70) /home/build/go/pkg/mod/github.com/golangci/golangci-lint@v1.56.1/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xa5 created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze in goroutine 3468 /home/build/go/pkg/mod/github.com/golangci/golangci-lint@v1.56.1/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x1e9 Update golangci-lint to 1.61.0 that works with go 1.23. It has new checkers that report errors that we need to fix: lib/crypto/gpg/gpgbin/gpgbin.go:226:22: printf: non-constant format string in call to fmt.Errorf (govet) return fmt.Errorf(strings.TrimPrefix(line, "[GNUPG:] ")) ^ worker/imap/observer.go:142:21: printf: non-constant format string in call to fmt.Errorf (govet) Error: fmt.Errorf(errMsg), ^ app/dirlist.go:409:5: S1009: should omit nil check; len() for []string is defined as zero (gosimple) if dirlist.dirs == nil || len(dirlist.dirs) == 0 { ^ app/dirtree.go:181:5: S1009: should omit nil check; len() for []*git.sr.ht/~rjarry/aerc/worker/types.Thread is defined as zero (gosimple) if dt.list == nil || len(dt.list) == 0 || dt.countVisible(dt.list) < y+dt.Scroll() { ^ app/authinfo.go:30:34: printf: non-constant format string in call to (*git.sr.ht/~rjarry/aerc/lib/ui.Context).Printf (govet) ctx.Printf(0, 0, defaultStyle, text) ^ app/authinfo.go:34:27: printf: non-constant format string in call to (*git.sr.ht/~rjarry/aerc/lib/ui.Context).Printf (govet) ctx.Printf(0, 0, style, text) ^ app/authinfo.go:62:34: printf: non-constant format string in call to (*git.sr.ht/~rjarry/aerc/lib/ui.Context).Printf (govet) x += ctx.Printf(x, 0, style, text) ^ Pretty much all of these errors are us passing non-const format strings to various methods. In C land, this is a large security issue. I would assume the same stands in Go. Thank you golangci-lint! Link: https://builds.sr.ht/~rjarry/job/1332376#task-validate-500 Signed-off-by: Tristan Partin <tristan@partin.io> Acked-by: Robin Jarry <robin@jarry.cc>
* treewide: replace uint32 uids with opaque stringsRobin Jarry2024-08-288-37/+46
| | | | | | | | | | | | | | | | | Add a new models.UID type (an alias to string). Replace all occurrences of uint32 being used as message UID or thread UID with models.UID. Update all workers to only expose models.UID values and deal with the conversion internally. Only IMAP needs to convert these to uint32. All other backends already use plain strings as message identifiers, in which case no conversion is even needed. The directory tree implementation needed to be heavily refactored in order to accommodate thread UID not being usable as a list index. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Inwit <inwit@sindominio.net> Tested-by: Tim Culverhouse <tim@timculverhouse.com>
* imap: fix SeqMap.Pop runtime errorKoni Marti2024-08-241-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix a runtime error in the SeqMap.Pop function causing a index-out-of-range panic: Version: 0.18.2.r22.gfff69046 (go1.22.6 amd64 linux 2024-08-10) Error: runtime error: index out of range [487] with length 487 goroutine 24430 [running]: runtime/debug.Stack() runtime/debug/stack.go:24 +0x5e git.sr.ht/~rjarry/aerc/lib/log.PanicHandler() git.sr.ht/~rjarry/aerc/lib/log/panic-logger.go:49 +0x66a panic({0x5dbf5a688020?, 0xc002ab0d80?}) runtime/panic.go:770 +0x132 git.sr.ht/~rjarry/aerc/worker/imap.(*SeqMap).Pop(0xc0003d4940, 0x1e8) git.sr.ht/~rjarry/aerc/worker/imap/seqmap.go:64 +0x17c git.sr.ht/~rjarry/aerc/worker/imap.(*IMAPWorker).handleImapUpdate(0xc0003d4820, {0x5dbf5a6dbd00, 0xc002068708}) git.sr.ht/~rjarry/aerc/worker/imap/worker.go:296 +0x26c git.sr.ht/~rjarry/aerc/worker/imap.(*IMAPWorker).drainUpdates.func1() git.sr.ht/~rjarry/aerc/worker/imap/flags.go:29 +0x10c created by git.sr.ht/~rjarry/aerc/worker/imap.(*IMAPWorker).drainUpdates in goroutine 52 git.sr.ht/~rjarry/aerc/worker/imap/flags.go:21 +0x78 SeqMap.Pop uses two locks in the same function: first lock grabs the size of the slice, second lock removes the given index in the slice. Combine the two locks to prevent a change of the slice size before the index can be removed. Reported-by: Moritz Poldrack <moritz@poldrack.dev> Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: expose extension in capabilitiesKoni Marti2024-08-041-0/+2
| | | | | | | | Expose the supported extensions in the capabilities. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: extend SEARCH with X-GM-RAW for full Gmail search syntaxKoni Marti2024-08-044-6/+120
| | | | | | | | | | | | | Extend the IMAP SEARCH command with the X-GM-RAW attribute for full Gmail search syntax. It is based on the Gmail extension (X-GM-EXT-1). The search/filter command will be interpreted in the same manner as in the Gmail web interface. Link: https://support.google.com/mail/answer/7190?hl=en Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Inwit <inwit@sindominio.net> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: report errors from serverRobin Jarry2024-07-011-21/+31
| | | | | | | | | | | | Avoid eternal spinner on the message list when the imap server advertises some message UIDs but fails to provide their headers when aerc asks from them. When an error occurs, or if some UIDs are not returned, make sure to report the errors to the message list UI. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Tristan Partin <tristan@partin.io>
* imap: fix panic in connectKoni Marti2024-05-091-2/+3
| | | | | | | | | | | | | Fix a nil pointer dereference panic in connect when trying to obtain the folder delimiter. There is a List call to the imap server that in some instances can return a nil *imap.MailboxInfo that is not checked before it is dereferenced. Link: https://lists.sr.ht/~rjarry/aerc-devel/%3CEDE672E5-3F6F-402D-B1A4-5477183FC13C@ukr.net%3E Reported-by: Misha <ulianich_mihail@ukr.net> Signed-off-by: Koni Marti <koni.marti@gmail.com> Reviewed-by: Tim Culverhouse <tim@tim.culverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: add imaps+insecure modeMoritz Poldrack2024-05-011-0/+3
| | | | | | | | | | | | | | When connecting through environments bypassing hostnames, like SSH tunnels, the certificate verification of the server will fail, making it impossible to connect, if plain IMAP has been disabled. Add handling for the insecure modifier to the imaps connection. Changelog-added: Add `imaps+insecure` to the available protocols, for connections that should ignore issues with certificate verification. Signed-off-by: Moritz Poldrack <git@moritz.sh> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: drain updates channel when moving messagesKoni Marti2024-02-261-0/+3
| | | | | | | | | | | | | Drain the updates channel when moving messages to prevent a backend freeze. This also fixes a possible freeze for large-scale archive operations since the archive command uses the move operation. Reported-by: Moritz Poldrack <moritz@poldrack.dev> Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Jeremy Baxter <jtbx@disroot.org> Tested-by: Moritz Poldrack <moritz@poldrack.dev> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: drain updates channel when deleting messagesKoni Marti2024-02-261-0/+40
| | | | | | | | | | | | | Drain the buffered updates channel when deleting messages to prevent a backend freeze. Unilateral update messages from the IMAP server can fill up the buffered channel if not handled during a large operation (more than ~50 messages). Link: https://lists.sr.ht/~rjarry/aerc-discuss/%3CCZCPBTWI3PIW.T8MWNCBG7FGL%40disroot.org%3E Changelog-fixed: Prevent a freeze for large-scale deletions with IMAP. Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Jeremy Baxter <jtbx@disroot.org> Acked-by: Robin Jarry <robin@jarry.cc>
* log: move package to libRobin Jarry2024-02-148-8/+8
| | | | | | | 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>
* filter: allow workers to combine filter termsKoni Marti2024-02-111-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Allow the backend workers to combine the filter terms. Currently, the consecutive filters are joined in the message store with a space (" "). This works well for most backends, but makes the filter combination for notmuch confusing. Example: Issuing two consecutive filter commands in notmuch :filter not tag:list :filter tag:list would create the following filter query 'not tag:list tag:list' This is not what users would expect; they expect: '(not tag:list) and (tag:list)' Note that the notmuch backend works correctly for the given query, but produced a query that does not match the user's expectation. This patch fixes this. The combination of filter terms in other backends remains the same. Reported-by: Ángel Castañeda <angel@acsq.me> Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Inwit <inwit@sindominio.net> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: fix connection when host only has ipv6 addressRobin Jarry2024-02-041-8/+2
| | | | | | | | | | | | | | | | | | | | | | | | | Some IMAP servers report both IPv4 and IPv6 addresses from their DNS name: $ host imap.gmail.com imap.gmail.com has address 108.177.15.109 imap.gmail.com has address 108.177.15.108 imap.gmail.com has IPv6 address 2a00:1450:400c:c0a::6c imap.gmail.com has IPv6 address 2a00:1450:400c:c0a::6d ResolveTCPAddr actually returns the first *IPv4* address by default, unless the address string is an explicit IPv6 address. Directly use net.Dial which has a fast fallback mechanism. It first tries to connect with an IPv6 address (if any) and if that fails, it will retry with an IPv4 address (if any) before failing completely. Link: https://cs.opensource.google/go/go/+/refs/tags/go1.21.6:src/net/ipsock.go;l=81 Link: https://lists.sr.ht/~rjarry/aerc-discuss/%3CCYVLU3AOA00I.26I5IMAF3T4CK%40dow.land%3E Link: https://pkg.go.dev/net#Dial Reported-by: Jonathan Dowland <jon@dow.land> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Koni Marti <koni.marti@gmail.com>
* flags: add support for draft flagJason Cox2024-01-261-0/+2
| | | | | | | | | | | | | | Support the draft flag wherever flags are used. Automatically set it when postponing a message, and allow recalling a message without the -f flag if it has the draft flag set, regardless of what folder it's in. Notmuch doesn't seem to pick up on the draft flag when indexing even though the flag is set on the maildir file. Explicitly set all tags corresponding to set flags when appending a message in notmuch. Changelog-added: Support the `draft` flag. Signed-off-by: Jason Cox <me@jasoncarloscox.com> Acked-by: Robin Jarry <robin@jarry.cc>
* idler: improve the imap idlerKoni Marti2024-01-255-137/+177
| | | | | | | | | | Rewrite the imap idler to make it more fault tolerant and prevent hangs (and possibly short writes). Fixes: https://todo.sr.ht/~rjarry/aerc/208 Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Karel Balej <balejk@matfyz.cz> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: show parseable messages on errorMoritz Poldrack2023-12-301-12/+13
| | | | | | | | | | | | | Currently if there are mails aerc can not properly handle, listing the mailbox is aborted. This is especially bothersome if the message one is looking for would be parseable without issue. Show an error if parsing of a message fails, but handle all other messages as normal. This leads to those messages showing up as still loading. Signed-off-by: Moritz Poldrack <git@moritz.sh> Acked-by: Robin Jarry <robin@jarry.cc>
* search: use a common api for all workersRobin Jarry2023-10-283-103/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* worker: move shared code to libRobin Jarry2023-10-281-2/+2
| | | | | | | | | | | | | Avoid importing code from worker/lib into lib. It should only be the other way around. Move the message parsing code used by maildir, notmuch, mbox and the eml viewer into a lib/rfc822 package. Adapt imports accordingly. 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>
* xdg: get rid of deprecated dependenciesRobin Jarry2023-08-272-26/+4
| | | | | | | | | | | 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>
* imap: support the Gmail extension (X-GM-EXT-1)Koni Marti2023-08-035-0/+186
| | | | | | | | | | | | | Support the IMAP Gmail extension (X-GM-EXT-1) to fetch all messages for a given thread. This allows client-side threading to display a full message thread. Obviously, it requires a Gmail account to work. The extension is only used when requested in accounts.conf with: "use-gmail-ext = true" (default: false) Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc> Tested-by: Tristan Partin <tristan@partin.io>
* imap: fix header cache key collisionsRobin Jarry2023-07-161-13/+17
| | | | | | | | | | | | | | | | | | | | | | Sometimes, aerc lists completely random messages when opening a mailbox. It only happens when cache-headers=true. According to RFC 3501: > The combination of mailbox name, UIDVALIDITY, and UID must refer to > a single immutable message on that server forever. It turns out that several mailboxes may have the same UIDVALIDITY value and may contain messages that have the same UID. When that happens, aerc assumes that the headers for these messages are already cached and returns them whereas they are for messages from another mailbox. Add the mailbox name into the header cache key to avoid these confusing collisions. Fixes: 7aa71d334b27 ("imap: add option to cache headers") Link: https://datatracker.ietf.org/doc/html/rfc3501#section-2.3.1.1 Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Inwit <inwit@sindominio.net>
* imap: only call UidSort with sort criteriaKoni Marti2023-06-251-2/+3
| | | | | | | | | | | | | Only call UidSort with some sort criteria. If we call it without, some imap severs report it as an error. For example, Fastmail imap with the sort config in aerc.conf commented out reports: "[Fastmail] unexpected error: Missing Sort criteria" and cannot display the messages. Fixes: https://lists.sr.ht/~rjarry/aerc-devel/%3C5955665f-4d1a-4295-86bd-d1a5eabd0d6d%40milic.suse.cz%3E Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: add folder-mapKoni Marti2023-06-224-5/+27
| | | | | | | | | Add the folder-map functionality to the imap backend. If the folder-map config option is specified, the folder-map worker middleware is used. Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Signed-off-by: Robin Jarry <robin@jarry.cc>
* worker: add WorkerInteractor interfaceKoni Marti2023-06-224-3/+5
| | | | | | | | | | | | Add a WorkerInteractor interface. Avoid exposing any public fields in the types.Worker. This will set the stage to implement a middleware pattern for the workers, i.e. to map folder names between the ui and the backend. Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Signed-off-by: Robin Jarry <robin@jarry.cc>
* imap: implement cancellation of searching and fetchingTim Culverhouse2023-06-202-0/+26
| | | | | | | | | Check for cancelled contexts before and after performing headers or flag fetches and any directory searching. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: implement cancellation of opening dir and listing contentsTim Culverhouse2023-06-201-39/+72
| | | | | | | | | | | Check for a cancelled context when opening a directory, and before+after fetching directory contents/threads. Clean up the nesting of fetchDirectoryContents by using what we already know about server capabilities and using a switch statement. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
* logging: remove ultra verbose trace logsRobin Jarry2023-06-123-21/+2
| | | | | | | | | | | | | | | | | Every message exchanged between the UI and the worker(s) is logged at least twice with some obscure IDs and struct pointer names. When enabling trace logging, this floods the files for very little or no benefit and makes the meaningful logging message hard to catch. Also, other messages tend to flood the output for no specific reason. These are most of the time leftovers from the development process and are not useful for tracking potential issues. Remove these. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Inwit <inwit@sindominio.net>
* imap: use named loggerRobin Jarry2023-06-129-48/+47
| | | | | | | | Use the worker's logging functions to have all imap related messages prefixed by the account name. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Inwit <inwit@sindominio.net>
* headers: enable partial header fetchingTim Culverhouse2023-05-164-4/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | Enable partial header fetching by creating config values for headers to specifically include, or specifically exclude. The References field will always be fetched, regardless of the include list. Envelope data is always fetched, but is not shown with :toggle-headers, since it isn't in the RFC822 struct unless explicitly included in the list. Partial headers can break the cache on changes. Update the cache tag key to include the state of the partially-fetched headers. Partial header fetching can have a significant performance increase for IMAP, and for all backends a resource improvement. Some data to support this is below. Gathered by opening aerc, selecting a mailbox with approximately 800 messages and scrolling to the end. Received measured with nethogs, RAM from btop Received | RAM ------------------------------------- All Headers | 9,656 kb | 103 MB Minimum Headers | 896 kb | 36 MB Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Moritz Poldrack <moritz@poldrack.dev> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: handle the NonExistent attributeKoni Marti2023-05-161-1/+4
| | | | | | | | | | | | | | | | | | Treat the "\NonExistent" attribute similar to the "\NoSelect" one. Only list folders without the "\NonExistent" or "\NoSelect" attribute. According to RFC 9501, section 7.3.1, the "\NonExistent" attribute implies "\NoSelect". When using the LIST-STATUS extension, some servers return a "\NonExistent" flag instead of the "\NoSelect" one. We only check for the "\NoSelect" attribute, and hence, a "\NonExistent" folder will appear in the directory list and raise an error when being selected. This occurs, e.g., for gmail accounts with the "[Gmail]" folder. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: use delimiter from serverMoritz Poldrack2023-05-162-5/+24
| | | | | | | | | To accommodate servers that use a delimiter other than "/" ("." being a common alternative), the delimiter is fetched from the server when connecting. Signed-off-by: Moritz Poldrack <git@moritz.sh> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: avoid error log when pruning cache entriesRobin Jarry2023-04-271-2/+4
| | | | | | | | | | | | | | Avoid such errors in the logs: ERROR cache.go:187: cannot clean database 0: unexpected EOF The cache now contains a tag mapped to a special key. This is not a gob serialized cached header. Ignore it when pruning old cache entries. Fixes: 6ea0f18635a8 ("imap: clear cache on tag mismatch") Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
* imap: add size field to cache structKoni Marti2023-04-261-1/+4
| | | | | | | Add size field to the cache struct and increment cache tag. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: clear cache on tag mismatchKoni Marti2023-04-261-2/+41
| | | | | | | | | Tag the imap cache and clear it when the cache tag does not match the current tag in the code. This ensures that the cache structure is always consitent with our code base. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* messageinfo: report message sizesKoni Marti2023-04-261-0/+2
| | | | | | | Report sizes of the message across all backends. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* search: handle headers in search/filter queryJulian Marcos2023-04-221-1/+7
| | | | | | | | | Handle headers in the search and filter commands, for searching and filtering based on the Headers specified by the -H parameter, the syntax for the -H parameter should be `Header: Key`. Signed-off-by: Julian Marcos <jmjl@tilde.green> Acked-by: Robin Jarry<robin@jarry.cc>
* directory: add IANA mailbox rolesTim Culverhouse2023-04-221-3/+18
| | | | | | | | | | | Add IANA registered mailbox role, and a custom aerc role "query". This will be used in subsequent commits which add the Role field to templates, allowing users to style mailbox by IANA role, or style notmuch queries differently than maildir dirs when using the notmuch worker + maildir option. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry<robin@jarry.cc>
* directory: use directory to store rue countsTim Culverhouse2023-04-222-10/+2
| | | | | | | | | | | | Store the Directory RUE counts on the Directory data model. Use DirectoryInfo messages to update the Directory model. Access Directories via the dirlist instead of via the msgstore. Remove unused fields on DirectoryInfo, all backends now give accurate counts. Move refetch logic into dirlist Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry<robin@jarry.cc>
* imap: update directory on flag opsTim Culverhouse2023-04-221-0/+3
| | | | | | | | | | All other backends automatically update directory counts by sending a directory info when a flag operation is performed. Unify the imap backend to this model by posting a CheckMail action, which requests an updated status from the server and posts a DirectoryInfo message Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry<robin@jarry.cc>
* directory: remove attributes fieldTim Culverhouse2023-04-221-2/+1
| | | | | | | Remove the unused field Attributes Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
* capabilities: report capabilities from backendTim Culverhouse2023-04-223-2/+4
| | | | | | | | | | | | | Use the Backend interface to report Backend capabilities. Previously, these were reported via a DirectoryInfo message, however they have nothing to do with a directory and should be reported directly by the backend. Add Capabilities method to Backend interface, satisfy this in each backend, and use it on the UI side. Remove Caps field from DirectoryInfo Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry<robin@jarry.cc>
* imap: properly handle mailbox status updatesTim Culverhouse2023-04-222-15/+11
| | | | | | | | | | | | | | | | | | | | Mailbox status updates received from the IMAP server do not come with the information being sent to the UI. Use the update signal to instead trigger a check-mail of the directory the status was sent for. The status update comes with the following data: - Messages in the mailbox - Recent messages in the mailbox - Sequence number of the first Unseen message - Flags in the mailbox The data we actually we want to send to the UI: - Messages in the mailbox - Recent messages in the mailbox - Unseen messages in the mailbox Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
* msgstore: fetch message list based on OpenDirectory msgTim Culverhouse2023-04-222-2/+0
| | | | | | | | | | | | | | | Fetching the message list is done in a convoluted way. The UI receives a DirectoryInfo message, which creates a message store. It then receives a second DirectoryInfo (an oddity from the IMAP worker), and this DirectoryInfo is passed to the message store which then requests a fetch of the message list via store.Sort. Use the OpenDirectory done response to tell the message store to fetch messages. This makes the code easier to follow, and does not rely on quirks from the IMAP worker. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
* parse msg-id lists more liberallyNguyễn Gia Phong2023-03-262-8/+4
| | | | | | | | | | | | | | | Some user agents deliberately generate non-standard message identifier lists in In-Reply-To and References headers. Instead of failing silently, aerc now falls back to a desperate parser scavaging whatever looking like <id-left@id-right>. As the more liberal parser being substituted with, References header are now stored for IMAP not only when there's a parsing error. Fixes: 31d2f5be3cec ("message-info: add explicit References field") Signed-off-by: Nguyễn Gia Phong <mcsinyx@disroot.org> Acked-by: Robin Jarry <robin@jarry.cc>
* imap,smtp: cache and cycle XOAUTH2 refresh tokenDean2023-01-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Normally for emails with xoauth2, the help page says to pass the refresh token as the password. When the refresh token expires, aerc can't fetch the access token, and you must get a new refresh token from the external script. This patch implements a cycle of refresh tokens so you only need to use an external script to fetch the refresh token once. Once you have fetched the initial refresh token (with an external script like mutt_xoauth2.py or https://github.com/gaoDean/oauthRefreshToken), that refresh token is inputted as the password to aerc (as normal) to fetch the access token. Before this patch aerc used to only fetch the access token, but now it fetches that and a new refresh token, which it caches in $XDG_CONFIG_HOME/aerc/<account>-xoauth2.token. In the next opening of aerc, aerc will pull the refresh token from the cache, and use it instead of the inputted refresh token from the password. If it is not present in the cache, the refresh token is taken from the password as usual. Signed-off-by: Dean <gao.dean@hotmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* lint: add missing panic handlers in goroutinesRobin Jarry2023-01-063-0/+5
| | | | | | | | These issues were all reported by the new custom analyzer introduced in previous commit. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
* model: change flags array to bitmaskRobin Jarry2023-01-043-11/+10
| | | | | | | Using a list of integers is not optimal. Use a bit mask instead. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
* imap: use list-status for check-mailTim Culverhouse2022-12-021-24/+43
| | | | | | | | | Use list-status to perform check-mail commands, if it is available. This provides a significant performance benefit by only requiring one IMAP command vs one command for each mailbox. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: use list-status for list-directories if availableTim Culverhouse2022-12-021-8/+48
| | | | | | | | | Use the LIST-STATUS extension when listing directories. This enables the UI to show message counts for every mailbox, in a similar behavior to the maildir and notmuch backends. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
* imap: check for list-status capabilityTim Culverhouse2022-12-021-3/+16
| | | | | | | | | | | | | Check for LIST-STATUS capability on IMAP servers. This will be used in subsequent commits for improved check-mail performance. The LIST-STATUS command allows the LIST command to also return STATUS responses, which include message counts. Upgrade go-imap to latest release. Add go-imap-liststatus extension. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>