[PATCH v2.1 2/2] emacs: Correctly quote non-text/plain parts in reply
[notmuch-archives.git] / bb / 103455d7c3cd585992321ddc682fbfc59a2703
1 Return-Path: <awg@lagos.xvx.ca>\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 D0847431FC4\r
6         for <notmuch@notmuchmail.org>; Sat,  5 May 2012 12:30:43 -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\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_NONE=-0.0001] 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 O34nL2TRqTBk for <notmuch@notmuchmail.org>;\r
16         Sat,  5 May 2012 12:30:43 -0700 (PDT)\r
17 Received: from smtp-out-04.shaw.ca (smtp-out-04.shaw.ca [64.59.134.12])\r
18         by olra.theworths.org (Postfix) with ESMTP id 0D00D431FAE\r
19         for <notmuch@notmuchmail.org>; Sat,  5 May 2012 12:30:42 -0700 (PDT)\r
20 Received: from lb7f8hsrpno-svcs.dcs.int.inet (HELO pd7ml2no-ssvc.prod.shaw.ca)\r
21         ([10.0.144.222])\r
22         by pd5mo1no-svcs.prod.shaw.ca with ESMTP; 05 May 2012 13:30:42 -0600\r
23 X-Cloudmark-SP-Filtered: true\r
24 X-Cloudmark-SP-Result: v=1.1 cv=GZn8e3lTBEeJrlGK3+GUWyR5aYe1SJcDn5uEERMe9yQ=\r
25         c=1 sm=1\r
26         a=T8ybgwlJkKYA:10 a=BLceEmwcHowA:10 a=yQp6g8lIsgqumF79BAsFDg==:17\r
27         a=B535l3t0i191nsDIXDgA:9 a=buOBQ8xC_Aqx9VmyuMkA:7\r
28         a=HpAAvcLHHh0Zw7uRqdWCyQ==:117\r
29 Received: from unknown (HELO lagos.xvx.ca) ([96.52.216.56])\r
30         by pd7ml2no-dmz.prod.shaw.ca with ESMTP; 05 May 2012 13:30:41 -0600\r
31 Received: by lagos.xvx.ca (Postfix, from userid 1000)\r
32         id B60D68004203; Sat,  5 May 2012 13:30:41 -0600 (MDT)\r
33 From: Adam Wolfe Gordon <awg+notmuch@xvx.ca>\r
34 To: notmuch@notmuchmail.org\r
35 Subject: [PATCH v2.1 2/2] emacs: Correctly quote non-text/plain parts in reply\r
36 Date: Sat,  5 May 2012 13:30:37 -0600\r
37 Message-Id: <1336246237-4888-1-git-send-email-awg+notmuch@xvx.ca>\r
38 X-Mailer: git-send-email 1.7.5.4\r
39 In-Reply-To: <1336245869-32699-3-git-send-email-awg+notmuch@xvx.ca>\r
40 References: <1336245869-32699-3-git-send-email-awg+notmuch@xvx.ca>\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.13\r
43 Precedence: list\r
44 List-Id: "Use and development of the notmuch mail system."\r
45         <notmuch.notmuchmail.org>\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
49 List-Post: <mailto:notmuch@notmuchmail.org>\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
53 X-List-Received-Date: Sat, 05 May 2012 19:30:44 -0000\r
54 \r
55 Quote non-text parts nicely by displaying them with mm-display-part\r
56 before calling message-cite-original to quote them. HTML-only emails\r
57 can now be quoted correctly. We re-use some code from notmuch-show\r
58 (notmuch-show-mm-display-part-inline), which has been moved to\r
59 notmuch-lib.el.\r
60 \r
61 Mark the test for this feature as not broken.\r
62 ---\r
63 I had removed the narrowing from this patch to check whether it was\r
64 actually necessary (it is), and forgot to put it back in. Here is \r
65 a corrected patch.\r
66 \r
67  emacs/notmuch-lib.el  |   19 +++++++++++++++++++\r
68  emacs/notmuch-mua.el  |   15 ++++++++++-----\r
69  emacs/notmuch-show.el |   19 +------------------\r
70  test/emacs            |    1 -\r
71  4 files changed, 30 insertions(+), 24 deletions(-)\r
72 \r
73 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
74 index 6907a5f..7fa441a 100644\r
75 --- a/emacs/notmuch-lib.el\r
76 +++ b/emacs/notmuch-lib.el\r
77 @@ -21,6 +21,8 @@\r
78  \r
79  ;; This is an part of an emacs-based interface to the notmuch mail system.\r
80  \r
81 +(require 'mm-view)\r
82 +(require 'mm-decode)\r
83  (eval-when-compile (require 'cl))\r
84  \r
85  (defvar notmuch-command "notmuch"\r
86 @@ -237,6 +239,23 @@ the given type."\r
87    (or (plist-get part :content)\r
88        (notmuch-get-bodypart-internal (notmuch-id-to-query (plist-get msg :id)) nth process-crypto)))\r
89  \r
90 +(defun notmuch-mm-display-part-inline (msg part nth content-type process-crypto)\r
91 +  "Use the mm-decode/mm-view functions to display a part in the\r
92 +current buffer, if possible."\r
93 +  (let ((display-buffer (current-buffer)))\r
94 +    (with-temp-buffer\r
95 +      (let* ((charset (plist-get part :content-charset))\r
96 +            (handle (mm-make-handle (current-buffer) `(,content-type (charset . ,charset)))))\r
97 +       ;; If the user wants the part inlined, insert the content and\r
98 +       ;; test whether we are able to inline it (which includes both\r
99 +       ;; capability and suitability tests).\r
100 +       (when (mm-inlined-p handle)\r
101 +         (insert (notmuch-get-bodypart-content msg part nth process-crypto))\r
102 +         (when (mm-inlinable-p handle)\r
103 +           (set-buffer display-buffer)\r
104 +           (mm-display-part handle)\r
105 +           t))))))\r
106 +\r
107  ;; Converts a plist of headers to an alist of headers. The input plist should\r
108  ;; have symbols of the form :Header as keys, and the resulting alist will have\r
109  ;; symbols of the form 'Header as keys.\r
110 diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
111 index 87bd88d..fc7ae07 100644\r
112 --- a/emacs/notmuch-mua.el\r
113 +++ b/emacs/notmuch-mua.el\r
114 @@ -21,6 +21,7 @@\r
115  \r
116  (require 'json)\r
117  (require 'message)\r
118 +(require 'mm-view)\r
119  (require 'format-spec)\r
120  \r
121  (require 'notmuch-lib)\r
122 @@ -90,6 +91,14 @@ list."\r
123         else if (notmuch-match-content-type (plist-get part :content-type) "text/*")\r
124           collect part))\r
125  \r
126 +(defun notmuch-mua-insert-quotable-part (message part)\r
127 +  (save-restriction\r
128 +    (narrow-to-region (point) (point))\r
129 +    (notmuch-mm-display-part-inline message part (plist-get part :id)\r
130 +                                   (plist-get part :content-type)\r
131 +                                   notmuch-show-process-crypto)\r
132 +    (goto-char (point-max))))\r
133 +\r
134  ;; There is a bug in emacs 23's message.el that results in a newline\r
135  ;; not being inserted after the References header, so the next header\r
136  ;; is concatenated to the end of it. This function fixes the problem,\r
137 @@ -169,11 +178,7 @@ list."\r
138         ;; Get the parts of the original message that should be quoted; this includes\r
139         ;; all the text parts, except the non-preferred ones in a multipart/alternative.\r
140         (let ((quotable-parts (notmuch-mua-get-quotable-parts (plist-get original :body))))\r
141 -         (mapc (lambda (part)\r
142 -                 (insert (notmuch-get-bodypart-content original part\r
143 -                                                       (plist-get part :id)\r
144 -                                                       notmuch-show-process-crypto)))\r
145 -               quotable-parts))\r
146 +         (mapc (apply-partially 'notmuch-mua-insert-quotable-part original) quotable-parts))\r
147  \r
148         (set-mark (point))\r
149         (goto-char start)\r
150 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
151 index 37f0ebb..d318430 100644\r
152 --- a/emacs/notmuch-show.el\r
153 +++ b/emacs/notmuch-show.el\r
154 @@ -524,23 +524,6 @@ message at DEPTH in the current thread."\r
155      (let ((handle (mm-make-handle (current-buffer) (list content-type))))\r
156        (mm-interactively-view-part handle))))\r
157  \r
158 -(defun notmuch-show-mm-display-part-inline (msg part nth content-type)\r
159 -  "Use the mm-decode/mm-view functions to display a part in the\r
160 -current buffer, if possible."\r
161 -  (let ((display-buffer (current-buffer)))\r
162 -    (with-temp-buffer\r
163 -      (let* ((charset (plist-get part :content-charset))\r
164 -            (handle (mm-make-handle (current-buffer) `(,content-type (charset . ,charset)))))\r
165 -       ;; If the user wants the part inlined, insert the content and\r
166 -       ;; test whether we are able to inline it (which includes both\r
167 -       ;; capability and suitability tests).\r
168 -       (when (mm-inlined-p handle)\r
169 -         (insert (notmuch-get-bodypart-content msg part nth notmuch-show-process-crypto))\r
170 -         (when (mm-inlinable-p handle)\r
171 -           (set-buffer display-buffer)\r
172 -           (mm-display-part handle)\r
173 -           t))))))\r
174 -\r
175  (defun notmuch-show-multipart/*-to-list (part)\r
176    (mapcar (lambda (inner-part) (plist-get inner-part :content-type))\r
177           (plist-get part :content)))\r
178 @@ -785,7 +768,7 @@ current buffer, if possible."\r
179  (defun notmuch-show-insert-part-*/* (msg part content-type nth depth declared-type)\r
180    ;; This handler _must_ succeed - it is the handler of last resort.\r
181    (notmuch-show-insert-part-header nth content-type declared-type (plist-get part :filename))\r
182 -  (notmuch-show-mm-display-part-inline msg part nth content-type)\r
183 +  (notmuch-mm-display-part-inline msg part nth content-type notmuch-show-process-crypto)\r
184    t)\r
185  \r
186  ;; Functions for determining how to handle MIME parts.\r
187 diff --git a/test/emacs b/test/emacs\r
188 index 5f238d9..a615b39 100755\r
189 --- a/test/emacs\r
190 +++ b/test/emacs\r
191 @@ -445,7 +445,6 @@ EOF\r
192  test_expect_equal_file OUTPUT EXPECTED\r
193  \r
194  test_begin_subtest "Reply within emacs to an html-only message"\r
195 -test_subtest_known_broken\r
196  add_message '[content-type]="text/html"' \\r
197             '[body]="Hi,<br />This is an <b>HTML</b> test message.<br /><br />OK?"'\r
198  test_emacs "(let ((message-hidden-headers '()))\r
199 -- \r
200 1.7.5.4\r
201 \r