diff options
author | Srivathsan Murali <sri@vathsan.com> | 2020-05-25 16:59:48 +0200 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2020-05-25 11:29:53 -0400 |
commit | b1eb7ad18d2e0bbeecaf61a58825bbc794ceb40c (patch) | |
tree | 310ff7fa90dfb23c303b7f89674b8411bd8cdf89 /worker/imap | |
parent | a31d184ba53a9a61b8a0eed42cee52f9b1f2dc51 (diff) | |
download | aerc-b1eb7ad18d2e0bbeecaf61a58825bbc794ceb40c.tar.gz |
Set AnsweredFlag on successful reply
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 17c9393c..26250866 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 45a22690..a43ac49e 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: |