aboutsummaryrefslogtreecommitdiffstats
path: root/worker/maildir
diff options
context:
space:
mode:
authorGrégoire Delattre <gregoire.delattre@gmail.com>2020-05-05 10:16:02 +0200
committerReto Brunner <reto@labrat.space>2020-05-05 19:18:26 +0200
commit9a520c4098204b06b09f8d31f7ba126837d45a28 (patch)
tree0569537f67d12747ec898df6d0e5216552bb8832 /worker/maildir
parent52eb38ae5d8e56e96db4bd7ee31159efd4c5d241 (diff)
downloadaerc-9a520c4098204b06b09f8d31f7ba126837d45a28.tar.gz
Allow maildir subdirectories
Diffstat (limited to 'worker/maildir')
-rw-r--r--worker/maildir/container.go38
1 files changed, 27 insertions, 11 deletions
diff --git a/worker/maildir/container.go b/worker/maildir/container.go
index 85e892a8..cd9a4471 100644
--- a/worker/maildir/container.go
+++ b/worker/maildir/container.go
@@ -2,8 +2,8 @@ package maildir
import (
"fmt"
- "io/ioutil"
"log"
+ "os"
"path/filepath"
"sort"
@@ -28,17 +28,33 @@ func NewContainer(dir string, l *log.Logger) *Container {
// ListFolders returns a list of maildir folders in the container
func (c *Container) ListFolders() ([]string, error) {
- files, err := ioutil.ReadDir(c.dir)
- if err != nil {
- return nil, fmt.Errorf("error reading folders: %v", err)
- }
- dirnames := []string{}
- for _, f := range files {
- if f.IsDir() {
- dirnames = append(dirnames, f.Name())
+ folders := []string{}
+ err := filepath.Walk(c.dir, func(path string, info os.FileInfo, err error) error {
+ if !info.IsDir() {
+ return nil
}
- }
- return dirnames, nil
+
+ // Skip maildir's default directories
+ n := info.Name()
+ if n == "new" || n == "tmp" || n == "cur" {
+ return filepath.SkipDir
+ }
+
+ // Get the relative path from the parent directory
+ dirPath, err := filepath.Rel(c.dir, path)
+ if err != nil {
+ return err
+ }
+
+ // Skip the parent directory
+ if dirPath == "." {
+ return nil
+ }
+
+ folders = append(folders, dirPath)
+ return nil
+ })
+ return folders, err
}
// OpenDirectory opens an existing maildir in the container by name, moves new