aboutsummaryrefslogtreecommitdiffstats
path: root/worker/notmuch
diff options
context:
space:
mode:
Diffstat (limited to 'worker/notmuch')
-rw-r--r--worker/notmuch/message.go30
-rw-r--r--worker/notmuch/notmuch.go24
-rw-r--r--worker/notmuch/search.go15
3 files changed, 36 insertions, 33 deletions
diff --git a/worker/notmuch/message.go b/worker/notmuch/message.go
index 2beda4d6..849363f1 100644
--- a/worker/notmuch/message.go
+++ b/worker/notmuch/message.go
@@ -78,21 +78,13 @@ func (m *Message) NewBodyPartReader(requestedParts []int) (io.Reader, error) {
// Notmuch doesn't support all the flags, and for those this errors.
func (m *Message) SetFlag(flag models.Flags, enable bool) error {
// Translate the flag into a notmuch tag, ignoring no-op flags.
- var tag string
- switch flag {
- case models.SeenFlag:
- // Note: Inverted properly later
- tag = "unread"
- case models.AnsweredFlag:
- tag = "replied"
- case models.FlaggedFlag:
- tag = "flagged"
- default:
+ tag, ok := flagToTag[flag]
+ if !ok {
return fmt.Errorf("Notmuch doesn't support flag %v", flag)
}
// Get the current state of the flag.
- // Note that notmuch handles models.SeenFlag in an inverted sense.
+ // Note that notmuch handles some flags in an inverted sense
oldState := false
tags, err := m.Tags()
if err != nil {
@@ -105,9 +97,7 @@ func (m *Message) SetFlag(flag models.Flags, enable bool) error {
}
}
- if flag == models.SeenFlag {
- // Invert the operation since notmuch uses unread tags instead
- // of seen tags
+ if flagToInvert[flag] {
enable = !enable
}
@@ -147,13 +137,11 @@ func (m *Message) ModelFlags() (models.Flags, error) {
return 0, err
}
for _, tag := range tags {
- switch tag {
- case "replied":
- flags |= models.AnsweredFlag
- case "flagged":
- flags |= models.FlaggedFlag
- case "unread":
- flags &^= models.SeenFlag
+ flag := tagToFlag[tag]
+ if flagToInvert[flag] {
+ flags &^= flag
+ } else {
+ flags |= flag
}
}
return flags, nil
diff --git a/worker/notmuch/notmuch.go b/worker/notmuch/notmuch.go
new file mode 100644
index 00000000..5610cac0
--- /dev/null
+++ b/worker/notmuch/notmuch.go
@@ -0,0 +1,24 @@
+//go:build notmuch
+// +build notmuch
+
+package notmuch
+
+import "git.sr.ht/~rjarry/aerc/models"
+
+var tagToFlag = map[string]models.Flags{
+ "unread": models.SeenFlag,
+ "replied": models.AnsweredFlag,
+ "flagged": models.FlaggedFlag,
+}
+
+var flagToTag = map[models.Flags]string{
+ models.SeenFlag: "unread",
+ models.AnsweredFlag: "replied",
+ models.FlaggedFlag: "flagged",
+}
+
+var flagToInvert = map[models.Flags]bool{
+ models.SeenFlag: true,
+ models.AnsweredFlag: false,
+ models.FlaggedFlag: false,
+}
diff --git a/worker/notmuch/search.go b/worker/notmuch/search.go
index b3592d41..36d4c2df 100644
--- a/worker/notmuch/search.go
+++ b/worker/notmuch/search.go
@@ -67,7 +67,7 @@ func translate(crit *types.SearchCriteria) string {
}
// flags
- for _, f := range []models.Flags{models.SeenFlag, models.AnsweredFlag, models.FlaggedFlag} {
+ for f := range flagToTag {
if crit.WithFlags.Has(f) {
base.and(getParsedFlag(f, false))
}
@@ -100,17 +100,8 @@ func translate(crit *types.SearchCriteria) string {
}
func getParsedFlag(flag models.Flags, inverse bool) string {
- name := ""
- switch flag {
- case models.AnsweredFlag:
- name = "tag:replied"
- case models.SeenFlag:
- name = "tag:unread"
- inverse = !inverse
- case models.FlaggedFlag:
- name = "tag:flagged"
- }
- if inverse {
+ name := "tag:" + flagToTag[flag]
+ if flagToInvert[flag] {
name = "not " + name
}
return name