diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-03-20 23:23:38 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-03-20 23:23:38 -0400 |
commit | 312a53e5ff721e0a29e34aaeceb0eece1203002d (patch) | |
tree | fb0c5f30d89f904d5fad4a900c910a1dd1d891be /worker/imap/flags.go | |
parent | f3d3e0ed4f5dbf36b7a7c9762e6297083843f127 (diff) |
Implement :delete-message
Diffstat (limited to 'worker/imap/flags.go')
-rw-r--r-- | worker/imap/flags.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/worker/imap/flags.go b/worker/imap/flags.go new file mode 100644 index 0000000..cb9b3b1 --- /dev/null +++ b/worker/imap/flags.go @@ -0,0 +1,43 @@ +package imap + +import ( + "github.com/emersion/go-imap" + + "git.sr.ht/~sircmpwn/aerc2/worker/types" +) + +func (imapw *IMAPWorker) handleDeleteMessages(msg *types.DeleteMessages) { + item := imap.FormatFlagsOp(imap.AddFlags, true) + flags := []interface{}{imap.DeletedFlag} + if err := imapw.client.UidStore(&msg.Uids, item, flags, nil); err != nil { + imapw.worker.PostMessage(&types.Error{ + Message: types.RespondTo(msg), + Error: err, + }, nil) + return + } + var deleted []uint32 + ch := make(chan uint32) + done := make(chan interface{}) + go func() { + for seqNum := range ch { + i := seqNum - 1 + deleted = append(deleted, imapw.seqMap[i]) + imapw.seqMap = append(imapw.seqMap[:i], imapw.seqMap[i+1:]...) + } + done <- nil + }() + if err := imapw.client.Expunge(ch); err != nil { + imapw.worker.PostMessage(&types.Error{ + Message: types.RespondTo(msg), + Error: err, + }, nil) + } else { + <-done + imapw.worker.PostMessage(&types.MessagesDeleted{ + Message: types.RespondTo(msg), + Uids: deleted, + }, nil) + imapw.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil) + } +} |