[notmuch] auto-tagging replied messages

Jesse Rosenthal jrosenthal at jhu.edu
Fri Mar 5 06:39:14 PST 2010


Dear All,

One element of traditional clients that I've missed in notmuch is the
ability to easily see which messages have been replied to. A look at the
thread structure will often make that clear, but for both searching and
syncing, an "answered" tag would be nice.

To solve this, I have added the following to my .emacs, and I wanted to
share it in case others might find it useful. You can add an arbitrary
number of tags to the list "notmuch-answered-tags" and it will apply
them (or remove them) when the reply is sent. So you could use it to
automatically mark and email "answered" and remove it from the inbox, or
remove a "todo" or "reply_later" tag.

This relies on the "In-Reply-To" header, so if that's not there, it
won't mark the original message. But then, if that's not there,
threading won't work either, so you'll have bigger problems in notmuch.

Thanks to David, who took a look and offered some suggestions on IRC.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; A set of tags to be added or, if prefaced with a `-', removed
;; e.g. (setq notmuch-answered-tags '("replied" "-todo" "-inbox"))
(setq notmuch-answered-tags '("answered"))

(defun jkr/notmuch-mark-answered ()
  ;; get the in-reply-to header and parse it for the message id. 
  (let ((rep (mail-header-parse-addresses (message-field-value "In-Reply-To"))))
    (when (and notmuch-answered-tags rep)
      ;; add a "+" to any tag that is doesn't already begin with a "+"
      ;; or "-"
      (let ((tags (mapcar '(lambda (str)
			     (if (not (string-match "^[+-]" str))
				 (concat "+" str)
			       str))
			  notmuch-answered-tags)))
	(apply 'notmuch-call-notmuch-process "tag"
	       (append tags (list (concat "id:" (car (car rep)))) nil))))))

(add-hook 'message-sent-hook 'jkr/notmuch-mark-answered)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

By the way, the reason that I didn't submit this as a patch to
notmuch.el is that I'm not sure how we want to deal with things that are
actually more about message-mode, and could possibly affect other
programs using message-mode (gnus). There are a couple of ways to deal
with this (e.g., notmuch minor-mode in message-mode, custom headers) but
my sense is that we should keep notmuch.el from being too imperious at
the moment.

Best,
Jesse





More information about the notmuch mailing list