about summary refs log tree commit diff stats
path: root/worker/notmuch
diff options
context:
space:
mode:
Diffstat (limited to 'worker/notmuch')
-rw-r--r--worker/notmuch/message.go33
-rw-r--r--worker/notmuch/worker.go27
2 files changed, 60 insertions, 0 deletions
diff --git a/worker/notmuch/message.go b/worker/notmuch/message.go
index ec1adb9..3fd2fb6 100644
--- a/worker/notmuch/message.go
+++ b/worker/notmuch/message.go
@@ -64,6 +64,39 @@ func (m *Message) NewBodyPartReader(requestedParts []int) (io.Reader, error) {
 	return lib.FetchEntityPartReader(msg, requestedParts)
 }
 
+// MarkAnswered either adds or removes the "replied" tag from the message.
+func (m *Message) MarkAnswered(answered bool) error {
+	haveReplied := false
+	tags, err := m.Tags()
+	if err != nil {
+		return err
+	}
+	for _, t := range tags {
+		if t == "replied" {
+			haveReplied = true
+			break
+		}
+	}
+	if haveReplied == answered {
+		// we already have the desired state
+		return nil
+	}
+
+	if haveAnswered {
+		err := m.RemoveTag("replied")
+		if err != nil {
+			return err
+		}
+		return nil
+	}
+
+	err = m.AddTag("replied")
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
 // MarkRead either adds or removes the maildir.FlagSeen flag from the message.
 func (m *Message) MarkRead(seen bool) error {
 	haveUnread := false
diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go
index 9929648..b226269 100644
--- a/worker/notmuch/worker.go
+++ b/worker/notmuch/worker.go
@@ -363,6 +363,33 @@ func (w *worker) handleFetchFullMessages(msg *types.FetchFullMessages) error {
 	return nil
 }
 
+func (w *worker) handleAnsweredMessages(msg *types.AnsweredMessages) error {
+	for _, uid := range msg.Uids {
+		m, err := w.msgFromUid(uid)
+		if err != nil {
+			w.w.Logger.Printf("could not get message: %v", err)
+			w.err(msg, err)
+			continue
+		}
+		if err := m.MarkAnswered(msg.Answered); err != nil {
+			w.w.Logger.Printf("could not mark message as answered: %v", err)
+			w.err(msg, err)
+			continue
+		}
+		err = w.emitMessageInfo(m, msg)
+		if err != nil {
+			w.w.Logger.Printf(err.Error())
+			w.err(msg, err)
+			continue
+		}
+	}
+	if err := w.emitDirectoryInfo(w.currentQueryName); err != nil {
+		w.w.Logger.Printf(err.Error())
+	}
+	w.done(msg)
+	return nil
+}
+
 func (w *worker) handleReadMessages(msg *types.ReadMessages) error {
 	for _, uid := range msg.Uids {
 		m, err := w.msgFromUid(uid)