1 Return-Path: <markwalters1009@gmail.com>
\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 29DD2431FAE
\r
6 for <notmuch@notmuchmail.org>; Thu, 19 Jan 2012 13:22:42 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,
\r
14 RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
15 Received: from olra.theworths.org ([127.0.0.1])
\r
16 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
17 with ESMTP id 092KA9m-pB5d for <notmuch@notmuchmail.org>;
\r
18 Thu, 19 Jan 2012 13:22:39 -0800 (PST)
\r
19 Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com
\r
20 [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client
\r
21 certificate requested) by olra.theworths.org (Postfix) with ESMTPS id
\r
22 A7725431FB6 for <notmuch@notmuchmail.org>; Thu, 19 Jan 2012 13:22:37 -0800
\r
24 Received: by wgbdt12 with SMTP id dt12so400608wgb.2
\r
25 for <notmuch@notmuchmail.org>; Thu, 19 Jan 2012 13:22:36 -0800 (PST)
\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
\r
27 h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;
\r
28 bh=jpMQQrJWRh6ucDHFQC2wfBL7Dm+6z/19GhiWGfz9aL4=;
\r
29 b=e6WXSXqJ+oMNnQR77xi0HLsjcsBSon5xibhE0Kfp2z1Ac9bmY6j8df6XHJ8e3aH3qn
\r
30 SJiczhQo9Ac5kHUG0n3rmYvlw+dxCEuyLYbWndddyXev4GXo6IijyRlTQSH1LX1BGIMY
\r
31 K+qEW985xCT74i10xf582X2pV2F+RQ3MVw/DU=
\r
32 Received: by 10.180.100.100 with SMTP id ex4mr19447700wib.19.1327008156503;
\r
33 Thu, 19 Jan 2012 13:22:36 -0800 (PST)
\r
34 Received: from localhost (94-192-233-223.zone6.bethere.co.uk.
\r
35 [94.192.233.223]) by mx.google.com with ESMTPS id
\r
36 dr5sm2051181wib.0.2012.01.19.13.22.34 (version=TLSv1/SSLv3 cipher=OTHER);
\r
37 Thu, 19 Jan 2012 13:22:35 -0800 (PST)
\r
38 From: Mark Walters <markwalters1009@gmail.com>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH v4 1/1] Make buttons for attachments allow viewing as well as
\r
42 Date: Thu, 19 Jan 2012 21:23:05 +0000
\r
43 Message-Id: <1327008185-21194-2-git-send-email-markwalters1009@gmail.com>
\r
44 X-Mailer: git-send-email 1.7.2.3
\r
45 In-Reply-To: <id:"20120118192147.GF16740@mit.edu">
\r
46 References: <id:"20120118192147.GF16740@mit.edu">
\r
47 X-BeenThere: notmuch@notmuchmail.org
\r
48 X-Mailman-Version: 2.1.13
\r
50 List-Id: "Use and development of the notmuch mail system."
\r
51 <notmuch.notmuchmail.org>
\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
53 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
55 List-Post: <mailto:notmuch@notmuchmail.org>
\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
58 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
59 X-List-Received-Date: Thu, 19 Jan 2012 21:22:42 -0000
\r
61 Define a keymap for attachment buttons to allow multiple actions.
\r
62 Define 3 possible actions:
\r
63 save attachment: exactly as currently,
\r
64 view attachment: uses mailcap entry,
\r
65 view attachment with user chosen program
\r
67 Keymap on a button is: s for save, v for view and o for view with
\r
68 other program. Default (i.e. enter or mouse button) is save but this
\r
69 is configurable in notmuch customize.
\r
71 One implementation detail: the view attachment function forces all
\r
72 attachments to be "displayed" using mailcap even if emacs could
\r
73 display them itself. Thus, for example, text/html appears in a browser
\r
74 and text/plain asks whether to save (on a standard debian setup)
\r
76 emacs/notmuch-show.el | 116 ++++++++++++++++++++++++++++++++++++++----------
\r
77 1 files changed, 92 insertions(+), 24 deletions(-)
\r
79 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
\r
80 index fc13462..1fcd72a 100644
\r
81 --- a/emacs/notmuch-show.el
\r
82 +++ b/emacs/notmuch-show.el
\r
83 @@ -112,6 +112,16 @@ indentation."
\r
85 :group 'notmuch-show)
\r
87 +(defcustom notmuch-show-part-button-default-action 'notmuch-show-save-part
\r
88 + "Default part header button action (on ENTER or mouse click)."
\r
89 + :group 'notmuch-show
\r
90 + :type '(choice (const :tag "Save part"
\r
91 + notmuch-show-save-part)
\r
92 + (const :tag "View part"
\r
93 + notmuch-show-view-part)
\r
94 + (const :tag "View interactively"
\r
95 + notmuch-show-interactively-view-part)))
\r
97 (defmacro with-current-notmuch-show-message (&rest body)
\r
98 "Evaluate body with current buffer set to the text of current message"
\r
100 @@ -283,10 +293,21 @@ message at DEPTH in the current thread."
\r
101 (run-hooks 'notmuch-show-markup-headers-hook)))))
\r
103 (define-button-type 'notmuch-show-part-button-type
\r
104 - 'action 'notmuch-show-part-button-action
\r
105 + 'action 'notmuch-show-part-button-default
\r
106 + 'keymap 'notmuch-show-part-button-map
\r
108 'face 'message-mml)
\r
110 +(defvar notmuch-show-part-button-map
\r
111 + (let ((map (make-sparse-keymap)))
\r
112 + (set-keymap-parent map button-map)
\r
113 + (define-key map "s" 'notmuch-show-part-button-save)
\r
114 + (define-key map "v" 'notmuch-show-part-button-view)
\r
115 + (define-key map "o" 'notmuch-show-part-button-interactively-view)
\r
117 + "Submap for button commands")
\r
118 +(fset 'notmuch-show-part-button-map notmuch-show-part-button-map)
\r
120 (defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment)
\r
123 @@ -301,29 +322,58 @@ message at DEPTH in the current thread."
\r
125 :type 'notmuch-show-part-button-type
\r
127 - :notmuch-filename name))
\r
128 + :notmuch-filename name
\r
129 + :notmuch-content-type content-type))
\r
134 ;; Functions handling particular MIME parts.
\r
136 -(defun notmuch-show-save-part (message-id nth &optional filename)
\r
137 - (let ((process-crypto notmuch-show-process-crypto))
\r
138 - (with-temp-buffer
\r
139 - (setq notmuch-show-process-crypto process-crypto)
\r
140 - ;; Always acquires the part via `notmuch part', even if it is
\r
141 - ;; available in the JSON output.
\r
142 - (insert (notmuch-show-get-bodypart-internal message-id nth))
\r
143 - (let ((file (read-file-name
\r
144 - "Filename to save as: "
\r
145 - (or mailcap-download-directory "~/")
\r
148 - ;; Don't re-compress .gz & al. Arguably we should make
\r
149 - ;; `file-name-handler-alist' nil, but that would chop
\r
150 - ;; ange-ftp, which is reasonable to use here.
\r
151 - (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))))
\r
152 +(defmacro notmuch-with-temp-part-buffer (message-id nth &rest body)
\r
153 + (declare (indent 2))
\r
154 + (let ((process-crypto (make-symbol "process-crypto")))
\r
155 + `(let ((,process-crypto notmuch-show-process-crypto))
\r
156 + (with-temp-buffer
\r
157 + (setq notmuch-show-process-crypto ,process-crypto)
\r
158 + ;; Always acquires the part via `notmuch part', even if it is
\r
159 + ;; available in the JSON output.
\r
160 + (insert (notmuch-show-get-bodypart-internal ,message-id ,nth))
\r
163 +(defun notmuch-show-save-part (message-id nth &optional filename content-type)
\r
164 + (notmuch-with-temp-part-buffer message-id nth
\r
165 + (let ((file (read-file-name
\r
166 + "Filename to save as: "
\r
167 + (or mailcap-download-directory "~/")
\r
170 + ;; Don't re-compress .gz & al. Arguably we should make
\r
171 + ;; `file-name-handler-alist' nil, but that would chop
\r
172 + ;; ange-ftp, which is reasonable to use here.
\r
173 + (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t))))
\r
175 +(defun notmuch-show-view-part (message-id nth &optional filename content-type )
\r
176 + (notmuch-with-temp-part-buffer message-id nth
\r
177 + ;; set mm-inlined-types to nil to force an external viewer
\r
178 + (let ((handle (mm-make-handle (current-buffer) (list content-type)))
\r
179 + (mm-inlined-types nil))
\r
180 + ;; We override mm-save-part as notmuch-show-save-part is better
\r
181 + ;; since it offers the filename. We need to lexically bind
\r
182 + ;; everything we need for notmuch-show-save-part to prevent
\r
183 + ;; potential dynamic shadowing.
\r
184 + (lexical-let ((message-id message-id)
\r
186 + (filename filename)
\r
187 + (content-type content-type))
\r
188 + (flet ((mm-save-part (&rest args) (notmuch-show-save-part
\r
189 + message-id nth filename content-type)))
\r
190 + (mm-display-part handle))))))
\r
192 +(defun notmuch-show-interactively-view-part (message-id nth &optional filename content-type)
\r
193 + (notmuch-with-temp-part-buffer message-id nth
\r
194 + (let ((handle (mm-make-handle (current-buffer) (list content-type))))
\r
195 + (mm-interactively-view-part handle))))
\r
197 (defun notmuch-show-mm-display-part-inline (msg part nth content-type)
\r
198 "Use the mm-decode/mm-view functions to display a part in the
\r
199 @@ -1504,12 +1554,30 @@ buffer."
\r
201 ;; Commands typically bound to buttons.
\r
203 -(defun notmuch-show-part-button-action (button)
\r
204 - (let ((nth (button-get button :notmuch-part)))
\r
206 - (notmuch-show-save-part (notmuch-show-get-message-id) nth
\r
207 - (button-get button :notmuch-filename))
\r
208 - (message "Not a valid part (is it a fake part?)."))))
\r
209 +(defun notmuch-show-part-button-default (&optional button)
\r
211 + (notmuch-show-part-button-internal button notmuch-show-part-button-default-action))
\r
213 +(defun notmuch-show-part-button-save (&optional button)
\r
215 + (notmuch-show-part-button-internal button #'notmuch-show-save-part))
\r
217 +(defun notmuch-show-part-button-view (&optional button)
\r
219 + (notmuch-show-part-button-internal button #'notmuch-show-view-part))
\r
221 +(defun notmuch-show-part-button-interactively-view (&optional button)
\r
223 + (notmuch-show-part-button-internal button #'notmuch-show-interactively-view-part))
\r
225 +(defun notmuch-show-part-button-internal (button handler)
\r
226 + (let ((button (or button (button-at (point)))))
\r
228 + (let ((nth (button-get button :notmuch-part)))
\r
230 + (funcall handler (notmuch-show-get-message-id) nth
\r
231 + (button-get button :notmuch-filename)
\r
232 + (button-get button :notmuch-content-type)))))))
\r