[PATCH v2 04/14] cli/reply: unify reply format functions
[notmuch-archives.git] / 2d / c2cc69f40db938f86ec8e822401cd8d025f084
1 Return-Path: <dme@dme.org>\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 7D9BC431FAF\r
6         for <notmuch@notmuchmail.org>; Wed,  7 May 2014 10:14:16 -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.7\r
10 X-Spam-Level: \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 j8ns2fPvtHRO for <notmuch@notmuchmail.org>;\r
16         Wed,  7 May 2014 10:14:11 -0700 (PDT)\r
17 Received: from mail-wg0-f46.google.com (mail-wg0-f46.google.com\r
18  [74.125.82.46])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
19  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
20  C50EB431FAE    for <notmuch@notmuchmail.org>; Wed,  7 May 2014 10:14:10 -0700\r
21  (PDT)\r
22 Received: by mail-wg0-f46.google.com with SMTP id n12so1329235wgh.5\r
23         for <notmuch@notmuchmail.org>; Wed, 07 May 2014 10:14:09 -0700 (PDT)\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25         d=1e100.net; s=20130820;\r
26         h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to\r
27         :references;\r
28         bh=3A5ST4yHGlWraKm1pwJXk60uFMS1rsVqWH4Y70LOIqA=;\r
29         b=V38I8hJ5RLK3zacuNZ94W2C5xuVa9KZM+VIOMr+TxgNkz11elTtxsPU7Omzx+JSrlK\r
30         LhPUeYhl3WTJ+7DBAIMsNCZYW5vlV+hVUVwdH+2Twc1bILls3ayt/KpoTphH7kIZMV+6\r
31         FdX5CwZkxGe3Na5fzyvKJe8W/MtiYoIOcCpD7os1eiN2Qzifb8JJasg8M+eBXTsK1L6F\r
32         j4LXNolD5tBz192+jQmDKuaOMmUji4VGM0OR9AJNkhPhxrPohwvJPp68202nilY84+WL\r
33         TC1Va1iawuoSJRXsDbHDJW9s88xIY45V3kdPNxtFVmsTNk57mqNvkAPVhBsyOLtp+KT8\r
34         CgaA==\r
35 X-Gm-Message-State:\r
36  ALoCoQnT5kXOJkDgibXVOQT4DgTJBVl61Lb0ynpen7qsSP3wIVNzpk+IkXXMZMZaS92gn/qqK+AZ\r
37 X-Received: by 10.180.89.241 with SMTP id br17mr8894899wib.0.1399482849271;\r
38         Wed, 07 May 2014 10:14:09 -0700 (PDT)\r
39 Received: from hotblack-desiato.hh.sledj.net (disaster-area.hh.sledj.net.\r
40         [81.149.164.25])\r
41         by mx.google.com with ESMTPSA id n5sm32835096wiz.1.2014.05.07.10.14.07\r
42         for <notmuch@notmuchmail.org>\r
43         (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
44         Wed, 07 May 2014 10:14:08 -0700 (PDT)\r
45 Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
46         id B7D51108AA8; Wed,  7 May 2014 18:14:06 +0100 (BST)\r
47 From: David Edmondson <dme@dme.org>\r
48 To: notmuch@notmuchmail.org\r
49 Subject: [RFC] [PATCH] emacs/notmuch-mua: Generate improved cited text for\r
50         replies\r
51 Date: Wed,  7 May 2014 18:14:06 +0100\r
52 Message-Id: <1399482846-25308-1-git-send-email-dme@dme.org>\r
53 X-Mailer: git-send-email 2.0.0.rc0\r
54 In-Reply-To: <87sixdujkv.fsf@qmul.ac.uk>\r
55 References: <87sixdujkv.fsf@qmul.ac.uk>\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60         <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Wed, 07 May 2014 17:14:16 -0000\r
69 \r
70 Use the message display code to generate message text to cite in\r
71 replies.\r
72 ---\r
73 \r
74 This breaks the tests, which know about the details of how the reply\r
75 buffer looks in emacs. I will fix that of course, if this approach is\r
76 considered acceptable.\r
77 \r
78 The original implementation took a simplistic view of how a reply to a\r
79 complex message could be generated (essentially it tried to reduce it\r
80 to a flat list of text parts). Given that we already have code to\r
81 display more complex message structure, it seems obvious to use it.\r
82 \r
83  emacs/notmuch-mua.el | 34 ++++------------------------------\r
84  1 file changed, 4 insertions(+), 30 deletions(-)\r
85 \r
86 diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
87 index 95e4a4d..a8cff3d 100644\r
88 --- a/emacs/notmuch-mua.el\r
89 +++ b/emacs/notmuch-mua.el\r
90 @@ -28,7 +28,7 @@\r
91  \r
92  (eval-when-compile (require 'cl))\r
93  \r
94 -(declare-function notmuch-show-insert-bodypart "notmuch-show" (msg part depth &optional hide))\r
95 +(declare-function notmuch-show-insert-body "notmuch-show" (msg body depth))\r
96  \r
97  ;;\r
98  \r
99 @@ -123,31 +123,6 @@ list."\r
100         else if (notmuch-match-content-type (plist-get part :content-type) "multipart/*")\r
101           do (notmuch-mua-reply-crypto (plist-get part :content))))\r
102  \r
103 -(defun notmuch-mua-get-quotable-parts (parts)\r
104 -  (loop for part in parts\r
105 -       if (notmuch-match-content-type (plist-get part :content-type) "multipart/alternative")\r
106 -         collect (let* ((subparts (plist-get part :content))\r
107 -                       (types (mapcar (lambda (part) (plist-get part :content-type)) subparts))\r
108 -                       (chosen-type (car (notmuch-multipart/alternative-choose types))))\r
109 -                  (loop for part in (reverse subparts)\r
110 -                        if (notmuch-match-content-type (plist-get part :content-type) chosen-type)\r
111 -                        return part))\r
112 -       else if (notmuch-match-content-type (plist-get part :content-type) "multipart/*")\r
113 -         append (notmuch-mua-get-quotable-parts (plist-get part :content))\r
114 -       else if (notmuch-match-content-type (plist-get part :content-type) "text/*")\r
115 -         collect part))\r
116 -\r
117 -(defun notmuch-mua-insert-quotable-part (message part)\r
118 -  ;; We don't want text properties leaking from the show renderer into\r
119 -  ;; the reply so we use a temp buffer. Also we don't want hooks, such\r
120 -  ;; as notmuch-wash-*, to be run on the quotable part so we set\r
121 -  ;; notmuch-show-insert-text/plain-hook to nil.\r
122 -  (insert (with-temp-buffer\r
123 -           (let ((notmuch-show-insert-text/plain-hook nil))\r
124 -             ;; Show the part but do not add buttons.\r
125 -             (notmuch-show-insert-bodypart message part 0 'no-buttons))\r
126 -           (buffer-substring-no-properties (point-min) (point-max)))))\r
127 -\r
128  ;; There is a bug in emacs 23's message.el that results in a newline\r
129  ;; not being inserted after the References header, so the next header\r
130  ;; is concatenated to the end of it. This function fixes the problem,\r
131 @@ -225,10 +200,9 @@ list."\r
132         (insert "From: " from "\n")\r
133         (insert "Date: " date "\n\n")\r
134  \r
135 -       ;; Get the parts of the original message that should be quoted; this includes\r
136 -       ;; all the text parts, except the non-preferred ones in a multipart/alternative.\r
137 -       (let ((quotable-parts (notmuch-mua-get-quotable-parts (plist-get original :body))))\r
138 -         (mapc (apply-partially 'notmuch-mua-insert-quotable-part original) quotable-parts))\r
139 +       (insert (with-temp-buffer\r
140 +                 (notmuch-show-insert-body original (plist-get original :body) 0)\r
141 +                 (buffer-substring-no-properties (point-min) (point-max))))\r
142  \r
143         (set-mark (point))\r
144         (goto-char start)\r
145 -- \r
146 2.0.0.rc0\r
147 \r