From 1a129a21239abf188d2ea78b46e832e6266739b7 Mon Sep 17 00:00:00 2001 From: Bence Ferdinandy Date: Fri, 26 Jan 2024 21:42:30 +0100 Subject: 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 --- worker/maildir/container.go | 8 ++++++-- worker/maildir/worker.go | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'worker') 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 { -- cgit