diff options
author | Bence Ferdinandy <bence@ferdinandy.com> | 2024-01-26 21:42:30 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-01-26 22:14:39 +0100 |
commit | 1a129a21239abf188d2ea78b46e832e6266739b7 (patch) | |
tree | 6a90b8dcb2fb6dcb464183a2891aafb9228799ef /worker/maildir | |
parent | 161768eb7371b4844dfdfac56ce090a0f0091ff1 (diff) | |
download | aerc-1a129a21239abf188d2ea78b46e832e6266739b7.tar.gz |
maildir: show valid messages even if there are errors
When go-maildir parses a folder and finds an error, it will still return
the valid keys it has found along with the error. Instead of returning
an empty list of UIDs log an error and proceed with the valid uids found
by go-maildir. When opening a folder with invalid files, show an error
message to the user.
References: https://todo.sr.ht/~rjarry/aerc/215
Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
Diffstat (limited to 'worker/maildir')
-rw-r--r-- | worker/maildir/container.go | 8 | ||||
-rw-r--r-- | worker/maildir/worker.go | 10 |
2 files changed, 14 insertions, 4 deletions
diff --git a/worker/maildir/container.go b/worker/maildir/container.go index 946de74d..23c96617 100644 --- a/worker/maildir/container.go +++ b/worker/maildir/container.go @@ -9,6 +9,7 @@ import ( "github.com/emersion/go-maildir" "git.sr.ht/~rjarry/aerc/lib/uidstore" + "git.sr.ht/~rjarry/aerc/log" "git.sr.ht/~rjarry/aerc/worker/lib" ) @@ -69,15 +70,18 @@ func (c *Container) ClearRecentFlag(uid uint32) { // UIDs fetches the unique message identifiers for the maildir func (c *Container) UIDs(d maildir.Dir) ([]uint32, error) { keys, err := d.Keys() - if err != nil { + if err != nil && len(keys) == 0 { return nil, fmt.Errorf("could not get keys for %s: %w", d, err) } + if err != nil { + log.Errorf("could not get all keys for %s: %s", d, err.Error()) + } sort.Strings(keys) var uids []uint32 for _, key := range keys { uids = append(uids, c.uids.GetOrInsert(key)) } - return uids, nil + return uids, err } // Message returns a Message struct for the given UID and maildir diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go index 5ca648c4..643ab8a9 100644 --- a/worker/maildir/worker.go +++ b/worker/maildir/worker.go @@ -236,7 +236,7 @@ func (w *Worker) getDirectoryInfo(name string) *models.DirectoryInfo { } uids, err := w.c.UIDs(dir) - if err != nil { + if err != nil && len(uids) == 0 { w.worker.Errorf("could not get uids: %v", err) return dirInfo } @@ -468,10 +468,16 @@ func (w *Worker) handleFetchDirectoryContents( } } else { uids, err = w.c.UIDs(*w.selected) - if err != nil { + if err != nil && len(uids) == 0 { w.worker.Errorf("failed scanning uids: %v", err) return err } + + if err != nil { + w.worker.PostMessage(&types.Error{ + Error: fmt.Errorf("could not get all uids for %s: %w", *w.selected, err), + }, nil) + } } sortedUids, err := w.sort(msg.Context, uids, msg.SortCriteria) if err != nil { |