From cee5d5a3f602e5db0ca3feb6e0754c1bb0059f36 Mon Sep 17 00:00:00 2001 From: Bence Ferdinandy Date: Wed, 10 Apr 2024 20:08:00 +0200 Subject: 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 Acked-by: Robin Jarry --- app/account.go | 10 ++++++++++ config/hooks.go | 1 + doc/aerc-config.5.scd | 10 ++++++++++ lib/hooks/tag-modified.go | 27 +++++++++++++++++++++++++++ lib/msgstore.go | 12 ++++++++++-- 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 lib/hooks/tag-modified.go 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* = __ + 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)) { -- cgit v1.2.3-54-g00ecf