From ea10b329ddd18573fdb066a1a3293c839d839fbd Mon Sep 17 00:00:00 2001 From: Julian Pidancet Date: Wed, 26 Oct 2022 22:29:03 +0200 Subject: maildir: replace ListFolder method with FolderMap Replace ListFolder with a new method that returns a map indexed by folder names instead of a list of folder names. A map is simpler to use and more efficient in case we only want to check the presence of a specific folder in the Maildir store. Signed-off-by: Julian Pidancet Acked-by: Robin Jarry Acked-by: Tim Culverhouse --- worker/lib/maildir.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'worker/lib/maildir.go') diff --git a/worker/lib/maildir.go b/worker/lib/maildir.go index f6199f9c..f3fe9415 100644 --- a/worker/lib/maildir.go +++ b/worker/lib/maildir.go @@ -34,12 +34,11 @@ func NewMaildirStore(root string, maildirpp bool) (*MaildirStore, error) { }, nil } -// ListFolders returns a list of maildir folders in the container -func (s *MaildirStore) ListFolders() ([]string, error) { - folders := []string{} +func (s *MaildirStore) FolderMap() (map[string]maildir.Dir, error) { + folders := make(map[string]maildir.Dir) if s.maildirpp { // In Maildir++ layout, INBOX is the root folder - folders = append(folders, "INBOX") + folders["INBOX"] = maildir.Dir(s.root) } err := filepath.Walk(s.root, func(path string, info os.FileInfo, err error) error { if err != nil { @@ -81,14 +80,14 @@ func (s *MaildirStore) ListFolders() ([]string, error) { } dirPath = strings.TrimPrefix(dirPath, ".") dirPath = strings.ReplaceAll(dirPath, ".", "/") - folders = append(folders, dirPath) + folders[dirPath] = maildir.Dir(path) // Since all mailboxes are stored in a single directory, don't // recurse into subdirectories return filepath.SkipDir } - folders = append(folders, dirPath) + folders[dirPath] = maildir.Dir(path) return nil }) return folders, err -- cgit