aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--worker/lib/maildir.go11
-rw-r--r--worker/maildir/worker.go10
2 files changed, 10 insertions, 11 deletions
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
diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go
index d2bb6464..a9c45ce8 100644
--- a/worker/maildir/worker.go
+++ b/worker/maildir/worker.go
@@ -329,12 +329,12 @@ func (w *Worker) handleListDirectories(msg *types.ListDirectories) error {
if w.c == nil {
return errors.New("Incorrect maildir directory")
}
- dirs, err := w.c.Store.ListFolders()
+ dirs, err := w.c.Store.FolderMap()
if err != nil {
logging.Errorf("failed listing directories: %v", err)
return err
}
- for _, name := range dirs {
+ for name := range dirs {
w.worker.PostMessage(&types.Directory{
Message: types.RespondTo(msg),
Dir: &models.Directory{
@@ -733,12 +733,12 @@ func (w *Worker) handleCheckMail(msg *types.CheckMail) {
if err != nil {
w.err(msg, fmt.Errorf("checkmail: error running command: %w", err))
} else {
- dirs, err := w.c.Store.ListFolders()
+ dirs, err := w.c.Store.FolderMap()
if err != nil {
w.err(msg, fmt.Errorf("failed listing directories: %w", err))
}
- for _, name := range dirs {
- err := w.c.SyncNewMail(w.c.Store.Dir(name))
+ for name, dir := range dirs {
+ err := w.c.SyncNewMail(dir)
if err != nil {
w.err(msg, fmt.Errorf("could not sync new mail: %w", err))
}