0535f6333f
More mail flags can now be set, unset, and toggled, not just the read/seen flag. This functionality is implemented with a new `:flag` and `:unflag` command, which are extensions to the matching `:read` and `:unread` commands, adding support for different flags. In fact, the `read`/`unread` commands are now recognized aliases to `flag`/`unflag`. The new commands are also well documented in aerc(1). The change mostly extends the previous read/unread setting functionality by adding a selection for the flag to change.
108 lines
2.9 KiB
Go
108 lines
2.9 KiB
Go
package imap
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/emersion/go-imap"
|
|
|
|
"git.sr.ht/~sircmpwn/aerc/worker/types"
|
|
)
|
|
|
|
func (imapw *IMAPWorker) handleDeleteMessages(msg *types.DeleteMessages) {
|
|
item := imap.FormatFlagsOp(imap.AddFlags, true)
|
|
flags := []interface{}{imap.DeletedFlag}
|
|
uids := toSeqSet(msg.Uids)
|
|
if err := imapw.client.UidStore(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)
|
|
}
|
|
}
|
|
|
|
func (imapw *IMAPWorker) handleAnsweredMessages(msg *types.AnsweredMessages) {
|
|
item := imap.FormatFlagsOp(imap.AddFlags, true)
|
|
flags := []interface{}{imap.AnsweredFlag}
|
|
if !msg.Answered {
|
|
item = imap.FormatFlagsOp(imap.RemoveFlags, true)
|
|
flags = []interface{}{imap.AnsweredFlag}
|
|
}
|
|
uids := toSeqSet(msg.Uids)
|
|
emitErr := func(err error) {
|
|
imapw.worker.PostMessage(&types.Error{
|
|
Message: types.RespondTo(msg),
|
|
Error: err,
|
|
}, nil)
|
|
}
|
|
if err := imapw.client.UidStore(uids, item, flags, nil); err != nil {
|
|
emitErr(err)
|
|
return
|
|
}
|
|
imapw.worker.PostAction(&types.FetchMessageHeaders{
|
|
Uids: msg.Uids,
|
|
}, func(_msg types.WorkerMessage) {
|
|
switch m := _msg.(type) {
|
|
case *types.Error:
|
|
err := fmt.Errorf("handleAnsweredMessages: %v", m.Error)
|
|
imapw.worker.Logger.Printf("could not fetch headers: %s", err)
|
|
emitErr(err)
|
|
case *types.Done:
|
|
imapw.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (imapw *IMAPWorker) handleFlagMessages(msg *types.FlagMessages) {
|
|
flags := []interface{}{flagToImap[msg.Flag]}
|
|
item := imap.FormatFlagsOp(imap.AddFlags, true)
|
|
if !msg.Enable {
|
|
item = imap.FormatFlagsOp(imap.RemoveFlags, true)
|
|
}
|
|
uids := toSeqSet(msg.Uids)
|
|
emitErr := func(err error) {
|
|
imapw.worker.PostMessage(&types.Error{
|
|
Message: types.RespondTo(msg),
|
|
Error: err,
|
|
}, nil)
|
|
}
|
|
if err := imapw.client.UidStore(uids, item, flags, nil); err != nil {
|
|
emitErr(err)
|
|
return
|
|
}
|
|
imapw.worker.PostAction(&types.FetchMessageHeaders{
|
|
Uids: msg.Uids,
|
|
}, func(_msg types.WorkerMessage) {
|
|
switch m := _msg.(type) {
|
|
case *types.Error:
|
|
err := fmt.Errorf("handleFlagMessages: %v", m.Error)
|
|
imapw.worker.Logger.Printf("could not fetch headers: %s", err)
|
|
emitErr(err)
|
|
case *types.Done:
|
|
imapw.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
|
|
}
|
|
})
|
|
}
|