Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / 28 / 971d9165716bf8b85731d2579554fbc3085ad1
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 B8577429E37\r
6         for <notmuch@notmuchmail.org>; Fri, 31 May 2013 11:27:27 -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: 0.201\r
10 X-Spam-Level: \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 rquC8vM5X4m8 for <notmuch@notmuchmail.org>;\r
18         Fri, 31 May 2013 11:27:21 -0700 (PDT)\r
19 Received: from mail-we0-f174.google.com (mail-we0-f174.google.com\r
20         [74.125.82.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
21         (No client certificate requested)\r
22         by olra.theworths.org (Postfix) with ESMTPS id BA5CE431E82\r
23         for <notmuch@notmuchmail.org>; Fri, 31 May 2013 11:27:19 -0700 (PDT)\r
24 Received: by mail-we0-f174.google.com with SMTP id q58so11013wes.19\r
25         for <notmuch@notmuchmail.org>; Fri, 31 May 2013 11:27:18 -0700 (PDT)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
27         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
28         bh=sRQMfgY5zcTiPpY3xxDQ7CzvbManorE350bGLelpo3I=;\r
29         b=Li0GWw/sv/wqhTjrNmhGShC2srqZd7O5RyF6KaFyojU+MTOiyAa+EAGow5+VuCDZbx\r
30         sctZU+D43k90yR4ilpTFqQ+GpYkyayKKl8ffzKH+AUH4Ki83akvqdZT5qzDWx/TN3FC0\r
31         JCqXeiVDsWBavBt/ZLGlCH76RCB0x+uN0MUe6R0fP8WeDVVLbJbEqhxUceXcq1BlLWZ4\r
32         sRvmESfVqIqcX31j5WmXGNN1WsFZAIlSKGZ81hG6DK9dggr9DJmJYnCbHDn+woW9vDb3\r
33         1iMqXqTrXb3t9Mx+P1/87nZT+Hi9ILHg1QltuMumqLEjbH4m4KUHz0o3XEa+otgprLcL\r
34         a9lw==\r
35 X-Received: by 10.181.11.194 with SMTP id ek2mr4510494wid.27.1370024838686;\r
36         Fri, 31 May 2013 11:27:18 -0700 (PDT)\r
37 Received: from localhost (92.40.240.237.threembb.co.uk. [92.40.240.237])\r
38         by mx.google.com with ESMTPSA id hl6sm5736692wib.2.2013.05.31.11.27.16\r
39         for <multiple recipients>\r
40         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
41         Fri, 31 May 2013 11:27:18 -0700 (PDT)\r
42 From: Mark Walters <markwalters1009@gmail.com>\r
43 To: notmuch@notmuchmail.org, Austin Clements <aclements@csail.mit.edu>,\r
44         Adam Wolfe Gordon <awg+notmuch@xvx.ca>\r
45 Subject: [PATCH v3 2/5] emacs: show: move the insertion of the header button\r
46         to the top level\r
47 Date: Fri, 31 May 2013 19:26:43 +0100\r
48 Message-Id: <1370024806-6616-3-git-send-email-markwalters1009@gmail.com>\r
49 X-Mailer: git-send-email 1.7.10.4\r
50 In-Reply-To: <1370024806-6616-1-git-send-email-markwalters1009@gmail.com>\r
51 References: <1370024806-6616-1-git-send-email-markwalters1009@gmail.com>\r
52 X-BeenThere: notmuch@notmuchmail.org\r
53 X-Mailman-Version: 2.1.13\r
54 Precedence: list\r
55 List-Id: "Use and development of the notmuch mail system."\r
56         <notmuch.notmuchmail.org>\r
57 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
58         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
59 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
60 List-Post: <mailto:notmuch@notmuchmail.org>\r
61 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
62 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
64 X-List-Received-Date: Fri, 31 May 2013 18:27:28 -0000\r
65 \r
66 Previously each of the part insertion handlers inserted the part\r
67 button themselves. Move this up into\r
68 notmuch-show-insert-bodypart. Since a small number of the handlers\r
69 modify the button (the encryption/signature ones) we need to pass the\r
70 header button as an argument into the individual part insertion\r
71 handlers. However, the declared-type argument was only used for the\r
72 text for the part buttons we can now omit it.\r
73 \r
74 The patch is large but mostly simple. The only things of note are that\r
75 we let the text/plain handler applies notmuch-wash to the whole part\r
76 including the part button (otherwise rendering is slightly changed and\r
77 tests fail).\r
78 ---\r
79  emacs/notmuch-show.el |   97 ++++++++++++++++++++++++-------------------------\r
80  1 file changed, 47 insertions(+), 50 deletions(-)\r
81 \r
82 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
83 index fd14469..be3aeac 100644\r
84 --- a/emacs/notmuch-show.el\r
85 +++ b/emacs/notmuch-show.el\r
86 @@ -572,8 +572,7 @@ message at DEPTH in the current thread."\r
87    (mapcar (lambda (inner-part) (plist-get inner-part :content-type))\r
88           (plist-get part :content)))\r
89  \r
90 -(defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type)\r
91 -  (notmuch-show-insert-part-header nth declared-type content-type nil)\r
92 +(defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth button)\r
93    (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))\r
94         (inner-parts (plist-get part :content))\r
95         (start (point)))\r
96 @@ -650,8 +649,7 @@ message at DEPTH in the current thread."\r
97           content-type)\r
98        nil)))\r
99  \r
100 -(defun notmuch-show-insert-part-multipart/related (msg part content-type nth depth declared-type)\r
101 -  (notmuch-show-insert-part-header nth declared-type content-type nil)\r
102 +(defun notmuch-show-insert-part-multipart/related (msg part content-type nth depth button)\r
103    (let ((inner-parts (plist-get part :content))\r
104         (start (point)))\r
105  \r
106 @@ -670,16 +668,15 @@ message at DEPTH in the current thread."\r
107        (indent-rigidly start (point) 1)))\r
108    t)\r
109  \r
110 -(defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth declared-type)\r
111 -  (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil)))\r
112 -    (button-put button 'face 'notmuch-crypto-part-header)\r
113 -    ;; add signature status button if sigstatus provided\r
114 -    (if (plist-member part :sigstatus)\r
115 -       (let* ((from (notmuch-show-get-header :From msg))\r
116 -              (sigstatus (car (plist-get part :sigstatus))))\r
117 -         (notmuch-crypto-insert-sigstatus-button sigstatus from))\r
118 -      ;; if we're not adding sigstatus, tell the user how they can get it\r
119 -      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
120 +(defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth button)\r
121 +  (button-put button 'face 'notmuch-crypto-part-header)\r
122 +  ;; add signature status button if sigstatus provided\r
123 +  (if (plist-member part :sigstatus)\r
124 +      (let* ((from (notmuch-show-get-header :From msg))\r
125 +            (sigstatus (car (plist-get part :sigstatus))))\r
126 +       (notmuch-crypto-insert-sigstatus-button sigstatus from))\r
127 +    ;; if we're not adding sigstatus, tell the user how they can get it\r
128 +    (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts."))\r
129  \r
130    (let ((inner-parts (plist-get part :content))\r
131         (start (point)))\r
132 @@ -692,20 +689,19 @@ message at DEPTH in the current thread."\r
133        (indent-rigidly start (point) 1)))\r
134    t)\r
135  \r
136 -(defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth declared-type)\r
137 -  (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil)))\r
138 -    (button-put button 'face 'notmuch-crypto-part-header)\r
139 -    ;; add encryption status button if encstatus specified\r
140 -    (if (plist-member part :encstatus)\r
141 -       (let ((encstatus (car (plist-get part :encstatus))))\r
142 -         (notmuch-crypto-insert-encstatus-button encstatus)\r
143 -         ;; add signature status button if sigstatus specified\r
144 -         (if (plist-member part :sigstatus)\r
145 -             (let* ((from (notmuch-show-get-header :From msg))\r
146 -                    (sigstatus (car (plist-get part :sigstatus))))\r
147 -               (notmuch-crypto-insert-sigstatus-button sigstatus from))))\r
148 -      ;; if we're not adding encstatus, tell the user how they can get it\r
149 -      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
150 +(defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth button)\r
151 +  (button-put button 'face 'notmuch-crypto-part-header)\r
152 +  ;; add encryption status button if encstatus specified\r
153 +  (if (plist-member part :encstatus)\r
154 +      (let ((encstatus (car (plist-get part :encstatus))))\r
155 +       (notmuch-crypto-insert-encstatus-button encstatus)\r
156 +       ;; add signature status button if sigstatus specified\r
157 +       (if (plist-member part :sigstatus)\r
158 +           (let* ((from (notmuch-show-get-header :From msg))\r
159 +                  (sigstatus (car (plist-get part :sigstatus))))\r
160 +             (notmuch-crypto-insert-sigstatus-button sigstatus from))))\r
161 +    ;; if we're not adding encstatus, tell the user how they can get it\r
162 +    (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts."))\r
163  \r
164    (let ((inner-parts (plist-get part :content))\r
165         (start (point)))\r
166 @@ -718,8 +714,7 @@ message at DEPTH in the current thread."\r
167        (indent-rigidly start (point) 1)))\r
168    t)\r
169  \r
170 -(defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth declared-type)\r
171 -  (notmuch-show-insert-part-header nth declared-type content-type nil)\r
172 +(defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth button)\r
173    (let ((inner-parts (plist-get part :content))\r
174         (start (point)))\r
175      ;; Show all of the parts.\r
176 @@ -731,8 +726,7 @@ message at DEPTH in the current thread."\r
177        (indent-rigidly start (point) 1)))\r
178    t)\r
179  \r
180 -(defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth declared-type)\r
181 -  (notmuch-show-insert-part-header nth declared-type content-type nil)\r
182 +(defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth button)\r
183    (let* ((message (car (plist-get part :content)))\r
184          (body (car (plist-get message :body)))\r
185          (start (point)))\r
186 @@ -753,12 +747,13 @@ message at DEPTH in the current thread."\r
187        (indent-rigidly start (point) 1)))\r
188    t)\r
189  \r
190 -(defun notmuch-show-insert-part-text/plain (msg part content-type nth depth declared-type)\r
191 -  (let ((start (point)))\r
192 -    ;; If this text/plain part is not the first part in the message,\r
193 -    ;; insert a header to make this clear.\r
194 -    (if (> nth 1)\r
195 -       (notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename)))\r
196 +(defun notmuch-show-insert-part-text/plain (msg part content-type nth depth button)\r
197 +  ;; For backward compatibility we want to apply the text/plain hook\r
198 +  ;; to the whole of the part including the part button if there is\r
199 +  ;; one.\r
200 +  (let ((start (if button\r
201 +                  (button-start button)\r
202 +                (point))))\r
203      (insert (notmuch-get-bodypart-content msg part nth notmuch-show-process-crypto))\r
204      (save-excursion\r
205        (save-restriction\r
206 @@ -766,8 +761,7 @@ message at DEPTH in the current thread."\r
207         (run-hook-with-args 'notmuch-show-insert-text/plain-hook msg depth))))\r
208    t)\r
209  \r
210 -(defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth declared-type)\r
211 -  (notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename))\r
212 +(defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth button)\r
213    (insert (with-temp-buffer\r
214             (insert (notmuch-get-bodypart-content msg part nth notmuch-show-process-crypto))\r
215             ;; notmuch-get-bodypart-content provides "raw", non-converted\r
216 @@ -790,8 +784,8 @@ message at DEPTH in the current thread."\r
217    t)\r
218  \r
219  ;; For backwards compatibility.\r
220 -(defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth declared-type)\r
221 -  (notmuch-show-insert-part-text/calendar msg part content-type nth depth declared-type))\r
222 +(defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth button)\r
223 +  (notmuch-show-insert-part-text/calendar msg part content-type nth depth button))\r
224  \r
225  (defun notmuch-show-get-mime-type-of-application/octet-stream (part)\r
226    ;; If we can deduce a MIME type from the filename of the attachment,\r
227 @@ -809,7 +803,7 @@ message at DEPTH in the current thread."\r
228                 nil))\r
229           nil))))\r
230  \r
231 -(defun notmuch-show-insert-part-text/html (msg part content-type nth depth declared-type)\r
232 +(defun notmuch-show-insert-part-text/html (msg part content-type nth depth button)\r
233    ;; text/html handler to work around bugs in renderers and our\r
234    ;; invisibile parts code. In particular w3m sets up a keymap which\r
235    ;; "leaks" outside the invisible region and causes strange effects\r
236 @@ -817,11 +811,10 @@ message at DEPTH in the current thread."\r
237    ;; tell w3m not to set a keymap (so the normal notmuch-show-mode-map\r
238    ;; remains).\r
239    (let ((mm-inline-text-html-with-w3m-keymap nil))\r
240 -    (notmuch-show-insert-part-*/* msg part content-type nth depth declared-type)))\r
241 +    (notmuch-show-insert-part-*/* msg part content-type nth depth button)))\r
242  \r
243 -(defun notmuch-show-insert-part-*/* (msg part content-type nth depth declared-type)\r
244 +(defun notmuch-show-insert-part-*/* (msg part content-type nth depth button)\r
245    ;; This handler _must_ succeed - it is the handler of last resort.\r
246 -  (notmuch-show-insert-part-header nth content-type declared-type (plist-get part :filename))\r
247    (notmuch-mm-display-part-inline msg part nth content-type notmuch-show-process-crypto)\r
248    t)\r
249  \r
250 @@ -844,13 +837,13 @@ message at DEPTH in the current thread."\r
251  \r
252  ;; \f\r
253 \r
254  \r
255 -(defun notmuch-show-insert-bodypart-internal (msg part content-type nth depth declared-type)\r
256 +(defun notmuch-show-insert-bodypart-internal (msg part content-type nth depth button)\r
257    (let ((handlers (notmuch-show-handlers-for content-type)))\r
258      ;; Run the content handlers until one of them returns a non-nil\r
259      ;; value.\r
260      (while (and handlers\r
261                 (not (condition-case err\r
262 -                        (funcall (car handlers) msg part content-type nth depth declared-type)\r
263 +                        (funcall (car handlers) msg part content-type nth depth button)\r
264                        (error (progn\r
265                                 (insert "!!! Bodypart insert error: ")\r
266                                 (insert (error-message-string err))\r
267 @@ -878,6 +871,7 @@ message at DEPTH in the current thread."\r
268    "Insert the body part PART at depth DEPTH in the current thread.\r
269  \r
270  If HIDE is non-nil then initially hide this part."\r
271 +\r
272    (let* ((content-type (downcase (plist-get part :content-type)))\r
273          (mime-type (or (and (string= content-type "application/octet-stream")\r
274                              (notmuch-show-get-mime-type-of-application/octet-stream part))\r
275 @@ -885,9 +879,12 @@ If HIDE is non-nil then initially hide this part."\r
276                              "text/x-diff")\r
277                         content-type))\r
278          (nth (plist-get part :id))\r
279 -        (beg (point)))\r
280 +        (beg (point))\r
281 +        ;; We omit the part button for the first (or only) part if this is text/plain.\r
282 +        (button (unless (and (string= mime-type "text/plain") (<= nth 1))\r
283 +                  (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename)))))\r
284  \r
285 -    (notmuch-show-insert-bodypart-internal msg part mime-type nth depth content-type)\r
286 +    (notmuch-show-insert-bodypart-internal msg part mime-type nth depth button)\r
287      ;; Some of the body part handlers leave point somewhere up in the\r
288      ;; part, so we make sure that we're down at the end.\r
289      (goto-char (point-max))\r
290 -- \r
291 1.7.10.4\r
292 \r