aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models/models.go27
-rw-r--r--worker/imap/list.go21
-rw-r--r--worker/notmuch/worker.go2
3 files changed, 47 insertions, 3 deletions
diff --git a/models/models.go b/models/models.go
index a47ac24b..1b864341 100644
--- a/models/models.go
+++ b/models/models.go
@@ -36,6 +36,31 @@ func (f Flags) Has(flags Flags) bool {
return f&flags == flags
}
+type Role string
+
+var Roles = map[string]Role{
+ "all": AllRole,
+ "archive": ArchiveRole,
+ "drafts": DraftsRole,
+ "inbox": InboxRole,
+ "junk": JunkRole,
+ "sent": SentRole,
+ "trash": TrashRole,
+ "query": QueryRole,
+}
+
+const (
+ AllRole Role = "all"
+ ArchiveRole Role = "archive"
+ DraftsRole Role = "drafts"
+ InboxRole Role = "inbox"
+ JunkRole Role = "junk"
+ SentRole Role = "sent"
+ TrashRole Role = "trash"
+ // Custom aerc roles
+ QueryRole Role = "query"
+)
+
type Directory struct {
Name string
// Exists messages in the Directory
@@ -44,6 +69,8 @@ type Directory struct {
Recent int
// Unseen messages in the Directory
Unseen int
+ // IANA role
+ Role Role
}
type DirectoryInfo struct {
diff --git a/worker/imap/list.go b/worker/imap/list.go
index 657779e5..41924d86 100644
--- a/worker/imap/list.go
+++ b/worker/imap/list.go
@@ -1,6 +1,8 @@
package imap
import (
+ "strings"
+
"github.com/emersion/go-imap"
"git.sr.ht/~rjarry/aerc/log"
@@ -21,11 +23,24 @@ func (imapw *IMAPWorker) handleListDirectories(msg *types.ListDirectories) {
// no need to pass this to handlers if it can't be opened
continue
}
+ dir := &models.Directory{
+ Name: mbox.Name,
+ }
+ for _, attr := range mbox.Attributes {
+ attr = strings.TrimPrefix(attr, "\\")
+ attr = strings.ToLower(attr)
+ role, ok := models.Roles[attr]
+ if !ok {
+ continue
+ }
+ dir.Role = role
+ }
+ if mbox.Name == "INBOX" {
+ dir.Role = models.InboxRole
+ }
imapw.worker.PostMessage(&types.Directory{
Message: types.RespondTo(msg),
- Dir: &models.Directory{
- Name: mbox.Name,
- },
+ Dir: dir,
}, nil)
}
done <- nil
diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go
index b25a8786..6b1b64d9 100644
--- a/worker/notmuch/worker.go
+++ b/worker/notmuch/worker.go
@@ -259,6 +259,7 @@ func (w *worker) handleListDirectories(msg *types.ListDirectories) error {
Message: types.RespondTo(msg),
Dir: &models.Directory{
Name: name,
+ Role: models.QueryRole,
},
}, nil)
}
@@ -317,6 +318,7 @@ func (w *worker) handleOpenDirectory(msg *types.OpenDirectory) error {
Message: types.RespondTo(msg),
Dir: &models.Directory{
Name: q,
+ Role: models.QueryRole,
},
}, nil)
}