diff options
author | Jason Cox <me@jasoncarloscox.com> | 2023-10-29 17:40:47 -0400 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-11-02 11:59:39 +0100 |
commit | 31b50f24d51fd429f30e20fb42a5681149e5bfe7 (patch) | |
tree | 3698ffa2662a04655a042769a23d4a07ccebd4c4 /lib | |
parent | fb8e60c041d7b4a61e5862d6bce6fd3bd8fca000 (diff) | |
download | aerc-31b50f24d51fd429f30e20fb42a5681149e5bfe7.tar.gz |
hooks: add mail-deleted hook
The mail-deleted hook runs whenever a message is deleted from a folder.
Note that this means moving a message from one folder to another
triggers the mail-deleted hook.
Changelog-added: `mail-deleted` hook that triggers when a message is
removed/moved from a folder.
References: https://todo.sr.ht/~rjarry/aerc/136
Signed-off-by: Jason Cox <me@jasoncarloscox.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/hooks/mail-deleted.go | 23 | ||||
-rw-r--r-- | lib/msgstore.go | 10 |
2 files changed, 31 insertions, 2 deletions
diff --git a/lib/hooks/mail-deleted.go b/lib/hooks/mail-deleted.go new file mode 100644 index 00000000..e9f13105 --- /dev/null +++ b/lib/hooks/mail-deleted.go @@ -0,0 +1,23 @@ +package hooks + +import ( + "fmt" + + "git.sr.ht/~rjarry/aerc/config" +) + +type MailDeleted struct { + Account string + Folder string +} + +func (m *MailDeleted) Cmd() string { + return config.Hooks.MailDeleted +} + +func (m *MailDeleted) Env() []string { + return []string{ + fmt.Sprintf("AERC_ACCOUNT=%s", m.Account), + fmt.Sprintf("AERC_FOLDER=%s", m.Folder), + } +} diff --git a/lib/msgstore.go b/lib/msgstore.go index e54c2565..9c6b750d 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -68,6 +68,7 @@ type MessageStore struct { triggerNewEmail func(*models.MessageInfo) triggerDirectoryChange func() + triggerMailDeleted func() threadBuilderDebounce *time.Timer threadBuilderDelay time.Duration @@ -87,8 +88,8 @@ func NewMessageStore(worker *types.Worker, thread bool, clientThreads bool, clientThreadsDelay time.Duration, reverseOrder bool, reverseThreadOrder bool, sortThreadSiblings bool, triggerNewEmail func(*models.MessageInfo), - triggerDirectoryChange func(), onSelect func(*models.MessageInfo), - threadContext bool, + triggerDirectoryChange func(), triggerMailDeleted func(), + onSelect func(*models.MessageInfo), threadContext bool, ) *MessageStore { if !worker.Backend.Capabilities().Thread { clientThreads = true @@ -122,6 +123,7 @@ func NewMessageStore(worker *types.Worker, triggerNewEmail: triggerNewEmail, triggerDirectoryChange: triggerDirectoryChange, + triggerMailDeleted: triggerMailDeleted, threadBuilderDelay: clientThreadsDelay, @@ -580,6 +582,9 @@ func (store *MessageStore) Delete(uids []uint32, if _, ok := msg.(*types.Unsupported); ok { store.revertDeleted(uids) } + if _, ok := msg.(*types.Done); ok { + store.triggerMailDeleted() + } cb(msg) }) } @@ -629,6 +634,7 @@ func (store *MessageStore) Move(uids []uint32, dest string, createDest bool, store.revertDeleted(uids) cb(msg) case *types.Done: + store.triggerMailDeleted() cb(msg) } }) |