aboutsummaryrefslogtreecommitdiffstats
path: root/commands/account/import-mbox.go
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 /commands/account/import-mbox.go
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 'commands/account/import-mbox.go')
-rw-r--r--commands/account/import-mbox.go44
1 files changed, 22 insertions, 22 deletions
diff --git a/commands/account/import-mbox.go b/commands/account/import-mbox.go
index 774dfa8f..7aa393b6 100644
--- a/commands/account/import-mbox.go
+++ b/commands/account/import-mbox.go
@@ -65,7 +65,6 @@ func (i ImportMbox) Execute(args []string) error {
app.PushError(err.Error())
return
}
- worker := acct.Worker()
var appended uint32
for i, m := range messages {
@@ -79,27 +78,28 @@ func (i ImportMbox) Execute(args []string) error {
break
}
nbytes, _ := io.Copy(&buf, r)
- worker.PostAction(&types.AppendMessage{
- Destination: folder,
- Flags: models.SeenFlag,
- Date: time.Now(),
- Reader: &buf,
- Length: int(nbytes),
- }, func(msg types.WorkerMessage) {
- switch msg := msg.(type) {
- case *types.Unsupported:
- errMsg := fmt.Sprintf("%s: AppendMessage is unsupported", args[0])
- log.Errorf(errMsg)
- app.PushError(errMsg)
- return
- case *types.Error:
- log.Errorf("AppendMessage failed: %v", msg.Error)
- done <- false
- case *types.Done:
- atomic.AddUint32(&appended, 1)
- done <- true
- }
- })
+ store.Append(
+ folder,
+ models.SeenFlag,
+ time.Now(),
+ &buf,
+ int(nbytes),
+ func(msg types.WorkerMessage) {
+ switch msg := msg.(type) {
+ case *types.Unsupported:
+ errMsg := fmt.Sprintf("%s: AppendMessage is unsupported", args[0])
+ log.Errorf(errMsg)
+ app.PushError(errMsg)
+ return
+ case *types.Error:
+ log.Errorf("AppendMessage failed: %v", msg.Error)
+ done <- false
+ case *types.Done:
+ atomic.AddUint32(&appended, 1)
+ done <- true
+ }
+ },
+ )
select {
case ok := <-done: