Allow maildir subdirectories
This commit is contained in:
parent
52eb38ae5d
commit
9a520c4098
1 changed files with 27 additions and 11 deletions
|
@ -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)
|
||||
folders := []string{}
|
||||
err := filepath.Walk(c.dir, func(path string, info os.FileInfo, err error) error {
|
||||
if !info.IsDir() {
|
||||
return 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 nil, fmt.Errorf("error reading folders: %v", err)
|
||||
return err
|
||||
}
|
||||
dirnames := []string{}
|
||||
for _, f := range files {
|
||||
if f.IsDir() {
|
||||
dirnames = append(dirnames, f.Name())
|
||||
|
||||
// Skip the parent directory
|
||||
if dirPath == "." {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return dirnames, nil
|
||||
|
||||
folders = append(folders, dirPath)
|
||||
return nil
|
||||
})
|
||||
return folders, err
|
||||
}
|
||||
|
||||
// OpenDirectory opens an existing maildir in the container by name, moves new
|
||||
|
|
Loading…
Reference in a new issue