Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 5c / 7217a4a4dbe540bbd96e0b880b194806cd0eb1
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 285DD431FBF\r
6         for <notmuch@notmuchmail.org>; Mon, 19 Jan 2015 12:06:45 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 1.34\r
10 X-Spam-Level: *\r
11 X-Spam-Status: No, score=1.34 tagged_above=-999 required=5\r
12         tests=[DKIM_ADSP_CUSTOM_MED=0.001, DNS_FROM_AHBL_RHSBL=2.438,\r
13         FREEMAIL_FROM=0.001, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3]\r
14         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 tCxYbcCPum0r for <notmuch@notmuchmail.org>;\r
18         Mon, 19 Jan 2015 12:06:42 -0800 (PST)\r
19 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
20         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
21         (No client certificate requested)\r
22         by olra.theworths.org (Postfix) with ESMTPS id 8BF8F431FB6\r
23         for <notmuch@notmuchmail.org>; Mon, 19 Jan 2015 12:06:41 -0800 (PST)\r
24 Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
25         by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
26         (envelope-from <m.walters@qmul.ac.uk>)\r
27         id 1YDIan-00089h-8F; Mon, 19 Jan 2015 20:06:35 +0000\r
28 Received: from 5751dfa2.skybroadband.com ([87.81.223.162] helo=localhost)\r
29         by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71)\r
30         (envelope-from <m.walters@qmul.ac.uk>)\r
31         id 1YDIam-0006iC-US; Mon, 19 Jan 2015 20:06:33 +0000\r
32 From: Mark Walters <markwalters1009@gmail.com>\r
33 To: David Edmondson <dme@dme.org>, notmuch@notmuchmail.org\r
34 Subject: Re: [PATCH v3 8/9] emacs/mua: Insert part headers depending on the\r
35         message\r
36 In-Reply-To: <1399897769-26809-9-git-send-email-dme@dme.org>\r
37 References: <87sixdujkv.fsf@qmul.ac.uk>\r
38         <1399897769-26809-1-git-send-email-dme@dme.org>\r
39         <1399897769-26809-9-git-send-email-dme@dme.org>\r
40 User-Agent: Notmuch/0.18.1+86~gef5e66a (http://notmuchmail.org) Emacs/24.4.1\r
41         (x86_64-pc-linux-gnu)\r
42 Date: Mon, 19 Jan 2015 20:06:51 +0000\r
43 Message-ID: <87h9vmk010.fsf@qmul.ac.uk>\r
44 MIME-Version: 1.0\r
45 Content-Type: text/plain\r
46 X-Sender-Host-Address: 87.81.223.162\r
47 X-QM-Geographic: According to ripencc,\r
48         this message was delivered by a machine in Britain (UK) (GB).\r
49 X-QM-SPAM-Info: Sender has good ham record.  :)\r
50 X-QM-Body-MD5: 4265275bf0d9b37ac3af025d02a6e314 (of first 20000 bytes)\r
51 X-SpamAssassin-Score: -0.1\r
52 X-SpamAssassin-SpamBar: /\r
53 X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
54         determine if it is\r
55         spam. We require at least 5.0 points to mark a message as spam.\r
56         This message scored -0.1 points.\r
57         Summary of the scoring: \r
58         * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
59         provider *      (markwalters1009[at]gmail.com)\r
60         * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
61         *      domain\r
62         * -0.1 AWL AWL: Adjusted score from AWL reputation of From: address\r
63 X-QM-Scan-Virus: ClamAV says the message is clean\r
64 X-BeenThere: notmuch@notmuchmail.org\r
65 X-Mailman-Version: 2.1.13\r
66 Precedence: list\r
67 List-Id: "Use and development of the notmuch mail system."\r
68         <notmuch.notmuchmail.org>\r
69 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
71 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
72 List-Post: <mailto:notmuch@notmuchmail.org>\r
73 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
74 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
75         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
76 X-List-Received-Date: Mon, 19 Jan 2015 20:06:45 -0000\r
77 \r
78 \r
79 On Mon, 12 May 2014, David Edmondson <dme@dme.org> wrote:\r
80 > Whether to insert part headers should depend on the details of the\r
81 > message being cited.\r
82 \r
83 Hi\r
84 \r
85 Overall I like this series and it does fix two annoying bugs (not being\r
86 able to reply to ref822 messages and (correctly) including parts\r
87 which have application/octet-stream but are actually text parts).\r
88 \r
89 The one problem is getting the right choice for part headers in the\r
90 reply text. I think getting this wrong will irritate users even if the\r
91 overall result is better.\r
92 \r
93 My guess at the correct logic is:\r
94 1) omit the part header for any empty part: (ie a part we don't display\r
95 such as a pdf file).\r
96 2) omit multipart/* part headers\r
97 3) include all other part headers\r
98 4) except omit the first part header (perhaps only in the case it is text/plain)\r
99 \r
100 My reasoning for each is\r
101 1) there is no point in saying we had a part which we are omitting.\r
102 2) all the subparts of multipart/* will get there own header which\r
103 should be sufficient.\r
104 3) we want to keep the parts distinguished\r
105 4) except we don't need to do that with the first part.\r
106 \r
107 Note for 4) it would be good to have a multipart/alternative with\r
108 subparts text/plain and text/html just give the text/plain with no part\r
109 header.\r
110 \r
111 I include a patch below which does all of these apart from 4) as I\r
112 couldn't see a clean way of implementing it. Any suggestions?\r
113 \r
114 It should apply on top of patch 6 or 7 instead of 8. The key change is\r
115 that it always puts in a button and then deletes it if unwanted: this\r
116 makes doing 1) above easy. \r
117 \r
118 It does break some tests, nothing unexpected except an interaction with\r
119 the way we wash text/plain parts: we remove leading blank lines from the\r
120 first text/plain part (because it doesn't have a button) but not from\r
121 subsequent ones (because they do). Because this code always has the\r
122 second case it doesn't remove a leading blank line of the first part.\r
123 \r
124 Best wishes\r
125 \r
126 Mark\r
127 \r
128 \r
129 >From 8f198b38e76e050ae8d20d866748c41ccf79f3d4 Mon Sep 17 00:00:00 2001\r
130 From: Mark Walters <markwalters1009@gmail.com>\r
131 Date: Mon, 19 Jan 2015 14:39:25 +0000\r
132 Subject: [PATCH] emacs show/reply modify part handling\r
133 \r
134 Modify the part handling so that we always insert the button and\r
135 delete it afterwards if not wanted. The advantage is that we can\r
136 decide whether to keep the part button based on what the insertion\r
137 code does. In particular the reply code can omit the button for all\r
138 parts with no displayable content.\r
139 ---\r
140  emacs/notmuch-mua.el  |  5 +++--\r
141  emacs/notmuch-show.el | 39 +++++++++++++++++++++++++--------------\r
142  2 files changed, 28 insertions(+), 16 deletions(-)\r
143 \r
144 diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
145 index 0ca9eed..6060f33 100644\r
146 --- a/emacs/notmuch-mua.el\r
147 +++ b/emacs/notmuch-mua.el\r
148 @@ -29,6 +29,7 @@\r
149  (eval-when-compile (require 'cl))\r
150  \r
151  (declare-function notmuch-show-insert-body "notmuch-show" (msg body depth))\r
152 +(declare-function notmuch-show-insert-header-p-reply "notmuch-show" (part empty-part))\r
153  \r
154  ;;\r
155  \r
156 @@ -223,8 +224,8 @@ Note that these functions use `mail-citation-hook' if that is non-nil."\r
157                       ;; citations, etc. in the original message before\r
158                       ;; quoting.\r
159                       ((notmuch-show-insert-text/plain-hook nil)\r
160 -                      ;; Don't insert part buttons.\r
161 -                      (notmuch-show-insert-header-p-function #'notmuch-show-insert-header-p-never))\r
162 +                      ;; Insert part buttons appropriate for a reply.\r
163 +                      (notmuch-show-insert-header-p-function #'notmuch-show-insert-header-p-reply))\r
164                     (notmuch-show-insert-body original (plist-get original :body) 0)\r
165                     (buffer-substring-no-properties (point-min) (point-max)))))\r
166  \r
167 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
168 index 4a0899f..2cdb5a8 100644\r
169 --- a/emacs/notmuch-show.el\r
170 +++ b/emacs/notmuch-show.el\r
171 @@ -909,16 +909,24 @@ message at DEPTH in the current thread."\r
172              "text/x-diff")\r
173         content-type)))\r
174  \r
175 -(defun notmuch-show-insert-header-p-smart (part)\r
176 +(defun notmuch-show-insert-header-p-smart (part empty-part)\r
177    "Return non-NIL if a header button should be inserted for this part."\r
178    (let ((mime-type (notmuch-show-mime-type part)))\r
179      (not (and (string= mime-type "text/plain")\r
180               (<= (plist-get part :id) 1)))))\r
181  \r
182 -(defun notmuch-show-insert-header-p-always (part)\r
183 +(defun notmuch-show-insert-header-p-reply (part empty-part)\r
184 +  "Return non-NIL if a header button should be inserted for this part."\r
185 +  (let ((mime-type (notmuch-show-mime-type part)))\r
186 +    (not (or empty-part\r
187 +            (notmuch-match-content-type mime-type "multipart/*")\r
188 +            (and (string= mime-type "text/plain")\r
189 +                 (<= (plist-get part :id) 1))))))\r
190 +\r
191 +(defun notmuch-show-insert-header-p-always (part empty-part)\r
192    t)\r
193  \r
194 -(defun notmuch-show-insert-header-p-never (part)\r
195 +(defun notmuch-show-insert-header-p-never (part empty-part)\r
196    nil)\r
197  \r
198  (defun notmuch-show-insert-bodypart (msg part depth &optional hide)\r
199 @@ -936,8 +944,8 @@ is t, hide the part initially and show the button."\r
200          (show-part (not (equal hide t)))\r
201          ;; We omit the part button for the first (or only) part if\r
202          ;; this is text/plain.\r
203 -        (button (when (funcall notmuch-show-insert-header-p-function part)\r
204 -                  (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename))))\r
205 +        (button-beg (point))\r
206 +        (button (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename)))\r
207          (content-beg (point)))\r
208  \r
209      ;; Store the computed mime-type for later use (e.g. by attachment handlers).\r
210 @@ -952,15 +960,18 @@ is t, hide the part initially and show the button."\r
211      ;; Some of the body part handlers leave point somewhere up in the\r
212      ;; part, so we make sure that we're down at the end.\r
213      (goto-char (point-max))\r
214 -    ;; Ensure that the part ends with a carriage return.\r
215 -    (unless (bolp)\r
216 -      (insert "\n"))\r
217 -    ;; We do not create the overlay for hidden (lazy) parts until\r
218 -    ;; they are inserted.\r
219 -    (if show-part\r
220 -       (notmuch-show-create-part-overlays button content-beg (point))\r
221 -      (save-excursion\r
222 -       (notmuch-show-toggle-part-invisibility button)))\r
223 +    (let ((empty-part (equal (point) content-beg)))\r
224 +      (if (not (funcall notmuch-show-insert-header-p-function part empty-part))\r
225 +         (delete-region button-beg content-beg)\r
226 +       ;; Ensure that the part ends with a carriage return.\r
227 +       (unless (bolp)\r
228 +         (insert "\n"))\r
229 +       ;; We do not create the overlay for hidden (lazy) parts until\r
230 +       ;; they are inserted.\r
231 +       (if show-part\r
232 +           (notmuch-show-create-part-overlays button content-beg (point))\r
233 +         (save-excursion\r
234 +           (notmuch-show-toggle-part-invisibility button)))))\r
235      (notmuch-show-record-part-information part beg (point))))\r
236  \r
237  (defun notmuch-show-insert-body (msg body depth)\r
238 -- \r
239 2.1.3\r
240 \r
241 \r