archive-mail

Maintains maildir archives synced with current maildirs

git clone https://git.8pit.net/archive-mail.git

 1package main
 2
 3import (
 4	"errors"
 5	"os"
 6	"path/filepath"
 7)
 8
 9func isMaildirFn(name string) bool {
10	return name == "new" || name == "cur" || name == "tmp"
11}
12
13func isValidMaildir(dir string) bool {
14	for _, fn := range []string{"new", "cur", "tmp"} {
15		_, err := os.Stat(filepath.Join(dir, fn))
16		if errors.Is(err, os.ErrNotExist) {
17			return false
18		}
19	}
20
21	return true
22}
23
24func getDir(path string) string {
25	dir := filepath.Base(filepath.Dir(path))
26	if !isMaildirFn(dir) {
27		panic("unexpected non-maildir folder")
28	}
29
30	return dir
31}