1 ;; notmuch-mua.el --- emacs style mail-user-agent
3 ;; Copyright © David Edmondson
5 ;; This file is part of Notmuch.
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.
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.
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/>.
20 ;; Authors: David Edmondson <dme@dme.org>
25 (require 'notmuch-lib)
29 (defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)
30 "Hook run before sending messages."
34 (defcustom notmuch-mua-user-agent-function 'notmuch-mua-user-agent-full
35 "Function used to generate a `User-Agent:' string. If this is
36 `nil' then no `User-Agent:' will be generated."
39 :options '(notmuch-mua-user-agent-full
40 notmuch-mua-user-agent-notmuch
41 notmuch-mua-user-agent-emacs))
45 (defun notmuch-mua-user-agent-full ()
46 "Generate a `User-Agent:' string suitable for notmuch."
47 (concat (notmuch-mua-user-agent-notmuch)
49 (notmuch-mua-user-agent-emacs)))
51 (defun notmuch-mua-user-agent-notmuch ()
52 "Generate a `User-Agent:' string suitable for notmuch."
53 (concat "Notmuch/" (notmuch-version) " (http://notmuchmail.org)"))
55 (defun notmuch-mua-user-agent-emacs ()
56 "Generate a `User-Agent:' string suitable for notmuch."
57 (concat "Emacs/" emacs-version " (" system-configuration ")"))
59 (defun notmuch-mua-reply (query-string)
61 ;; This make assumptions about the output of `notmuch reply', but
62 ;; really only that the headers come first followed by a blank
63 ;; line and then the body.
65 (call-process notmuch-command nil t nil "reply" query-string)
66 (goto-char (point-min))
67 (if (re-search-forward "^$" nil t)
70 (narrow-to-region (point-min) (point))
71 (goto-char (point-min))
72 (setq headers (mail-header-extract)))))
74 (setq body (buffer-substring (point) (point-max))))
75 (notmuch-mua-mail (mail-header 'to headers)
76 (mail-header 'subject headers)
77 (loop for header in headers
78 if (not (or (eq 'to (car header))
79 (eq 'subject (car header))))
81 (message-sort-headers)
82 (message-hide-headers)
84 (goto-char (point-max))
86 (set-buffer-modified-p nil)))
88 (defun notmuch-mua-forward-message ()
91 (when notmuch-mua-user-agent-function
92 (let ((user-agent (funcall notmuch-mua-user-agent-function)))
93 (when (not (string= "" user-agent))
94 (message-add-header (format "User-Agent: %s" user-agent)))))
95 (message-sort-headers)
96 (message-hide-headers))
97 (set-buffer-modified-p nil))
99 (defun notmuch-mua-mail (&optional to subject other-headers continue
100 switch-function yank-action send-actions)
103 (when notmuch-mua-user-agent-function
104 (let ((user-agent (funcall notmuch-mua-user-agent-function)))
105 (when (not (string= "" user-agent))
106 (push (cons "User-Agent" user-agent) other-headers))))
108 (message-mail to subject other-headers continue
109 switch-function yank-action send-actions)
110 (message-hide-headers))
112 (defun notmuch-mua-send-and-exit (&optional arg)
114 (message-send-and-exit arg))
116 (defun notmuch-mua-kill-buffer ()
118 (message-kill-buffer))
120 (defun notmuch-mua-message-send-hook ()
121 "The default function used for `notmuch-mua-send-hook', this
122 simply runs the corresponding `message-mode' hook functions."
123 (run-hooks 'message-send-hook))
127 (define-mail-user-agent 'notmuch-user-agent
128 'notmuch-mua-mail 'notmuch-mua-send-and-exit
129 'notmuch-mua-kill-buffer 'notmuch-mua-send-hook)
133 (provide 'notmuch-mua)