From 150aa0f498b9780a40fdab815552c4c4230b5178 Mon Sep 17 00:00:00 2001 From: Julian Pidancet Date: Mon, 3 Oct 2022 19:16:26 +0200 Subject: [PATCH] maildir: hide invalid folders The maildir worker currently populates the list of mail folders by listing all the filesystem subdirectories in the maildir directory. Although there's no official specification for maildir subfolders, they should all have cur/ new/ and tmp/ subdirectories to be valid. This patch prevents directories that don't have those subdirectories present on the filesystem from appearing in the account folder list. This is useful for example to prevent ".notmuch" and ".notmuch/xapian" from showing up in the folder list if using notmuch to index emails while using aerc's maildir backend. Signed-off-by: Julian Pidancet Acked-by: Tim Culverhouse --- worker/maildir/container.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/worker/maildir/container.go b/worker/maildir/container.go index 52bbf83..156b0af 100644 --- a/worker/maildir/container.go +++ b/worker/maildir/container.go @@ -78,6 +78,13 @@ func (c *Container) ListFolders() ([]string, error) { return nil } + // Drop dirs that lack {new,tmp,cur} subdirs + for _, sub := range []string{"new", "tmp", "cur"} { + if _, err := os.Stat(filepath.Join(path, sub)); os.IsNotExist(err) { + return filepath.SkipDir + } + } + if c.maildirpp { // In Maildir++ layout, mailboxes are stored in a single directory // and prefixed with a dot, and subfolders are separated by dots.