RFC/PATCH emacs attachment handling
[notmuch-archives.git] / 92 / 24af277b990f26b6cea8dc72151f99bc995a5d
1 Return-Path: <m.walters@qmul.ac.uk>\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 630D3431FD0\r
6         for <notmuch@notmuchmail.org>; Tue,  6 Sep 2011 19:23:23 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.098\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
12         tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
13         NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id ucCi4K6jyL54 for <notmuch@notmuchmail.org>;\r
17         Tue,  6 Sep 2011 19:23:22 -0700 (PDT)\r
18 X-Greylist: delayed 3774 seconds by postgrey-1.32 at olra;\r
19         Tue, 06 Sep 2011 19:23:22 PDT\r
20 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
21         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
22         (No client certificate requested)\r
23         by olra.theworths.org (Postfix) with ESMTPS id 8FC38431FB6\r
24         for <notmuch@notmuchmail.org>; Tue,  6 Sep 2011 19:23:22 -0700 (PDT)\r
25 Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
26         by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
27         (envelope-from <m.walters@qmul.ac.uk>)\r
28         id 1R16oS-0001Cm-Oo; Wed, 07 Sep 2011 02:20:24 +0100\r
29 Received: from [82.153.7.131] (helo=localhost)\r
30         by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
31         (envelope-from <m.walters@qmul.ac.uk>)\r
32         id 1R16oE-0000WM-16; Wed, 07 Sep 2011 02:20:24 +0100\r
33 From: Mark Walters <markwalters1009@gmail.com>\r
34 To: Notmuch Mail <notmuch@notmuchmail.org>\r
35 Subject: RFC/PATCH emacs attachment handling\r
36 User-Agent: Notmuch/0.7-37-g89c28de (http://notmuchmail.org) Emacs/23.2.1\r
37         (i486-pc-linux-gnu)\r
38 Date: Wed, 07 Sep 2011 02:20:14 +0100\r
39 Message-ID: <87mxehqhbl.fsf@r102.config>\r
40 MIME-Version: 1.0\r
41 Content-Type: text/plain; charset=us-ascii\r
42 X-Sender-Host-Address: 82.153.7.131\r
43 X-QM-SPAM-Info: Sender has good ham record.  :)\r
44 X-QM-Body-MD5: b05c930e36bafba0c01871cef296cb2c (of first 20000 bytes)\r
45 X-QM-Scan-Virus: ClamAV says the message is clean\r
46 X-BeenThere: notmuch@notmuchmail.org\r
47 X-Mailman-Version: 2.1.13\r
48 Precedence: list\r
49 List-Id: "Use and development of the notmuch mail system."\r
50         <notmuch.notmuchmail.org>\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
54 List-Post: <mailto:notmuch@notmuchmail.org>\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
57         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
58 X-List-Received-Date: Wed, 07 Sep 2011 02:23:23 -0000\r
59 \r
60 \r
61 Hello\r
62 \r
63 I have modified the emacs interface for handling attachments by adding\r
64 a keymap to the attachment button. For example pressing v when on an\r
65 attachment button views the attachment (using the mailcap method) and\r
66 pressing s saves the attachment. I find this makes it a lot easier\r
67 when dealing with message with lots of attachments.\r
68 \r
69 Other comments:\r
70 \r
71 "Viewing" a text/html button opens the part in the mailcap defined html viewer.\r
72 \r
73 "Viewing" a part with no mailcap entry just offers to save it.\r
74 \r
75 In this version I make the button default to viewing: this is obviously\r
76 trivial to change but I am not sure what the right way to make that\r
77 user-configurable is.  \r
78 \r
79 Finally, I have also mapped the key "o" (other/open with) on a button to\r
80 open with user chosen program. This could be split out into a separate\r
81 patch if preferred.\r
82 \r
83 Best wishes\r
84 \r
85 Mark\r
86 \r
87 ---\r
88  emacs/notmuch-show.el |   76 +++++++++++++++++++++++++++++++++++++++++++-----\r
89  1 files changed, 68 insertions(+), 8 deletions(-)\r
90 \r
91 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
92 index 90f9af7..3a025c5 100644\r
93 --- a/emacs/notmuch-show.el\r
94 +++ b/emacs/notmuch-show.el\r
95 @@ -267,10 +267,21 @@ message at DEPTH in the current thread."\r
96         (run-hooks 'notmuch-show-markup-headers-hook)))))\r
97  \r
98  (define-button-type 'notmuch-show-part-button-type\r
99 -  'action 'notmuch-show-part-button-action\r
100 +  'action 'notmuch-show-part-button-view-action\r
101 +  'keymap 'notmuch-show-part-button-map\r
102    'follow-link t\r
103    'face 'message-mml)\r
104  \r
105 +(defvar notmuch-show-part-button-map\r
106 +  (let ((map (make-sparse-keymap)))\r
107 +       (set-keymap-parent map button-map)\r
108 +       (define-key map "s" 'notmuch-show-part-button-save-action)\r
109 +       (define-key map "v" 'notmuch-show-part-button-view-action)\r
110 +       (define-key map "o" 'notmuch-show-part-button-interactively-view-action)\r
111 +    map)\r
112 +  "Submap for button commands")\r
113 +(fset 'notmuch-show-part-button-map notmuch-show-part-button-map)\r
114 +\r
115  (defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment)\r
116    (let ((button))\r
117      (setq button\r
118 @@ -285,7 +296,8 @@ message at DEPTH in the current thread."\r
119                    " ]")\r
120            :type 'notmuch-show-part-button-type\r
121            :notmuch-part nth\r
122 -          :notmuch-filename name))\r
123 +          :notmuch-filename name\r
124 +          :notmuch-content-type content-type))\r
125      (insert "\n")\r
126      ;; return button\r
127      button))\r
128 @@ -309,6 +321,28 @@ message at DEPTH in the current thread."\r
129         ;; ange-ftp, which is reasonable to use here.\r
130         (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))))\r
131  \r
132 +(defun notmuch-show-view-part (message-id nth content-type)\r
133 +  (let ((process-crypto notmuch-show-process-crypto))\r
134 +    (with-temp-buffer\r
135 +      (setq notmuch-show-process-crypto process-crypto)\r
136 +      ;; Always acquires the part via `notmuch part', even if it is\r
137 +      ;; available in the JSON output.\r
138 +      (insert (notmuch-show-get-bodypart-internal message-id nth))\r
139 +      ;; set mm-inlined-types to nil to force an external viewer\r
140 +      (let ((handle (mm-make-handle (current-buffer) (list content-type)))\r
141 +           (mm-inlined-types nil))\r
142 +       (mm-display-part handle)))))\r
143 +\r
144 +(defun notmuch-show-interactively-view-part (message-id nth content-type)\r
145 +  (let ((process-crypto notmuch-show-process-crypto))\r
146 +    (with-temp-buffer\r
147 +      (setq notmuch-show-process-crypto process-crypto)\r
148 +      ;; Always acquires the part via `notmuch part', even if it is\r
149 +      ;; available in the JSON output.\r
150 +      (insert (notmuch-show-get-bodypart-internal message-id nth))\r
151 +      (let ((handle (mm-make-handle (current-buffer) (list content-type))))\r
152 +       (mm-interactively-view-part handle)))))\r
153 +\r
154  (defun notmuch-show-mm-display-part-inline (msg part content-type content)\r
155    "Use the mm-decode/mm-view functions to display a part in the\r
156  current buffer, if possible."\r
157 @@ -1418,12 +1452,38 @@ buffer."\r
158  \r
159  ;; Commands typically bound to buttons.\r
160  \r
161 -(defun notmuch-show-part-button-action (button)\r
162 -  (let ((nth (button-get button :notmuch-part)))\r
163 -    (if nth\r
164 -       (notmuch-show-save-part (notmuch-show-get-message-id) nth\r
165 -                               (button-get button :notmuch-filename))\r
166 -      (message "Not a valid part (is it a fake part?)."))))\r
167 +(defun notmuch-show-part-button-save-action (&optional button)\r
168 +  (interactive)\r
169 +  (let ((button (or button (button-at (point)))))\r
170 +    (if (not button)\r
171 +       nil\r
172 +      (let ((nth (button-get button :notmuch-part)))\r
173 +       (if nth\r
174 +           (notmuch-show-save-part (notmuch-show-get-message-id) nth\r
175 +                                   (button-get button :notmuch-filename))\r
176 +         (message "Not a valid part (is it a fake part?)."))))))\r
177 +\r
178 +(defun notmuch-show-part-button-view-action (&optional button)\r
179 +  (interactive)\r
180 +  (let ((button (or button (button-at (point)))))\r
181 +    (if (not button)\r
182 +       nil\r
183 +      (let ((nth (button-get button :notmuch-part)))\r
184 +       (if nth\r
185 +           (notmuch-show-view-part (notmuch-show-get-message-id) nth\r
186 +                                   (button-get button :notmuch-content-type))\r
187 +         (message "Not a valid part (is it a fake part?)."))))))\r
188 +\r
189 +(defun notmuch-show-part-button-interactively-view-action (&optional button)\r
190 +  (interactive)\r
191 +  (let ((button (or button (button-at (point)))))\r
192 +    (if (not button)\r
193 +       nil\r
194 +      (let ((nth (button-get button :notmuch-part)))\r
195 +       (if nth\r
196 +           (notmuch-show-interactively-view-part (notmuch-show-get-message-id) nth\r
197 +                                   (button-get button :notmuch-content-type))\r
198 +         (message "Not a valid part (is it a fake part?)."))))))\r
199  \r
200  ;;\r
201  \r
202 -- \r
203 1.7.1\r
204 \r