summary refs log tree commit diff stats
path: root/worker/notmuch/message.go
diff options
context:
space:
mode:
authorSrivathsan Murali <sri@vathsan.com>2020-05-25 16:59:48 +0200
committerDrew DeVault <sir@cmpwn.com>2020-05-25 11:29:53 -0400
commitb1eb7ad18d2e0bbeecaf61a58825bbc794ceb40c (patch)
tree310ff7fa90dfb23c303b7f89674b8411bd8cdf89 /worker/notmuch/message.go
parenta31d184ba53a9a61b8a0eed42cee52f9b1f2dc51 (diff)
downloadaerc-b1eb7ad18d2e0bbeecaf61a58825bbc794ceb40c.tar.gz
Set AnsweredFlag on successful reply
Diffstat (limited to 'worker/notmuch/message.go')
-rw-r--r--worker/notmuch/message.go33
1 files changed, 33 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