Re: [PATCH v4 09/16] index encrypted parts when asked.
[notmuch-archives.git] / cb / c5b34e8920a4c46f9b4967ee30556302ad82cb
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 2380D429E42\r
6         for <notmuch@notmuchmail.org>; Mon, 21 Apr 2014 11:38:48 -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 1P1Bo0vKpsvB for <notmuch@notmuchmail.org>;\r
16         Mon, 21 Apr 2014 11:38:42 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu\r
18         [18.9.25.14])\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 0E294431FDA\r
22         for <notmuch@notmuchmail.org>; Mon, 21 Apr 2014 11:38:08 -0700 (PDT)\r
23 X-AuditID: 1209190e-f79ee6d000000c40-ab-535565904039\r
24 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\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-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
28         id 23.75.03136.09565535; Mon, 21 Apr 2014 14:38:08 -0400 (EDT)\r
29 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
30         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s3LIbudU018333; \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 s3LIbs4i029720\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-0003l9-FQ; 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 07/11] emacs: Return unibyte strings for binary part data\r
45 Date: Mon, 21 Apr 2014 14:37:44 -0400\r
46 Message-Id: <1398105468-14317-8-git-send-email-amdragon@mit.edu>\r
47 X-Mailer: git-send-email 1.9.1\r
48 In-Reply-To: <1398105468-14317-1-git-send-email-amdragon@mit.edu>\r
49 References: <1398105468-14317-1-git-send-email-amdragon@mit.edu>\r
50 X-Brightmail-Tracker:\r
51  H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrTshNTTY4PMnPovrN2cyOzB6PFt1\r
52         izmAMYrLJiU1J7MstUjfLoEr4/cswYI//BXtm98wNjA+5uli5OCQEDCRONfj2sXICWSKSVy4\r
53         t56ti5GLQ0hgNpPEgdcbGCGcjYwS7evfM0M4d5gkrk5uZYVw5gJlrt9kAulnE9CQ2LZ/OSOI\r
54         LSIgLbHz7mxWkBXMAmoSf7pUQMLCAp4SG5/9ZQGxWQRUJea+2APWyivgIPFp3Wc2iDPkJE4e\r
55         m8wKYnMKOEq0rX7JDmILAdVs2LuGaQIj/wJGhlWMsim5Vbq5iZk5xanJusXJiXl5qUW6xnq5\r
56         mSV6qSmlmxjBISPJt4Px60GlQ4wCHIxKPLwFRqHBQqyJZcWVuYcYJTmYlER5X0UBhfiS8lMq\r
57         MxKLM+KLSnNSiw8xSnAwK4nwrtcEyvGmJFZWpRblw6SkOViUxHnfWlsFCwmkJ5akZqemFqQW\r
58         wWRlODiUJHhvpgA1ChalpqdWpGXmlCCkmTg4QYbzAA2/CFLDW1yQmFucmQ6RP8WoKCXO2waS\r
59         EABJZJTmwfXCYvoVozjQK8K8LSBVPMB0ANf9CmgwE9DgJ1tCQAaXJCKkpBoYJfnNdqVkzgrP\r
60         1N5Q/uOc0VnbF9eUT9g4u7sUfZzz+krXsuvnD02blLPgT/HJl2flA387rF1z3DL92O1VE/8/\r
61         OL//d3Cd3OJtHEvnPGNi84pNerJEoud6OKvVs02ydvsN48t2S9mezDJe9/w9q2Ocknjhjcm7\r
62         p+++qP7X4EdcdLJy6AkvpXmKXEosxRmJhlrMRcWJAM3zWm/EAgAA\r
63 X-BeenThere: notmuch@notmuchmail.org\r
64 X-Mailman-Version: 2.1.13\r
65 Precedence: list\r
66 List-Id: "Use and development of the notmuch mail system."\r
67         <notmuch.notmuchmail.org>\r
68 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
69         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
70 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
71 List-Post: <mailto:notmuch@notmuchmail.org>\r
72 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
73 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
74         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
75 X-List-Received-Date: Mon, 21 Apr 2014 18:38:48 -0000\r
76 \r
77 Unibyte strings are meant for representing binary data.  In practice,\r
78 using unibyte versus multibyte strings affects *almost* nothing.  It\r
79 does happen to matter if we use the binary data in an image descriptor\r
80 (which is, helpfully, not documented anywhere and getting it wrong\r
81 results in opaque errors like "Not a PNG image: <giant binary spew\r
82 that is, in fact, a PNG image>").\r
83 ---\r
84  emacs/notmuch-lib.el | 12 +++++++++++-\r
85  1 file changed, 11 insertions(+), 1 deletion(-)\r
86 \r
87 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
88 index ece29c3..fc67b14 100644\r
89 --- a/emacs/notmuch-lib.el\r
90 +++ b/emacs/notmuch-lib.el\r
91 @@ -504,7 +504,7 @@ (defun notmuch-parts-filter-by-type (parts type)\r
92     parts))\r
93  \r
94  (defun notmuch-get-bodypart-binary (msg part process-crypto)\r
95 -  "Return the unprocessed content of PART in MSG.\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 @@ -515,6 +515,16 @@ (defun notmuch-get-bodypart-binary (msg part process-crypto)\r
101                 ,@(when process-crypto '("--decrypt"))\r
102                 ,(notmuch-id-to-query (plist-get msg :id)))))\r
103      (with-temp-buffer\r
104 +      ;; Emacs internally uses a UTF-8-like multibyte string\r
105 +      ;; representation by default (regardless of the coding system,\r
106 +      ;; which only affects how it goes from outside data to this\r
107 +      ;; internal representation).  This *almost* never matters.\r
108 +      ;; Annoyingly, it does matter if we use this data in an image\r
109 +      ;; descriptor, since Emacs will use its internal data buffer\r
110 +      ;; directly and this multibyte representation corrupts binary\r
111 +      ;; image formats.  Since the caller is asking for binary data, a\r
112 +      ;; unibyte string is a more appropriate representation anyway.\r
113 +      (set-buffer-multibyte nil)\r
114        (let ((coding-system-for-read 'no-conversion))\r
115         (apply #'call-process notmuch-command nil '(t nil) nil args)\r
116         (buffer-string)))))\r
117 -- \r
118 1.9.1\r
119 \r