1 Return-Path: <dme@dme.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 5F9C54196F0
\r
6 for <notmuch@notmuchmail.org>; Thu, 15 Apr 2010 08:50:39 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5
\r
12 tests=[BAYES_00=-1.9] autolearn=ham
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id kmoQPv+xjIEB for <notmuch@notmuchmail.org>;
\r
16 Thu, 15 Apr 2010 08:50:38 -0700 (PDT)
\r
17 Received: from mail-wy0-f181.google.com (mail-wy0-f181.google.com
\r
19 by olra.theworths.org (Postfix) with ESMTP id A6257431FC1
\r
20 for <notmuch@notmuchmail.org>; Thu, 15 Apr 2010 08:50:37 -0700 (PDT)
\r
21 Received: by wyj26 with SMTP id 26so728920wyj.26
\r
22 for <notmuch@notmuchmail.org>; Thu, 15 Apr 2010 08:50:37 -0700 (PDT)
\r
23 Received: by 10.216.168.8 with SMTP id j8mr214660wel.192.1271346636902;
\r
24 Thu, 15 Apr 2010 08:50:36 -0700 (PDT)
\r
25 Received: from ut.hh.sledj.net (gmp-ea-fw-1b.sun.com [192.18.8.1])
\r
26 by mx.google.com with ESMTPS id x14sm12770271wbs.0.2010.04.15.08.50.29
\r
27 (version=TLSv1/SSLv3 cipher=RC4-MD5);
\r
28 Thu, 15 Apr 2010 08:50:30 -0700 (PDT)
\r
29 Received: by ut.hh.sledj.net (Postfix, from userid 1000)
\r
30 id 34ECA5941D9; Thu, 15 Apr 2010 16:50:32 +0100 (BST)
\r
31 From: David Edmondson <dme@dme.org>
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [PATCH] emacs: Re-arrange message sending code
\r
34 Date: Thu, 15 Apr 2010 16:50:27 +0100
\r
35 Message-Id: <1271346627-25310-1-git-send-email-dme@dme.org>
\r
36 X-Mailer: git-send-email 1.7.0
\r
37 X-BeenThere: notmuch@notmuchmail.org
\r
38 X-Mailman-Version: 2.1.13
\r
40 List-Id: "Use and development of the notmuch mail system."
\r
41 <notmuch.notmuchmail.org>
\r
42 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
43 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
45 List-Post: <mailto:notmuch@notmuchmail.org>
\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
47 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
49 X-List-Received-Date: Thu, 15 Apr 2010 15:50:39 -0000
\r
51 Define a new `mail-user-agent' (`notmuch-user-agent') and use it by
\r
52 default. Re-arrange various routines that send mail to use this
\r
53 (compose, reply, forward). Insert a `User-Agent:' header by default.
\r
55 emacs/notmuch-hello.el | 2 +
\r
56 emacs/notmuch-mua.el | 94 ++++++++++++++++++++++++++++++++++++++++++++++++
\r
57 emacs/notmuch-show.el | 5 ++-
\r
58 emacs/notmuch.el | 43 ++++++++++++++++------
\r
59 4 files changed, 130 insertions(+), 14 deletions(-)
\r
60 create mode 100644 emacs/notmuch-mua.el
\r
62 diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
\r
63 index c49a35f..83586f2 100644
\r
64 --- a/emacs/notmuch-hello.el
\r
65 +++ b/emacs/notmuch-hello.el
\r
68 (require 'notmuch-lib)
\r
70 +(require 'notmuch-mua)
\r
72 (declare-function notmuch-search "notmuch" (query &optional oldest-first target-thread target-line))
\r
73 (declare-function notmuch-folder-count "notmuch" (search))
\r
74 @@ -314,6 +315,7 @@ diagonal."
\r
76 (use-local-map widget-keymap)
\r
77 (local-set-key "=" 'notmuch-hello-update)
\r
78 + (local-set-key "m" 'notmuch-mua-mail)
\r
79 (local-set-key "q" '(lambda () (interactive) (kill-buffer (current-buffer))))
\r
80 (local-set-key "s" 'notmuch-hello-goto-search)
\r
82 diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
\r
83 new file mode 100644
\r
84 index 0000000..c8a8743
\r
86 +++ b/emacs/notmuch-mua.el
\r
88 +;; notmuch-mua.el --- emacs style mail-user-agent
\r
90 +;; Copyright © David Edmondson
\r
92 +;; This file is part of Notmuch.
\r
94 +;; Notmuch is free software: you can redistribute it and/or modify it
\r
95 +;; under the terms of the GNU General Public License as published by
\r
96 +;; the Free Software Foundation, either version 3 of the License, or
\r
97 +;; (at your option) any later version.
\r
99 +;; Notmuch is distributed in the hope that it will be useful, but
\r
100 +;; WITHOUT ANY WARRANTY; without even the implied warranty of
\r
101 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
102 +;; General Public License for more details.
\r
104 +;; You should have received a copy of the GNU General Public License
\r
105 +;; along with Notmuch. If not, see <http://www.gnu.org/licenses/>.
\r
107 +;; Authors: David Edmondson <dme@dme.org>
\r
109 +(require 'message)
\r
113 +(defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)
\r
114 + "Hook run before sending messages."
\r
118 +(defcustom notmuch-mua-user-agent-function 'notmuch-mua-user-agent
\r
119 + "Function used to generate a `User-Agent:' string. If this is
\r
120 +`nil' then no `User-Agent:' will be generated."
\r
126 +(defun notmuch-mua-user-agent ()
\r
127 + "Generate a `User-Agent:' string suitable for notmuch."
\r
129 + ;; Trim off the trailing newline.
\r
130 + (substring (shell-command-to-string
\r
131 + (concat notmuch-command " --version"))
\r
133 + " (Emacs " emacs-version "/"
\r
134 + system-configuration ")"))
\r
136 +(defun notmuch-mua-forward-message ()
\r
137 + (message-forward)
\r
139 + (when notmuch-mua-user-agent-function
\r
140 + (let ((user-agent (funcall notmuch-mua-user-agent-function)))
\r
141 + (when (not (string= "" user-agent))
\r
142 + (message-add-header (format "User-Agent: %s" user-agent)))))
\r
143 + (message-sort-headers)
\r
144 + (message-hide-headers))
\r
145 + (set-buffer-modified-p nil))
\r
147 +(defun notmuch-mua-mail (&optional to subject other-headers continue
\r
148 + switch-function yank-action send-actions)
\r
151 + (when notmuch-mua-user-agent-function
\r
152 + (let ((user-agent (funcall notmuch-mua-user-agent-function)))
\r
153 + (when (not (string= "" user-agent))
\r
154 + (push (cons "User-Agent" user-agent) other-headers))))
\r
156 + (message-mail to subject other-headers continue
\r
157 + switch-function yank-action send-actions)
\r
158 + (message-hide-headers))
\r
160 +(defun notmuch-mua-send-and-exit (&optional arg)
\r
161 + (interactive "P")
\r
162 + (message-send-and-exit arg))
\r
164 +(defun notmuch-mua-kill-buffer ()
\r
166 + (message-kill-buffer))
\r
168 +(defun notmuch-mua-message-send-hook ()
\r
169 + "The default function used for `notmuch-mua-send-hook', this
\r
170 +simply runs the corresponding `message-mode' hook functions."
\r
171 + (run-hooks 'message-send-hook))
\r
175 +(define-mail-user-agent 'notmuch-user-agent
\r
176 + 'notmuch-mua-mail 'notmuch-mua-send-and-exit
\r
177 + 'notmuch-mua-kill-buffer 'notmuch-mua-send-hook)
\r
181 +(provide 'notmuch-mua)
\r
182 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
\r
183 index 54d1c48..d1b0f1a 100644
\r
184 --- a/emacs/notmuch-show.el
\r
185 +++ b/emacs/notmuch-show.el
\r
187 (require 'notmuch-lib)
\r
188 (require 'notmuch-query)
\r
189 (require 'notmuch-wash)
\r
190 +(require 'notmuch-mua)
\r
192 (declare-function notmuch-call-notmuch-process "notmuch" (&rest args))
\r
193 (declare-function notmuch-reply "notmuch" (query-string))
\r
194 @@ -519,7 +520,7 @@ function is used. "
\r
195 (define-key map (kbd "M-TAB") 'notmuch-show-previous-button)
\r
196 (define-key map (kbd "TAB") 'notmuch-show-next-button)
\r
197 (define-key map "s" 'notmuch-search)
\r
198 - (define-key map "m" 'message-mail)
\r
199 + (define-key map "m" 'notmuch-mua-mail)
\r
200 (define-key map "f" 'notmuch-show-forward-message)
\r
201 (define-key map "r" 'notmuch-show-reply)
\r
202 (define-key map "|" 'notmuch-show-pipe-message)
\r
203 @@ -835,7 +836,7 @@ any effects from previous calls to
\r
204 "Forward the current message."
\r
206 (with-current-notmuch-show-message
\r
207 - (message-forward)))
\r
208 + (notmuch-mua-forward-message)))
\r
210 (defun notmuch-show-next-message ()
\r
211 "Show the next message."
\r
212 diff --git a/emacs/notmuch.el b/emacs/notmuch.el
\r
213 index b9a0a3e..56bb27f 100644
\r
214 --- a/emacs/notmuch.el
\r
215 +++ b/emacs/notmuch.el
\r
218 (require 'notmuch-lib)
\r
219 (require 'notmuch-show)
\r
220 +(require 'notmuch-mua)
\r
222 (defcustom notmuch-search-authors-width 20
\r
223 "Number of columns to use to display authors in a notmuch-search buffer."
\r
224 @@ -117,15 +118,33 @@ For example:
\r
227 (defun notmuch-reply (query-string)
\r
228 - (switch-to-buffer (generate-new-buffer "notmuch-draft"))
\r
229 - (call-process notmuch-command nil t nil "reply" query-string)
\r
230 - (message-insert-signature)
\r
231 - (goto-char (point-min))
\r
232 - (if (re-search-forward "^$" nil t)
\r
234 - (insert "--text follows this line--")
\r
237 + (let (headers body)
\r
238 + ;; This make assumptions about the output of `notmuch reply', but
\r
239 + ;; really only that the headers come first followed by a blank
\r
240 + ;; line and then the body.
\r
241 + (with-temp-buffer
\r
242 + (call-process notmuch-command nil t nil "reply" query-string)
\r
243 + (goto-char (point-min))
\r
244 + (if (re-search-forward "^$" nil t)
\r
246 + (save-restriction
\r
247 + (narrow-to-region (point-min) (point))
\r
248 + (goto-char (point-min))
\r
249 + (setq headers (mail-header-extract)))))
\r
251 + (setq body (buffer-substring (point) (point-max))))
\r
252 + (notmuch-mua-mail (mail-header 'to headers)
\r
253 + (mail-header 'subject headers)
\r
254 + (loop for header in headers
\r
255 + if (not (or (eq 'to (car header))
\r
256 + (eq 'subject (car header))))
\r
258 + (message-sort-headers)
\r
259 + (message-hide-headers)
\r
261 + (goto-char (point-max))
\r
263 + (set-buffer-modified-p nil)))
\r
265 (defun notmuch-documentation-first-line (symbol)
\r
266 "Return the first line of the documentation string for SYMBOL."
\r
267 @@ -216,7 +235,7 @@ For a mouse binding, return nil."
\r
268 (define-key map "p" 'notmuch-search-previous-thread)
\r
269 (define-key map "n" 'notmuch-search-next-thread)
\r
270 (define-key map "r" 'notmuch-search-reply-to-thread)
\r
271 - (define-key map "m" 'message-mail)
\r
272 + (define-key map "m" 'notmuch-mua-mail)
\r
273 (define-key map "s" 'notmuch-search)
\r
274 (define-key map "o" 'notmuch-search-toggle-order)
\r
275 (define-key map "=" 'notmuch-search-refresh-view)
\r
276 @@ -767,14 +786,14 @@ current search results AND that are tagged with the given tag."
\r
278 (notmuch-search "tag:inbox" notmuch-search-oldest-first))
\r
280 -(setq mail-user-agent 'message-user-agent)
\r
281 +(setq mail-user-agent 'notmuch-user-agent)
\r
283 (defvar notmuch-folder-mode-map
\r
284 (let ((map (make-sparse-keymap)))
\r
285 (define-key map "?" 'notmuch-help)
\r
286 (define-key map "x" 'kill-this-buffer)
\r
287 (define-key map "q" 'kill-this-buffer)
\r
288 - (define-key map "m" 'message-mail)
\r
289 + (define-key map "m" 'notmuch-mua-mail)
\r
290 (define-key map "e" 'notmuch-folder-show-empty-toggle)
\r
291 (define-key map ">" 'notmuch-folder-last)
\r
292 (define-key map "<" 'notmuch-folder-first)
\r