1 Return-Path: <amdragon@mit.edu>
\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 56C90431FAF
\r
6 for <notmuch@notmuchmail.org>; Thu, 19 Jan 2012 20:30:45 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\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 nn4foO6Av-yu for <notmuch@notmuchmail.org>;
\r
16 Thu, 19 Jan 2012 20:30:44 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id 374FA431FAE
\r
20 for <notmuch@notmuchmail.org>; Thu, 19 Jan 2012 20:30:44 -0800 (PST)
\r
21 X-AuditID: 1209190e-b7f7c6d0000008c3-f4-4f18edf3a236
\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])
\r
23 by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id C0.BD.02243.3FDE81F4; Thu, 19 Jan 2012 23:30:43 -0500 (EST)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0K4UhRi019618;
\r
27 Thu, 19 Jan 2012 23:30:43 -0500
\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0K4Ugj9013396
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Thu, 19 Jan 2012 23:30:43 -0500 (EST)
\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)
\r
35 (envelope-from <amdragon@mit.edu>)
\r
36 id 1Ro67L-0004gV-Vb; Thu, 19 Jan 2012 23:30:24 -0500
\r
37 Date: Thu, 19 Jan 2012 23:30:23 -0500
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: Mark Walters <markwalters1009@gmail.com>
\r
40 Subject: Re: [PATCH v4 1/1] Make buttons for attachments allow viewing as
\r
42 Message-ID: <20120120043023.GW16740@mit.edu>
\r
43 References: <id:"20120118192147.GF16740@mit.edu">
\r
44 <1327008185-21194-2-git-send-email-markwalters1009@gmail.com>
\r
46 Content-Type: text/plain; charset=us-ascii
\r
47 Content-Disposition: inline
\r
48 In-Reply-To: <1327008185-21194-2-git-send-email-markwalters1009@gmail.com>
\r
49 User-Agent: Mutt/1.5.21 (2010-09-15)
\r
50 X-Brightmail-Tracker:
\r
51 H4sIAAAAAAAAA+NgFvrPIsWRmVeSWpSXmKPExsUixG6nrvv5rYS/wdK3ahar5/JYXL85k9mB
\r
52 yWPnrLvsHs9W3WIOYIrisklJzcksSy3St0vgyviweyNzwTbbivsbF7A3MC427GLk5JAQMJFY
\r
53 37ySEcIWk7hwbz1bFyMXh5DAPkaJ/zuPMUE4Gxgldn97zA5SJSRwkkli8/FgCHsJo8Tc2Ykg
\r
54 NouAqsT7UzNZQWw2AQ2JbfuXg00VEdCRuH1oAVgvs4C0xLffzUwgtrBAlMSBd3NYuhg5OHiB
\r
55 aj5uV4cYWSjxb+8isHJeAUGJkzOfsEC0aknc+PeSCaQcZMzyfxwgJqeAl0TPvGqQClEBFYkp
\r
56 J7exTWAUmoWkeRaS5lkIzQsYmVcxyqbkVunmJmbmFKcm6xYnJ+blpRbpGuvlZpbopaaUbmIE
\r
57 hTOnJN8Oxq8HlQ4xCnAwKvHwcrpK+AuxJpYVV+YeYpTkYFIS5VV+DRTiS8pPqcxILM6ILyrN
\r
58 SS0+xCjBwawkwuvwBCjHm5JYWZValA+TkuZgURLnVdN65yckkJ5YkpqdmlqQWgSTleHgUJLg
\r
59 dQXGrZBgUWp6akVaZk4JQpqJgxNkOA/Q8BKQGt7igsTc4sx0iPwpRkUpcV55kIQASCKjNA+u
\r
60 F5ZuXjGKA70izFsLUsUDTFVw3a+ABjMBDfZoEgMZXJKIkJJqYKxPqj2UoHX+9CSRSC2feu//
\r
61 jsIP23lNAtsFY80L5zqrMP3mSZ6bdPPeXW3b8ohUj8Dnm0N0Qk8XrNeavbMxRSOGk7eg0tVE
\r
62 QE9kPteRxS77/u44uE9ka8j/+abdyQu/luVabyp5FM5l/mQSx2vPGR33912WV941bbG0uoH7
\r
63 jQi/C8m+jpdWKrEUZyQaajEXFScCAGM9q+0SAwAA
\r
64 Cc: notmuch@notmuchmail.org
\r
65 X-BeenThere: notmuch@notmuchmail.org
\r
66 X-Mailman-Version: 2.1.13
\r
68 List-Id: "Use and development of the notmuch mail system."
\r
69 <notmuch.notmuchmail.org>
\r
70 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
71 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
72 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
73 List-Post: <mailto:notmuch@notmuchmail.org>
\r
74 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
75 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
76 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
77 X-List-Received-Date: Fri, 20 Jan 2012 04:30:45 -0000
\r
79 One indentation nit and then this LGTM.
\r
81 Quoth Mark Walters on Jan 19 at 9:23 pm:
\r
82 > Define a keymap for attachment buttons to allow multiple actions.
\r
83 > Define 3 possible actions:
\r
84 > save attachment: exactly as currently,
\r
85 > view attachment: uses mailcap entry,
\r
86 > view attachment with user chosen program
\r
88 > Keymap on a button is: s for save, v for view and o for view with
\r
89 > other program. Default (i.e. enter or mouse button) is save but this
\r
90 > is configurable in notmuch customize.
\r
92 > One implementation detail: the view attachment function forces all
\r
93 > attachments to be "displayed" using mailcap even if emacs could
\r
94 > display them itself. Thus, for example, text/html appears in a browser
\r
95 > and text/plain asks whether to save (on a standard debian setup)
\r
97 > emacs/notmuch-show.el | 116 ++++++++++++++++++++++++++++++++++++++----------
\r
98 > 1 files changed, 92 insertions(+), 24 deletions(-)
\r
100 > diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
\r
101 > index fc13462..1fcd72a 100644
\r
102 > --- a/emacs/notmuch-show.el
\r
103 > +++ b/emacs/notmuch-show.el
\r
104 > @@ -112,6 +112,16 @@ indentation."
\r
106 > :group 'notmuch-show)
\r
108 > +(defcustom notmuch-show-part-button-default-action 'notmuch-show-save-part
\r
109 > + "Default part header button action (on ENTER or mouse click)."
\r
110 > + :group 'notmuch-show
\r
111 > + :type '(choice (const :tag "Save part"
\r
112 > + notmuch-show-save-part)
\r
113 > + (const :tag "View part"
\r
114 > + notmuch-show-view-part)
\r
115 > + (const :tag "View interactively"
\r
116 > + notmuch-show-interactively-view-part)))
\r
118 > (defmacro with-current-notmuch-show-message (&rest body)
\r
119 > "Evaluate body with current buffer set to the text of current message"
\r
121 > @@ -283,10 +293,21 @@ message at DEPTH in the current thread."
\r
122 > (run-hooks 'notmuch-show-markup-headers-hook)))))
\r
124 > (define-button-type 'notmuch-show-part-button-type
\r
125 > - 'action 'notmuch-show-part-button-action
\r
126 > + 'action 'notmuch-show-part-button-default
\r
127 > + 'keymap 'notmuch-show-part-button-map
\r
129 > 'face 'message-mml)
\r
131 > +(defvar notmuch-show-part-button-map
\r
132 > + (let ((map (make-sparse-keymap)))
\r
133 > + (set-keymap-parent map button-map)
\r
134 > + (define-key map "s" 'notmuch-show-part-button-save)
\r
135 > + (define-key map "v" 'notmuch-show-part-button-view)
\r
136 > + (define-key map "o" 'notmuch-show-part-button-interactively-view)
\r
138 > + "Submap for button commands")
\r
139 > +(fset 'notmuch-show-part-button-map notmuch-show-part-button-map)
\r
141 > (defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment)
\r
144 > @@ -301,29 +322,58 @@ message at DEPTH in the current thread."
\r
146 > :type 'notmuch-show-part-button-type
\r
147 > :notmuch-part nth
\r
148 > - :notmuch-filename name))
\r
149 > + :notmuch-filename name
\r
150 > + :notmuch-content-type content-type))
\r
155 > ;; Functions handling particular MIME parts.
\r
157 > -(defun notmuch-show-save-part (message-id nth &optional filename)
\r
158 > - (let ((process-crypto notmuch-show-process-crypto))
\r
159 > - (with-temp-buffer
\r
160 > - (setq notmuch-show-process-crypto process-crypto)
\r
161 > - ;; Always acquires the part via `notmuch part', even if it is
\r
162 > - ;; available in the JSON output.
\r
163 > - (insert (notmuch-show-get-bodypart-internal message-id nth))
\r
164 > - (let ((file (read-file-name
\r
165 > - "Filename to save as: "
\r
166 > - (or mailcap-download-directory "~/")
\r
169 > - ;; Don't re-compress .gz & al. Arguably we should make
\r
170 > - ;; `file-name-handler-alist' nil, but that would chop
\r
171 > - ;; ange-ftp, which is reasonable to use here.
\r
172 > - (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))))
\r
173 > +(defmacro notmuch-with-temp-part-buffer (message-id nth &rest body)
\r
174 > + (declare (indent 2))
\r
175 > + (let ((process-crypto (make-symbol "process-crypto")))
\r
176 > + `(let ((,process-crypto notmuch-show-process-crypto))
\r
177 > + (with-temp-buffer
\r
178 > + (setq notmuch-show-process-crypto ,process-crypto)
\r
179 > + ;; Always acquires the part via `notmuch part', even if it is
\r
180 > + ;; available in the JSON output.
\r
181 > + (insert (notmuch-show-get-bodypart-internal ,message-id ,nth))
\r
184 > +(defun notmuch-show-save-part (message-id nth &optional filename content-type)
\r
185 > + (notmuch-with-temp-part-buffer message-id nth
\r
186 > + (let ((file (read-file-name
\r
187 > + "Filename to save as: "
\r
188 > + (or mailcap-download-directory "~/")
\r
191 > + ;; Don't re-compress .gz & al. Arguably we should make
\r
192 > + ;; `file-name-handler-alist' nil, but that would chop
\r
193 > + ;; ange-ftp, which is reasonable to use here.
\r
194 > + (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t))))
\r
196 > +(defun notmuch-show-view-part (message-id nth &optional filename content-type )
\r
197 > + (notmuch-with-temp-part-buffer message-id nth
\r
198 > + ;; set mm-inlined-types to nil to force an external viewer
\r
199 > + (let ((handle (mm-make-handle (current-buffer) (list content-type)))
\r
200 > + (mm-inlined-types nil))
\r
201 > + ;; We override mm-save-part as notmuch-show-save-part is better
\r
202 > + ;; since it offers the filename. We need to lexically bind
\r
203 > + ;; everything we need for notmuch-show-save-part to prevent
\r
204 > + ;; potential dynamic shadowing.
\r
205 > + (lexical-let ((message-id message-id)
\r
207 > + (filename filename)
\r
208 > + (content-type content-type))
\r
209 > + (flet ((mm-save-part (&rest args) (notmuch-show-save-part
\r
211 This body of lexical-let should be indented like a normal let body.
\r
212 You might have to load cl to get this indentation rule.
\r
214 > + message-id nth filename content-type)))
\r
215 > + (mm-display-part handle))))))
\r
217 > +(defun notmuch-show-interactively-view-part (message-id nth &optional filename content-type)
\r
218 > + (notmuch-with-temp-part-buffer message-id nth
\r
219 > + (let ((handle (mm-make-handle (current-buffer) (list content-type))))
\r
220 > + (mm-interactively-view-part handle))))
\r
222 > (defun notmuch-show-mm-display-part-inline (msg part nth content-type)
\r
223 > "Use the mm-decode/mm-view functions to display a part in the
\r
224 > @@ -1504,12 +1554,30 @@ buffer."
\r
226 > ;; Commands typically bound to buttons.
\r
228 > -(defun notmuch-show-part-button-action (button)
\r
229 > - (let ((nth (button-get button :notmuch-part)))
\r
231 > - (notmuch-show-save-part (notmuch-show-get-message-id) nth
\r
232 > - (button-get button :notmuch-filename))
\r
233 > - (message "Not a valid part (is it a fake part?)."))))
\r
234 > +(defun notmuch-show-part-button-default (&optional button)
\r
236 > + (notmuch-show-part-button-internal button notmuch-show-part-button-default-action))
\r
238 > +(defun notmuch-show-part-button-save (&optional button)
\r
240 > + (notmuch-show-part-button-internal button #'notmuch-show-save-part))
\r
242 > +(defun notmuch-show-part-button-view (&optional button)
\r
244 > + (notmuch-show-part-button-internal button #'notmuch-show-view-part))
\r
246 > +(defun notmuch-show-part-button-interactively-view (&optional button)
\r
248 > + (notmuch-show-part-button-internal button #'notmuch-show-interactively-view-part))
\r
250 > +(defun notmuch-show-part-button-internal (button handler)
\r
251 > + (let ((button (or button (button-at (point)))))
\r
253 > + (let ((nth (button-get button :notmuch-part)))
\r
255 > + (funcall handler (notmuch-show-get-message-id) nth
\r
256 > + (button-get button :notmuch-filename)
\r
257 > + (button-get button :notmuch-content-type)))))))
\r