]> git.notmuchmail.org Git - notmuch/blob - emacs/notmuch-message.el
emacs: Add auto-tagging for replied messages.
[notmuch] / emacs / notmuch-message.el
1 ;; notmuch-message.el --- message-mode functions specific to notmuch
2 ;;
3 ;; Copyright © Jesse Rosenthal
4 ;;
5 ;; This file is part of Notmuch.
6 ;;
7 ;; Notmuch is free software: you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
11 ;;
12 ;; Notmuch is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 ;; General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with Notmuch.  If not, see <http://www.gnu.org/licenses/>.
19 ;;
20 ;; Authors: Jesse Rosenthal <jrosenthal@jhu.edu>
21
22 (require 'message)
23 (require 'notmuch-mua)
24
25 (defcustom notmuch-message-replied-tags '("replied")
26   "Tags to be automatically added to or removed from a message when it is replied to.
27 Any tag in the list will be added to a replied message or,
28 if it is prefaced with a \"-\", removed.
29
30 For example, if you wanted to add a \"replied\" tag and remove
31 the \"inbox\" and \"todo\", you would set
32     (\"replied\" \"-inbox\" \"-todo\"\)"
33   :type 'list
34   :group 'notmuch)
35
36 (defun notmuch-message-mark-replied ()
37   ;; get the in-reply-to header and parse it for the message id.
38   (let ((rep (mail-header-parse-addresses (message-field-value "In-Reply-To"))))
39     (when (and notmuch-message-replied-tags rep)
40       ;; add a "+" to any tag that is doesn't already begin with a "+"
41       ;; or "-"
42       (let ((tags (mapcar '(lambda (str)
43                              (if (not (string-match "^[+-]" str))
44                                  (concat "+" str)
45                                str))
46                           notmuch-message-replied-tags)))
47         (apply 'notmuch-call-notmuch-process "tag"
48                (append tags (list (concat "id:" (car (car rep)))) nil))))))
49
50 (add-hook 'message-send-hook 'notmuch-message-mark-replied)
51
52 (provide 'notmuch-message)