aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJason Cox <me@jasoncarloscox.com>2023-10-29 17:40:48 -0400
committerRobin Jarry <robin@jarry.cc>2023-11-02 11:59:39 +0100
commitfaa879f9a84d44f9b251410fc923a827a44df1a7 (patch)
tree91f0a718e58b88d41a9a2c0720389bfcc137516a /lib
parent31b50f24d51fd429f30e20fb42a5681149e5bfe7 (diff)
downloadaerc-faa879f9a84d44f9b251410fc923a827a44df1a7.tar.gz
hooks: add mail-added hook
The mail-added hook runs whenever a message is added to a folder. Note that the hook does not run when a new message is received (the mail-received hook already covers that) but instead runs whenever aerc itself adds a message to a folder, e.g. when moving or copying a message. Changelog-added: `mail-added` hook that triggers when a message is added to 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-added.go23
-rw-r--r--lib/msgstore.go30
2 files changed, 51 insertions, 2 deletions
diff --git a/lib/hooks/mail-added.go b/lib/hooks/mail-added.go
new file mode 100644
index 00000000..f146d010
--- /dev/null
+++ b/lib/hooks/mail-added.go
@@ -0,0 +1,23 @@
+package hooks
+
+import (
+ "fmt"
+
+ "git.sr.ht/~rjarry/aerc/config"
+)
+
+type MailAdded struct {
+ Account string
+ Folder string
+}
+
+func (m *MailAdded) Cmd() string {
+ return config.Hooks.MailAdded
+}
+
+func (m *MailAdded) 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 9c6b750d..cb81abef 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -69,6 +69,7 @@ type MessageStore struct {
triggerNewEmail func(*models.MessageInfo)
triggerDirectoryChange func()
triggerMailDeleted func()
+ triggerMailAdded func(string)
threadBuilderDebounce *time.Timer
threadBuilderDelay time.Duration
@@ -89,7 +90,8 @@ func NewMessageStore(worker *types.Worker,
reverseOrder bool, reverseThreadOrder bool, sortThreadSiblings bool,
triggerNewEmail func(*models.MessageInfo),
triggerDirectoryChange func(), triggerMailDeleted func(),
- onSelect func(*models.MessageInfo), threadContext bool,
+ triggerMailAdded func(string), onSelect func(*models.MessageInfo),
+ threadContext bool,
) *MessageStore {
if !worker.Backend.Capabilities().Thread {
clientThreads = true
@@ -124,6 +126,7 @@ func NewMessageStore(worker *types.Worker,
triggerNewEmail: triggerNewEmail,
triggerDirectoryChange: triggerDirectoryChange,
triggerMailDeleted: triggerMailDeleted,
+ triggerMailAdded: triggerMailAdded,
threadBuilderDelay: clientThreadsDelay,
@@ -608,7 +611,12 @@ func (store *MessageStore) Copy(uids []uint32, dest string, createDest bool,
store.worker.PostAction(&types.CopyMessages{
Destination: dest,
Uids: uids,
- }, cb)
+ }, func(msg types.WorkerMessage) {
+ if _, ok := msg.(*types.Done); ok {
+ store.triggerMailAdded(dest)
+ }
+ cb(msg)
+ })
}
func (store *MessageStore) Move(uids []uint32, dest string, createDest bool,
@@ -635,11 +643,29 @@ func (store *MessageStore) Move(uids []uint32, dest string, createDest bool,
cb(msg)
case *types.Done:
store.triggerMailDeleted()
+ store.triggerMailAdded(dest)
cb(msg)
}
})
}
+func (store *MessageStore) Append(dest string, flags models.Flags, date time.Time,
+ reader io.Reader, length int, cb func(msg types.WorkerMessage),
+) {
+ store.worker.PostAction(&types.AppendMessage{
+ Destination: dest,
+ Flags: flags,
+ Date: date,
+ Reader: reader,
+ Length: length,
+ }, func(msg types.WorkerMessage) {
+ if _, ok := msg.(*types.Done); ok {
+ store.triggerMailAdded(dest)
+ }
+ cb(msg)
+ })
+}
+
func (store *MessageStore) Flag(uids []uint32, flags models.Flags,
enable bool, cb func(msg types.WorkerMessage),
) {