Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / 96 / fdeb432b6224a450968ef93db611ae47a871f7
1 Return-Path: <amdragon@mit.edu>\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 5EFF8431FC3\r
6         for <notmuch@notmuchmail.org>; Mon, 21 Apr 2014 11:38:44 -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 rpLKhZAtG2dk for <notmuch@notmuchmail.org>;\r
16         Mon, 21 Apr 2014 11:38:39 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu\r
18         [18.7.68.37])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 63D2C431FD9\r
22         for <notmuch@notmuchmail.org>; Mon, 21 Apr 2014 11:38:08 -0700 (PDT)\r
23 X-AuditID: 12074425-f79906d000000cf9-30-5355658f8c71\r
24 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
25         (using TLS with cipher AES256-SHA (256/256 bits))\r
26         (Client did not present a certificate)\r
27         by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
28         id BA.F3.03321.F8565535; Mon, 21 Apr 2014 14:38:07 -0400 (EDT)\r
29 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
30         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s3LIbuiq022319; \r
31         Mon, 21 Apr 2014 14:37:57 -0400\r
32 Received: from drake.dyndns.org\r
33         (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
34         [216.15.114.40]) (authenticated bits=0)\r
35         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
36         by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s3LIbslQ029716\r
37         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
38         Mon, 21 Apr 2014 14:37:56 -0400\r
39 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
40         (envelope-from <amdragon@mit.edu>)\r
41         id 1WcJ6I-0003l3-Di; Mon, 21 Apr 2014 14:37:54 -0400\r
42 From: Austin Clements <amdragon@MIT.EDU>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH 05/11] emacs: Create an API for fetching parts as undecoded\r
45         binary\r
46 Date: Mon, 21 Apr 2014 14:37:42 -0400\r
47 Message-Id: <1398105468-14317-6-git-send-email-amdragon@mit.edu>\r
48 X-Mailer: git-send-email 1.9.1\r
49 In-Reply-To: <1398105468-14317-1-git-send-email-amdragon@mit.edu>\r
50 References: <1398105468-14317-1-git-send-email-amdragon@mit.edu>\r
51 X-Brightmail-Tracker:\r
52  H4sIAAAAAAAAA+NgFtrMIsWRmVeSWpSXmKPExsUixG6nrtufGhpscG6vpcX1mzOZHRg9nq26\r
53         xRzAGMVlk5Kak1mWWqRvl8CV0dV2kr3goHbFhtsr2RoYHyl3MXJySAiYSEyfMIsZwhaTuHBv\r
54         PVsXIxeHkMBsJolv608wQjgbGSVWNjyDcu4wSfxt72GFcOYySpw/eJMFpJ9NQENi2/7ljCC2\r
55         iIC0xM67s4GKODiYBdQk/nSpgISFBYIkDm74DVbCIqAqsffOPrBWXgEHiU/rn7JBnCEncfLY\r
56         ZFYQm1PAUaJt9Ut2EFsIqGbD3jVMExj5FzAyrGKUTcmt0s1NzMwpTk3WLU5OzMtLLdK10MvN\r
57         LNFLTSndxAgOGxfVHYwTDikdYhTgYFTi4S0wCg0WYk0sK67MPcQoycGkJMr7KgooxJeUn1KZ\r
58         kVicEV9UmpNafIhRgoNZSYR3vSZQjjclsbIqtSgfJiXNwaIkzvvW2ipYSCA9sSQ1OzW1ILUI\r
59         JivDwaEkwZuWAtQoWJSanlqRlplTgpBm4uAEGc4DNDwKpIa3uCAxtzgzHSJ/ilFRSpy3DSQh\r
60         AJLIKM2D64XF9StGcaBXhHndQap4gCkBrvsV0GAmoMFPtoSADC5JREhJNTCukuPUnRy246Hr\r
61         sRl1u6yvaHz1/du+yvluj75S0Wa5wjqZ37Kun4UUur9H6wlOteSVaXqXZiSz9vyVMv17Z0oY\r
62         fGLu79AOSXs4d+s+jz1753wrSb31/lSqwHMGG5/e5fEqqi0bD3+cznI76ecE1VN2Wo7h0588\r
63         FdvZt3amj515yuYd55gmFt1QYinOSDTUYi4qTgQAUoxbP8YCAAA=\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, 21 Apr 2014 18:38:44 -0000\r
77 \r
78 The new function, `notmuch-get-bodypart-binary', replaces\r
79 `notmuch-get-bodypart-internal'.  Whereas the old function was really\r
80 meant for internal use in `notmuch-get-bodypart-content', it was used\r
81 in a few other places.  Since the difference between\r
82 `notmuch-get-bodypart-content' and `notmuch-get-bodypart-internal' was\r
83 unclear, these other uses were always confusing and potentially\r
84 inconsistent.  The new call clearly requests the part as undecoded\r
85 binary.\r
86 \r
87 This is step 1 of 2 in separating `notmuch-get-bodypart-content' into\r
88 two APIs for retrieving either undecoded binary or decoded text.\r
89 ---\r
90  emacs/notmuch-lib.el  | 28 ++++++++++++++--------------\r
91  emacs/notmuch-show.el | 22 +++++++++-------------\r
92  2 files changed, 23 insertions(+), 27 deletions(-)\r
93 \r
94 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
95 index 35b9065..4711098 100644\r
96 --- a/emacs/notmuch-lib.el\r
97 +++ b/emacs/notmuch-lib.el\r
98 @@ -503,25 +503,25 @@ (defun notmuch-parts-filter-by-type (parts type)\r
99     (lambda (part) (notmuch-match-content-type (plist-get part :content-type) type))\r
100     parts))\r
101  \r
102 -;; Helper for parts which are generally not included in the default\r
103 -;; SEXP output.\r
104 -(defun notmuch-get-bodypart-internal (query part-number process-crypto)\r
105 -  (let ((args '("show" "--format=raw"))\r
106 -       (part-arg (format "--part=%s" part-number)))\r
107 -    (setq args (append args (list part-arg)))\r
108 -    (if process-crypto\r
109 -       (setq args (append args '("--decrypt"))))\r
110 -    (setq args (append args (list query)))\r
111 +(defun notmuch-get-bodypart-binary (msg part process-crypto)\r
112 +  "Return the unprocessed content of PART in MSG.\r
113 +\r
114 +This returns the \"raw\" content of the given part after content\r
115 +transfer decoding, but with no further processing (see the\r
116 +discussion of --format=raw in man notmuch-show).  In particular,\r
117 +this does no charset conversion."\r
118 +  (let ((args `("show" "--format=raw"\r
119 +               ,(format "--part=%d" (plist-get part :id))\r
120 +               ,@(when process-crypto '("--decrypt"))\r
121 +               ,(notmuch-id-to-query (plist-get msg :id)))))\r
122      (with-temp-buffer\r
123        (let ((coding-system-for-read 'no-conversion))\r
124 -       (progn\r
125 -         (apply 'call-process (append (list notmuch-command nil (list t nil) nil) args))\r
126 -         (buffer-string))))))\r
127 +       (apply #'call-process notmuch-command nil '(t nil) nil args)\r
128 +       (buffer-string)))))\r
129  \r
130  (defun notmuch-get-bodypart-content (msg part process-crypto)\r
131    (or (plist-get part :content)\r
132 -      (notmuch-get-bodypart-internal (notmuch-id-to-query (plist-get msg :id))\r
133 -                                    (plist-get part :id) process-crypto)))\r
134 +      (notmuch-get-bodypart-binary msg part process-crypto)))\r
135  \r
136  ;; Workaround: The call to `mm-display-part' below triggers a bug in\r
137  ;; Emacs 24 if it attempts to use the shr renderer to display an HTML\r
138 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
139 index 455cfee..e9867fd 100644\r
140 --- a/emacs/notmuch-show.el\r
141 +++ b/emacs/notmuch-show.el\r
142 @@ -557,16 +557,14 @@ (defun notmuch-show-w3m-cid-retrieve (url &rest args)\r
143         (let* ((msg (nth 1 matching-part))\r
144                (part (nth 2 matching-part))\r
145                (content (nth 3 matching-part))\r
146 -              (message-id (plist-get msg :id))\r
147 -              (part-number (plist-get part :id))\r
148                (content-type (plist-get part :content-type)))\r
149           ;; If we don't already have the content, get it and cache\r
150           ;; it, as some messages reference the same cid: part many\r
151           ;; times (hundreds!), which results in many calls to\r
152           ;; `notmuch part'.\r
153           (unless content\r
154 -           (setq content (notmuch-get-bodypart-internal (notmuch-id-to-query message-id)\r
155 -                                                             part-number notmuch-show-process-crypto))\r
156 +           (setq content (notmuch-get-bodypart-binary\r
157 +                          msg part notmuch-show-process-crypto))\r
158             (with-current-buffer w3m-current-buffer\r
159               (notmuch-show-w3m-cid-store-internal url msg part content)))\r
160           (insert content)\r
161 @@ -2067,15 +2065,14 @@ (defun notmuch-show-stash-mlarchive-link-and-go (&optional mla)\r
162  \r
163  ;; Interactive part functions and their helpers\r
164  \r
165 -(defun notmuch-show-generate-part-buffer (message-id nth)\r
166 +(defun notmuch-show-generate-part-buffer (msg part)\r
167    "Return a temporary buffer containing the specified part's content."\r
168    (let ((buf (generate-new-buffer " *notmuch-part*"))\r
169         (process-crypto notmuch-show-process-crypto))\r
170      (with-current-buffer buf\r
171 -      (setq notmuch-show-process-crypto process-crypto)\r
172 -      ;; Always acquires the part via `notmuch part', even if it is\r
173 -      ;; available in the SEXP output.\r
174 -      (insert (notmuch-get-bodypart-internal message-id nth notmuch-show-process-crypto)))\r
175 +      ;; This is always used in the content of mm handles, which\r
176 +      ;; expect undecoded, binary part content.\r
177 +      (insert (notmuch-get-bodypart-binary msg part process-crypto)))\r
178      buf))\r
179  \r
180  (defun notmuch-show-current-part-handle ()\r
181 @@ -2083,10 +2080,9 @@ (defun notmuch-show-current-part-handle ()\r
182  \r
183  This creates a temporary buffer for the part's content; the\r
184  caller is responsible for killing this buffer as appropriate."\r
185 -  (let* ((part (notmuch-show-get-part-properties))\r
186 -        (message-id (notmuch-show-get-message-id))\r
187 -        (nth (plist-get part :id))\r
188 -        (buf (notmuch-show-generate-part-buffer message-id nth))\r
189 +  (let* ((msg (notmuch-show-get-message-properties))\r
190 +        (part (notmuch-show-get-part-properties))\r
191 +        (buf (notmuch-show-generate-part-buffer msg part))\r
192          (computed-type (plist-get part :computed-type))\r
193          (filename (plist-get part :filename))\r
194          (disposition (if filename `(attachment (filename . ,filename)))))\r
195 -- \r
196 1.9.1\r
197 \r