aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBence Ferdinandy <bence@ferdinandy.com>2024-04-10 20:08:00 +0200
committerRobin Jarry <robin@jarry.cc>2024-04-14 11:50:39 +0200
commitcee5d5a3f602e5db0ca3feb6e0754c1bb0059f36 (patch)
treec380b0cb317a62d17b6ff4922fbc6c95486f3295
parentae3f7419ce1b6d4a81c4f240ff1073ba45f45b52 (diff)
downloadaerc-cee5d5a3f602e5db0ca3feb6e0754c1bb0059f36.tar.gz
aerc-cee5d5a3f602e5db0ca3feb6e0754c1bb0059f36.zip
hooks: add tag-modified
Add the tag-modified hook for notmuch and JMAP accounts. References: https://todo.sr.ht/~rjarry/aerc/136 Changelog-added: New `tag-modified` hook for notmuch and JMAP accounts. Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--app/account.go10
-rw-r--r--config/hooks.go1
-rw-r--r--doc/aerc-config.5.scd10
-rw-r--r--lib/hooks/tag-modified.go27
-rw-r--r--lib/msgstore.go12
5 files changed, 58 insertions, 2 deletions
diff --git a/app/account.go b/app/account.go
index 08ab6498..99739f01 100644
--- a/app/account.go
+++ b/app/account.go
@@ -282,6 +282,16 @@ func (acct *AccountView) newStore(name string) *lib.MessageStore {
msg := fmt.Sprintf("mail-added hook: %s", err)
PushError(msg)
}
+ }, func(add []string, remove []string) {
+ err := hooks.RunHook(&hooks.TagModified{
+ Account: acct.Name(),
+ Add: add,
+ Remove: remove,
+ })
+ if err != nil {
+ msg := fmt.Sprintf("tag-modified hook: %s", err)
+ PushError(msg)
+ }
},
acct.updateSplitView,
acct.dirlist.UiConfig(name).ThreadContext,
diff --git a/config/hooks.go b/config/hooks.go
index 4fc9482e..bd053e95 100644
--- a/config/hooks.go
+++ b/config/hooks.go
@@ -12,6 +12,7 @@ type HooksConfig struct {
MailDeleted string `ini:"mail-deleted"`
MailAdded string `ini:"mail-added"`
MailSent string `ini:"mail-sent"`
+ TagModified string `ini:"tag-modified"`
}
var Hooks HooksConfig
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index d457e0ab..3912b3da 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -1255,6 +1255,16 @@ They are configured in the *[hooks]* section of aerc.conf.
- *AERC_LIFETIME*
+*tag-modified* = _<command>_
+ Executed when notmuch tags are modified in a notmuch account. The list
+ of added and removed tags are passed as variables.
+
+ Variables:
+
+ - *AERC_ACCOUNT*
+ - *AERC_TAG_ADDED*
+ - *AERC_TAG_REMOVED*
+
# TEMPLATES
Template files are used to populate the body of an email. The *:compose*,
diff --git a/lib/hooks/tag-modified.go b/lib/hooks/tag-modified.go
new file mode 100644
index 00000000..44af9471
--- /dev/null
+++ b/lib/hooks/tag-modified.go
@@ -0,0 +1,27 @@
+package hooks
+
+import (
+ "fmt"
+
+ "git.sr.ht/~rjarry/aerc/config"
+)
+
+type TagModified struct {
+ Account string
+ Add []string
+ Remove []string
+}
+
+func (m *TagModified) Cmd() string {
+ return config.Hooks.TagModified
+}
+
+func (m *TagModified) Env() []string {
+ env := []string{
+ fmt.Sprintf("AERC_ACCOUNT=%s", m.Account),
+ fmt.Sprintf("AERC_TAG_ADDED=%v", m.Add),
+ fmt.Sprintf("AERC_TAG_REMOVED=%v", m.Remove),
+ }
+
+ return env
+}
diff --git a/lib/msgstore.go b/lib/msgstore.go
index d11d280e..a906d0cc 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -70,6 +70,7 @@ type MessageStore struct {
triggerDirectoryChange func()
triggerMailDeleted func()
triggerMailAdded func(string)
+ triggerTagModified func([]string, []string)
threadBuilderDebounce *time.Timer
threadBuilderDelay time.Duration
@@ -90,7 +91,8 @@ func NewMessageStore(worker *types.Worker,
reverseOrder bool, reverseThreadOrder bool, sortThreadSiblings bool,
triggerNewEmail func(*models.MessageInfo),
triggerDirectoryChange func(), triggerMailDeleted func(),
- triggerMailAdded func(string), onSelect func(*models.MessageInfo),
+ triggerMailAdded func(string), triggerTagModified func([]string, []string),
+ onSelect func(*models.MessageInfo),
threadContext bool,
) *MessageStore {
if !worker.Backend.Capabilities().Thread {
@@ -129,6 +131,7 @@ func NewMessageStore(worker *types.Worker,
triggerDirectoryChange: triggerDirectoryChange,
triggerMailDeleted: triggerMailDeleted,
triggerMailAdded: triggerMailAdded,
+ triggerTagModified: triggerTagModified,
threadBuilderDelay: clientThreadsDelay,
@@ -885,7 +888,12 @@ func (store *MessageStore) ModifyLabels(uids []uint32, add, remove []string,
Uids: uids,
Add: add,
Remove: remove,
- }, cb)
+ }, func(msg types.WorkerMessage) {
+ if _, ok := msg.(*types.Done); ok {
+ store.triggerTagModified(add, remove)
+ }
+ cb(msg)
+ })
}
func (store *MessageStore) Sort(criteria []*types.SortCriterion, cb func(types.WorkerMessage)) {