Re: [PATCH v4 13/16] add indexopts to notmuch python bindings.
[notmuch-archives.git] / aa / 8b022b70b73aa1143cbf94cab315261dc5ac8a
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 1F765431FAE\r
6         for <notmuch@notmuchmail.org>; Sat, 24 Jan 2015 13:17:19 -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: 0.138\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.138 tagged_above=-999 required=5\r
12         tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_MED=-2.3]\r
13         autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id MrD7Oc5j5wk6 for <notmuch@notmuchmail.org>;\r
17         Sat, 24 Jan 2015 13:17:15 -0800 (PST)\r
18 Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu\r
19         [18.9.25.14])\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 D8F83431FCB\r
23         for <notmuch@notmuchmail.org>; Sat, 24 Jan 2015 13:17:12 -0800 (PST)\r
24 X-AuditID: 1209190e-f799e6d000000cfe-91-54c40bd6bd45\r
25 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
26         (using TLS with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
27         (Client did not present a certificate)\r
28         by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
29         id 24.73.03326.6DB04C45; Sat, 24 Jan 2015 16:17:10 -0500 (EST)\r
30 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
31         by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id t0OLH9fM000700; \r
32         Sat, 24 Jan 2015 16:17:09 -0500\r
33 Received: from drake (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 t0OLH6P5007459\r
37         (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT);\r
38         Sat, 24 Jan 2015 16:17:07 -0500\r
39 Received: from amthrax by drake with local (Exim 4.84)\r
40         (envelope-from <amdragon@mit.edu>)\r
41         id 1YF84n-0005Rf-Lu; Sat, 24 Jan 2015 16:17:05 -0500\r
42 From: Austin Clements <amdragon@mit.edu>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH v2 5/8] emacs: Support caching in\r
45  notmuch-get-bodypart-{binary,  text}\r
46 Date: Sat, 24 Jan 2015 16:17:00 -0500\r
47 Message-Id: <1422134223-20739-6-git-send-email-amdragon@mit.edu>\r
48 X-Mailer: git-send-email 2.1.3\r
49 In-Reply-To: <1422134223-20739-1-git-send-email-amdragon@mit.edu>\r
50 References: <1422134223-20739-1-git-send-email-amdragon@mit.edu>\r
51 X-Brightmail-Tracker:\r
52  H4sIAAAAAAAAA+NgFrrFIsWRmVeSWpSXmKPExsUixG6nonuN+0iIwbeTchY3WrsZLfbd2cJk\r
53         sXouj8X1mzOZLd6snMfqwOqx6/lfJo+ds+6yexz+upDF49mqW8weWw69Zw5gjeKySUnNySxL\r
54         LdK3S+DKaD85kb1gvXLFl4cz2BoYF8h0MXJySAiYSGw5+oAJwhaTuHBvPVsXIxeHkMBiJon+\r
55         k9dYIJyNjBIvtqxkhnAuMklcPNDECOFMYpTomvWdEaSfTUBD4vetxWCzRASkJXbenc0KYjML\r
56         1En8nXMerEZYIETi/8wPYHEWAVWJ7+uWs4PYvAIOEqfvPACKcwDdISexdZ03SJhTwFHixoZd\r
57         LCC2EFBJ9+dGtgmM/AsYGVYxyqbkVunmJmbmFKcm6xYnJ+blpRbpGuvlZpbopaaUbmIEBSGn\r
58         JN8Oxq8HlQ4xCnAwKvHwBjAeDhFiTSwrrsw9xCjJwaQkyrvqF1CILyk/pTIjsTgjvqg0J7X4\r
59         EKMEB7OSCO+FDUA53pTEyqrUonyYlDQHi5I476YffCFCAumJJanZqakFqUUwWRkODiUJXkZg\r
60         tAkJFqWmp1akZeaUIKSZODhBhvMADWcFqeEtLkjMLc5Mh8ifYlSUEuf9ygWUEABJZJTmwfXC\r
61         ksQrRnGgV4R560GqeIAJBq77FdBgJqDBBdsPgAwuSURISTUwKviE3OaU9oyvv1S34p2lZ9em\r
62         ygcuZ4WUxfX/Jy3sDHojkfFqzdZE0bWr8mbWMohuXacXvuZZZJzVe8ZX+x/mB8W0Rd1/k1Nz\r
63         embk7tArnsy83gxVvXszc6Y3pr2/n9z0dl6hg2XOrWNbvypb5X6UmFX5/E6AiuaLW2ru2w3u\r
64         CcZfV3faMFFbiaU4I9FQi7moOBEAXsVqY+0CAAA=\r
65 Cc: tomi.ollila@iki.fi\r
66 X-BeenThere: notmuch@notmuchmail.org\r
67 X-Mailman-Version: 2.1.13\r
68 Precedence: list\r
69 List-Id: "Use and development of the notmuch mail system."\r
70         <notmuch.notmuchmail.org>\r
71 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
73 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
74 List-Post: <mailto:notmuch@notmuchmail.org>\r
75 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
76 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
77         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
78 X-List-Received-Date: Sat, 24 Jan 2015 21:17:19 -0000\r
79 \r
80 (The actual code change here is small, but requires re-indenting\r
81 existing code.)\r
82 ---\r
83  emacs/notmuch-lib.el | 64 ++++++++++++++++++++++++++++++++--------------------\r
84  1 file changed, 40 insertions(+), 24 deletions(-)\r
85 \r
86 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
87 index 3154725..f8e5165 100644\r
88 --- a/emacs/notmuch-lib.el\r
89 +++ b/emacs/notmuch-lib.el\r
90 @@ -529,39 +529,53 @@ (defun notmuch-parts-filter-by-type (parts type)\r
91     (lambda (part) (notmuch-match-content-type (plist-get part :content-type) type))\r
92     parts))\r
93  \r
94 -(defun notmuch-get-bodypart-binary (msg part process-crypto)\r
95 +(defun notmuch-get-bodypart-binary (msg part process-crypto &optional cache)\r
96    "Return the unprocessed content of PART in MSG as a unibyte string.\r
97  \r
98  This returns the \"raw\" content of the given part after content\r
99  transfer decoding, but with no further processing (see the\r
100  discussion of --format=raw in man notmuch-show).  In particular,\r
101 -this does no charset conversion."\r
102 -  (let ((args `("show" "--format=raw"\r
103 -               ,(format "--part=%d" (plist-get part :id))\r
104 -               ,@(when process-crypto '("--decrypt"))\r
105 -               ,(notmuch-id-to-query (plist-get msg :id)))))\r
106 -    (with-temp-buffer\r
107 -      ;; Emacs internally uses a UTF-8-like multibyte string\r
108 -      ;; representation by default (regardless of the coding system,\r
109 -      ;; which only affects how it goes from outside data to this\r
110 -      ;; internal representation).  This *almost* never matters.\r
111 -      ;; Annoyingly, it does matter if we use this data in an image\r
112 -      ;; descriptor, since Emacs will use its internal data buffer\r
113 -      ;; directly and this multibyte representation corrupts binary\r
114 -      ;; image formats.  Since the caller is asking for binary data, a\r
115 -      ;; unibyte string is a more appropriate representation anyway.\r
116 -      (set-buffer-multibyte nil)\r
117 -      (let ((coding-system-for-read 'no-conversion))\r
118 -       (apply #'call-process notmuch-command nil '(t nil) nil args)\r
119 -       (buffer-string)))))\r
120 -\r
121 -(defun notmuch-get-bodypart-text (msg part process-crypto)\r
122 +this does no charset conversion.\r
123 +\r
124 +If CACHE is non-nil, the content of this part will be saved in\r
125 +MSG (if it isn't already)."\r
126 +  (let ((data (plist-get part :binary-content)))\r
127 +    (when (not data)\r
128 +      (let ((args `("show" "--format=raw"\r
129 +                   ,(format "--part=%d" (plist-get part :id))\r
130 +                   ,@(when process-crypto '("--decrypt"))\r
131 +                   ,(notmuch-id-to-query (plist-get msg :id)))))\r
132 +       (with-temp-buffer\r
133 +         ;; Emacs internally uses a UTF-8-like multibyte string\r
134 +         ;; representation by default (regardless of the coding\r
135 +         ;; system, which only affects how it goes from outside data\r
136 +         ;; to this internal representation).  This *almost* never\r
137 +         ;; matters.  Annoyingly, it does matter if we use this data\r
138 +         ;; in an image descriptor, since Emacs will use its internal\r
139 +         ;; data buffer directly and this multibyte representation\r
140 +         ;; corrupts binary image formats.  Since the caller is\r
141 +         ;; asking for binary data, a unibyte string is a more\r
142 +         ;; appropriate representation anyway.\r
143 +         (set-buffer-multibyte nil)\r
144 +         (let ((coding-system-for-read 'no-conversion))\r
145 +           (apply #'call-process notmuch-command nil '(t nil) nil args)\r
146 +           (setq data (buffer-string)))))\r
147 +      (when cache\r
148 +       ;; Cheat.  part is non-nil, and `plist-put' always modifies\r
149 +       ;; the list in place if it's non-nil.\r
150 +       (plist-put part :binary-content data)))\r
151 +    data))\r
152 +\r
153 +(defun notmuch-get-bodypart-text (msg part process-crypto &optional cache)\r
154    "Return the text content of PART in MSG.\r
155  \r
156  This returns the content of the given part as a multibyte Lisp\r
157  string after performing content transfer decoding and any\r
158  necessary charset decoding.  It is an error to use this for\r
159 -non-text/* parts."\r
160 +non-text/* parts.\r
161 +\r
162 +If CACHE is non-nil, the content of this part will be saved in\r
163 +MSG (if it isn't already)."\r
164    (let ((content (plist-get part :content)))\r
165      (when (not content)\r
166        ;; Use show --format=sexp to fetch decoded content\r
167 @@ -572,7 +586,9 @@ (defun notmuch-get-bodypart-text (msg part process-crypto)\r
168              (npart (apply #'notmuch-call-notmuch-sexp args)))\r
169         (setq content (plist-get npart :content))\r
170         (when (not content)\r
171 -         (error "Internal error: No :content from %S" args))))\r
172 +         (error "Internal error: No :content from %S" args)))\r
173 +      (when cache\r
174 +       (plist-put part :content content)))\r
175      content))\r
176  \r
177  ;; Workaround: The call to `mm-display-part' below triggers a bug in\r
178 -- \r
179 2.1.3\r
180 \r