diff options
Diffstat (limited to 'worker/imap')
-rw-r--r-- | worker/imap/flags.go | 32 | ||||
-rw-r--r-- | worker/imap/worker.go | 2 |
2 files changed, 34 insertions, 0 deletions
diff --git a/worker/imap/flags.go b/worker/imap/flags.go index 17c9393..2625086 100644 --- a/worker/imap/flags.go +++ b/worker/imap/flags.go @@ -44,6 +44,38 @@ func (imapw *IMAPWorker) handleDeleteMessages(msg *types.DeleteMessages) { } } +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) handleReadMessages(msg *types.ReadMessages) { item := imap.FormatFlagsOp(imap.AddFlags, true) flags := []interface{}{imap.SeenFlag} diff --git a/worker/imap/worker.go b/worker/imap/worker.go index 45a2269..a43ac49 100644 --- a/worker/imap/worker.go +++ b/worker/imap/worker.go @@ -175,6 +175,8 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error { w.handleDeleteMessages(msg) case *types.ReadMessages: w.handleReadMessages(msg) + case *types.AnsweredMessages: + w.handleAnsweredMessages(msg) case *types.CopyMessages: w.handleCopyMessages(msg) case *types.AppendMessage: |