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 /commands/compose/send.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 'commands/compose/send.go')
-rw-r--r-- | commands/compose/send.go | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/commands/compose/send.go b/commands/compose/send.go index 1047ebad..91fd42bd 100644 --- a/commands/compose/send.go +++ b/commands/compose/send.go @@ -228,8 +228,7 @@ func send(composer *app.Composer, ctx sendCtx, } if ctx.copyto != "" && ctx.scheme != "jmap" { app.PushStatus("Copying to "+ctx.copyto, 10*time.Second) - errch := copyToSent(composer.Worker(), ctx.copyto, - copyBuf.Len(), ©Buf) + errch := copyToSent(ctx.copyto, copyBuf.Len(), ©Buf) err = <-errch if err != nil { errmsg := fmt.Sprintf( @@ -558,23 +557,32 @@ func newJmapSender( return writer, err } -func copyToSent(worker *types.Worker, dest string, - n int, msg io.Reader, -) <-chan error { - errCh := make(chan error) - worker.PostAction(&types.AppendMessage{ - Destination: dest, - Flags: models.SeenFlag, - Date: time.Now(), - Reader: msg, - Length: n, - }, func(msg types.WorkerMessage) { - switch msg := msg.(type) { - case *types.Done: - errCh <- nil - case *types.Error: - errCh <- msg.Error - } - }) +func copyToSent(dest string, n int, msg io.Reader) <-chan error { + errCh := make(chan error, 1) + acct := app.SelectedAccount() + if acct == nil { + errCh <- errors.New("No account selected") + return errCh + } + store := acct.Store() + if store == nil { + errCh <- errors.New("No message store selected") + return errCh + } + store.Append( + dest, + models.SeenFlag, + time.Now(), + msg, + n, + func(msg types.WorkerMessage) { + switch msg := msg.(type) { + case *types.Done: + errCh <- nil + case *types.Error: + errCh <- msg.Error + } + }, + ) return errCh } |