--- /dev/null
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 2380D429E42\r
+ for <notmuch@notmuchmail.org>; Mon, 21 Apr 2014 11:38:48 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 1P1Bo0vKpsvB for <notmuch@notmuchmail.org>;\r
+ Mon, 21 Apr 2014 11:38:42 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu\r
+ [18.9.25.14])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 0E294431FDA\r
+ for <notmuch@notmuchmail.org>; Mon, 21 Apr 2014 11:38:08 -0700 (PDT)\r
+X-AuditID: 1209190e-f79ee6d000000c40-ab-535565904039\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+ (using TLS with cipher AES256-SHA (256/256 bits))\r
+ (Client did not present a certificate)\r
+ by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 23.75.03136.09565535; Mon, 21 Apr 2014 14:38:08 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s3LIbudU018333; \r
+ Mon, 21 Apr 2014 14:37:57 -0400\r
+Received: from drake.dyndns.org\r
+ (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+ [216.15.114.40]) (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s3LIbs4i029720\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Mon, 21 Apr 2014 14:37:56 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1WcJ6I-0003l9-FQ; Mon, 21 Apr 2014 14:37:54 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 07/11] emacs: Return unibyte strings for binary part data\r
+Date: Mon, 21 Apr 2014 14:37:44 -0400\r
+Message-Id: <1398105468-14317-8-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.9.1\r
+In-Reply-To: <1398105468-14317-1-git-send-email-amdragon@mit.edu>\r
+References: <1398105468-14317-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrTshNTTY4PMnPovrN2cyOzB6PFt1\r
+ izmAMYrLJiU1J7MstUjfLoEr4/cswYI//BXtm98wNjA+5uli5OCQEDCRONfj2sXICWSKSVy4\r
+ t56ti5GLQ0hgNpPEgdcbGCGcjYwS7evfM0M4d5gkrk5uZYVw5gJlrt9kAulnE9CQ2LZ/OSOI\r
+ LSIgLbHz7mxWkBXMAmoSf7pUQMLCAp4SG5/9ZQGxWQRUJea+2APWyivgIPFp3Wc2iDPkJE4e\r
+ m8wKYnMKOEq0rX7JDmILAdVs2LuGaQIj/wJGhlWMsim5Vbq5iZk5xanJusXJiXl5qUW6xnq5\r
+ mSV6qSmlmxjBISPJt4Px60GlQ4wCHIxKPLwFRqHBQqyJZcWVuYcYJTmYlER5X0UBhfiS8lMq\r
+ MxKLM+KLSnNSiw8xSnAwK4nwrtcEyvGmJFZWpRblw6SkOViUxHnfWlsFCwmkJ5akZqemFqQW\r
+ wWRlODiUJHhvpgA1ChalpqdWpGXmlCCkmTg4QYbzAA2/CFLDW1yQmFucmQ6RP8WoKCXO2waS\r
+ EABJZJTmwfXCYvoVozjQK8K8LSBVPMB0ANf9CmgwE9DgJ1tCQAaXJCKkpBoYJfnNdqVkzgrP\r
+ 1N5Q/uOc0VnbF9eUT9g4u7sUfZzz+krXsuvnD02blLPgT/HJl2flA387rF1z3DL92O1VE/8/\r
+ OL//d3Cd3OJtHEvnPGNi84pNerJEoud6OKvVs02ydvsN48t2S9mezDJe9/w9q2Ocknjhjcm7\r
+ p+++qP7X4EdcdLJy6AkvpXmKXEosxRmJhlrMRcWJAM3zWm/EAgAA\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 21 Apr 2014 18:38:48 -0000\r
+\r
+Unibyte strings are meant for representing binary data. In practice,\r
+using unibyte versus multibyte strings affects *almost* nothing. It\r
+does happen to matter if we use the binary data in an image descriptor\r
+(which is, helpfully, not documented anywhere and getting it wrong\r
+results in opaque errors like "Not a PNG image: <giant binary spew\r
+that is, in fact, a PNG image>").\r
+---\r
+ emacs/notmuch-lib.el | 12 +++++++++++-\r
+ 1 file changed, 11 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index ece29c3..fc67b14 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -504,7 +504,7 @@ (defun notmuch-parts-filter-by-type (parts type)\r
+ parts))\r
+ \r
+ (defun notmuch-get-bodypart-binary (msg part process-crypto)\r
+- "Return the unprocessed content of PART in MSG.\r
++ "Return the unprocessed content of PART in MSG as a unibyte string.\r
+ \r
+ This returns the \"raw\" content of the given part after content\r
+ transfer decoding, but with no further processing (see the\r
+@@ -515,6 +515,16 @@ (defun notmuch-get-bodypart-binary (msg part process-crypto)\r
+ ,@(when process-crypto '("--decrypt"))\r
+ ,(notmuch-id-to-query (plist-get msg :id)))))\r
+ (with-temp-buffer\r
++ ;; Emacs internally uses a UTF-8-like multibyte string\r
++ ;; representation by default (regardless of the coding system,\r
++ ;; which only affects how it goes from outside data to this\r
++ ;; internal representation). This *almost* never matters.\r
++ ;; Annoyingly, it does matter if we use this data in an image\r
++ ;; descriptor, since Emacs will use its internal data buffer\r
++ ;; directly and this multibyte representation corrupts binary\r
++ ;; image formats. Since the caller is asking for binary data, a\r
++ ;; unibyte string is a more appropriate representation anyway.\r
++ (set-buffer-multibyte nil)\r
+ (let ((coding-system-for-read 'no-conversion))\r
+ (apply #'call-process notmuch-command nil '(t nil) nil args)\r
+ (buffer-string)))))\r
+-- \r
+1.9.1\r
+\r