From: Austin Clements Date: Sat, 24 Jan 2015 21:16:59 +0000 (+1900) Subject: [PATCH v2 4/8] emacs: Return unibyte strings for binary part data X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d1d58128ff1e5bb4a8b694182a9aef6b5ae62d27;p=notmuch-archives.git [PATCH v2 4/8] emacs: Return unibyte strings for binary part data --- diff --git a/5a/5ce3675f0d4c99a3f571ba6538b0f3fb43aec2 b/5a/5ce3675f0d4c99a3f571ba6538b0f3fb43aec2 new file mode 100644 index 000000000..843370238 --- /dev/null +++ b/5a/5ce3675f0d4c99a3f571ba6538b0f3fb43aec2 @@ -0,0 +1,121 @@ +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 77376429E2E + for ; Sat, 24 Jan 2015 13:18:05 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0.138 +X-Spam-Level: +X-Spam-Status: No, score=0.138 tagged_above=-999 required=5 + tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_MED=-2.3] + 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 Bm4vOk2R+Z5F for ; + Sat, 24 Jan 2015 13:18:02 -0800 (PST) +Received: from dmz-mailsec-scanner-7.mit.edu (dmz-mailsec-scanner-7.mit.edu + [18.7.68.36]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 4AB3D431FAF + for ; Sat, 24 Jan 2015 13:17:23 -0800 (PST) +X-AuditID: 12074424-f791c6d000000d25-56-54c40be0dcc1 +Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) + (using TLS with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP + id 33.7A.03365.0EB04C45; Sat, 24 Jan 2015 16:17:20 -0500 (EST) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id t0OLH9HW000699; + Sat, 24 Jan 2015 16:17:09 -0500 +Received: from drake (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 t0OLH6hx007455 + (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); + Sat, 24 Jan 2015 16:17:07 -0500 +Received: from amthrax by drake with local (Exim 4.84) + (envelope-from ) + id 1YF84n-0005Rb-LR; Sat, 24 Jan 2015 16:17:05 -0500 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v2 4/8] emacs: Return unibyte strings for binary part data +Date: Sat, 24 Jan 2015 16:16:59 -0500 +Message-Id: <1422134223-20739-5-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 2.1.3 +In-Reply-To: <1422134223-20739-1-git-send-email-amdragon@mit.edu> +References: <1422134223-20739-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFrrJIsWRmVeSWpSXmKPExsUixG6novuA+0iIwZnrZhY3WrsZLfbd2cJk + sXouj8X1mzOZLd6snMfqwOqx6/lfJo+ds+6yexz+upDF49mqW8weWw69Zw5gjeKySUnNySxL + LdK3S+DK2Nmwgr3gD3/Fj3urWRsYH/N0MXJySAiYSKy7eJQRwhaTuHBvPVsXIxeHkMBiJolF + jeuZIJyNjBL9b2ayg1QJCVxkkuj5oQ2RmMQoMXnKBzaQBJuAhsTvW4uZQGwRAWmJnXdns4LY + zAJ1En/nnAdbISzgJXH512wWEJtFQFViwtLVYDavgIPE+hUgCziAzpCT2LrOGyTMKeAocWPD + LhaIvQ4S3Z8b2SYw8i9gZFjFKJuSW6Wbm5iZU5yarFucnJiXl1qka66Xm1mil5pSuokRHIIu + KjsYmw8pHWIU4GBU4uH98e9QiBBrYllxZe4hRkkOJiVR3lW/DocI8SXlp1RmJBZnxBeV5qQW + H2KU4GBWEuG9sAEox5uSWFmVWpQPk5LmYFES5930gy9ESCA9sSQ1OzW1ILUIJivDwaEkwcsI + jDUhwaLU9NSKtMycEoQ0EwcnyHAeoOEnuYBqeIsLEnOLM9Mh8qcYFaXEedeDJARAEhmleXC9 + sBTxilEc6BVh3n0gVTzA9ALX/QpoMBPQ4ILtB0AGlyQipKQaGEt+mX158SrE/b+vjEAV89r4 + XJ26/xvab2wLUdhfJL4vr/vE//21kzbMMOVoiu4wkFsrI+pya79swYynho1p5+WYUnT+f57a + YZ37/nzsNHf1CNk1LjIufSvV3A8c5Zm7qnzn74aPyzkfPDRMajp7T/TDJHfDQ69c9tlp8K97 + dNL63YFnhl/uWSqxFGckGmoxFxUnAgDboNmd7AIAAA== +Cc: tomi.ollila@iki.fi +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: Sat, 24 Jan 2015 21:18:05 -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 a0a95d8..3154725 100644 +--- a/emacs/notmuch-lib.el ++++ b/emacs/notmuch-lib.el +@@ -530,7 +530,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 +@@ -541,6 +541,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))))) +-- +2.1.3 +