[PATCH] maildir: Support directories without cur/new dirs
Export this patch
From: 3nprob <3nprob@3nprob>
Directories without mail can still contain subdirectories
Could you give a more detailed explanation of what your patch does and
why is it useful? Also, please author commits with your name.
git config --global user.name "Foo Bar"
git config --global user.email "foo@bar.org"
See these links for reference.
https://git-send-email.io/
https://doc.dpdk.org/guides/contributing/patches.html#sending-patches
---
worker/maildir/container.go | 20 +++++++++++++++++
worker/maildir/worker.go | 44 +++++++++++++++++++++++++++ ----------
2 files changed, 53 insertions(+), 11 deletions(-)
diff --git a/worker/maildir/container.go b/worker/maildir/container.go
index 14815c9..be35c67 100644
--- a/worker/maildir/container.go
+++ b/worker/maildir/container.go
@@ -76,6 +76,13 @@ func (c *Container) ListFolders() ([]string, error) {
// messages into cur, and registers the new keys in the UIDStore.
func (c *Container) OpenDirectory(name string) (maildir.Dir, error) {
dir := c.Dir(name)
+ // exists, err := pathExists(filepath.Join(name, "new"))
+ // if err != nil {
+ // return dir, err
+ // }
+ // if !exists {
+ // return dir, nil
+ // }
This should be uncommented or removed from the patch.
keys, err := dir.Unseen()
if err != nil {
return dir, err
@@ -95,6 +102,9 @@ func (c *Container) Dir(name string) maildir.Dir {
func (c *Container) UIDs(d maildir.Dir) ([]uint32, error) {
keys, err := d.Keys()
if err != nil {
+ if os.IsNotExist(err) {
+ return make([]uint32, 0), nil
+ }
return nil, fmt.Errorf("could not get keys for %s: %v", d, err)
}
sort.Strings(keys)
@@ -154,3 +164,13 @@ func (c *Container) copyMessage(
_, err := src.Copy(dest, key)
return err
}
+
+ func pathExists(path string) (bool, error) {
+ if _, err := os.Stat(path); err != nil {
+ if os.IsNotExist(err) {
+ return false, nil
+ }
+ return false, err
+ }
+ return true, nil
+ }
diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go
index 87ebc97..080eb25 100644
--- a/worker/maildir/worker.go
+++ b/worker/maildir/worker.go
@@ -140,7 +140,9 @@ func (w *Worker) getDirectoryInfo(name string) *models.DirectoryInfo {
recent, err := dir.UnseenCount()
if err != nil {
- w.worker.Logger.Printf("could not get unseen count: %v", err)
+ if !os.IsNotExist(err) {
+ w.worker.Logger.Printf("could not get unseen count: %v", err)
+ }
}
dirInfo.Recent = recent
@@ -274,29 +276,41 @@ func (w *Worker) handleOpenDirectory(msg *types.OpenDirectory) error {
// open the directory
dir, err := w.c.OpenDirectory(msg.Directory)
+ exists := true
if err != nil {
- return err
+ if !os.IsNotExist(err) {
+ return fmt.Errorf("could not open directory: %v", err)
+ }
+ exists = false
}
// remove existing watch path
if w.selected != nil {
prevDir := filepath.Join(string(*w.selected), "new")
- if err := w.watcher.Remove(prevDir); err != nil {
- return fmt.Errorf("could not unwatch previous directory: %v", err)
+ prevExists, err := pathExists(prevDir)
+ if err != nil {
+ return fmt.Errorf("could not stat previous directory: %v", err)
+ }
+ if prevExists {
+ if err = w.watcher.Remove(prevDir); err != nil {
+ return fmt.Errorf("could not unwatch previous directory: %v", err)
+ }
}
}
w.selected = &dir
w.selectedName = msg.Directory
- // add watch path
- newDir := filepath.Join(string(*w.selected), "new")
- if err := w.watcher.Add(newDir); err != nil {
- return fmt.Errorf("could not add watch to directory: %v", err)
- }
+ if exists {
+ // add watch path
+ newDir := filepath.Join(string(*w.selected), "new")
+ if err := w.watcher.Add(newDir); err != nil {
+ return fmt.Errorf("could not add watch to directory: %v", err)
+ }
- if err := dir.Clean(); err != nil {
- return fmt.Errorf("could not clean directory: %v", err)
+ if err := dir.Clean(); err != nil {
+ return fmt.Errorf("could not clean directory: %v", err)
+ }
Please rebase your patch against the latest master. I have changed this
code recently:
https://git.sr.ht/~rjarry/aerc/commit/f4d3c8fc77f9
Thanks!
}
info := &types.DirectoryInfo{
@@ -310,6 +324,14 @@ func (w *Worker) handleFetchDirectoryContents(
msg *types.FetchDirectoryContents) error {
uids, err := w.c.UIDs(*w.selected)
if err != nil {
+ if os.IsNotExist(err) {
+ uids = make([]uint32, 0)
+ w.worker.PostMessage(&types.DirectoryContents{
+ Message: types.RespondTo(msg),
+ Uids: uids,
+ }, nil)
+ return nil
+ }
w.worker.Logger.Printf("error scanning uids: %v", err)
return err
}
--
2.31.1
Hello,
This project has been forked a while ago. In the future, could you
please send patches to the new mailing list as well?
~rjarry/aerc-devel@lists.sr.ht
See this thread for more details:
https://lists.sr.ht/~sircmpwn/aerc/%3CCFBVJ3G1Y4YB.ZI6C02D0MS0S%40dabtop%3E
, Dec 08, 2021 at 16:12: