diff options
author | Jason Cox <me@jasoncarloscox.com> | 2023-10-29 17:40:48 -0400 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-11-02 11:59:39 +0100 |
commit | faa879f9a84d44f9b251410fc923a827a44df1a7 (patch) | |
tree | 91f0a718e58b88d41a9a2c0720389bfcc137516a /lib/msgstore.go | |
parent | 31b50f24d51fd429f30e20fb42a5681149e5bfe7 (diff) | |
download | aerc-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/msgstore.go')
-rw-r--r-- | lib/msgstore.go | 30 |
1 files changed, 28 insertions, 2 deletions
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), ) { |