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