--- /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 BFB0C431FAF\r
+ for <notmuch@notmuchmail.org>; Sat, 24 Jan 2015 13:17:22 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.138\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.138 tagged_above=-999 required=5\r
+ tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_MED=-2.3]\r
+ 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 YyaQVkyMB5bE for <notmuch@notmuchmail.org>;\r
+ Sat, 24 Jan 2015 13:17:19 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-4.mit.edu (dmz-mailsec-scanner-4.mit.edu\r
+ [18.9.25.15])\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 AF61B431FD5\r
+ for <notmuch@notmuchmail.org>; Sat, 24 Jan 2015 13:17:13 -0800 (PST)\r
+X-AuditID: 1209190f-f79716d000000d1a-f8-54c40bd7d5d6\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+ (using TLS with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (Client did not present a certificate)\r
+ by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 24.30.03354.7DB04C45; Sat, 24 Jan 2015 16:17:11 -0500 (EST)\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 t0OLH94W027945; \r
+ Sat, 24 Jan 2015 16:17:09 -0500\r
+Received: from drake (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 t0OLH6Bn007450\r
+ (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT);\r
+ Sat, 24 Jan 2015 16:17:07 -0500\r
+Received: from amthrax by drake with local (Exim 4.84)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1YF84n-0005RU-KV; Sat, 24 Jan 2015 16:17:05 -0500\r
+From: Austin Clements <amdragon@mit.edu>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 2/8] emacs: Create an API for fetching parts as undecoded\r
+ binary\r
+Date: Sat, 24 Jan 2015 16:16:57 -0500\r
+Message-Id: <1422134223-20739-3-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 2.1.3\r
+In-Reply-To: <1422134223-20739-1-git-send-email-amdragon@mit.edu>\r
+References: <1422134223-20739-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFrrJIsWRmVeSWpSXmKPExsUixCmqrXud+0iIweXrwhY3WrsZLfbd2cJk\r
+ sXouj8X1mzOZLd6snMfqwOqx6/lfJo+ds+6yexz+upDF49mqW8weWw69Zw5gjeKySUnNySxL\r
+ LdK3S+DK2HfmDnvBUe2KX1/fszQwPlPuYuTkkBAwkXgw6y0LhC0mceHeerYuRi4OIYHFTBJ7\r
+ N/9nh3A2Mkose72VBcK5yCTRcv8oM0iLkMAkRolDs9JAbDYBDYnftxYzgdgiAtISO+/OZgWx\r
+ mQXqJP7OOc8IYgsLBEss/H6ODcRmEVCVODl/BzuIzSvgIPH53xmgXg6gM+Qktq7zBglzCjhK\r
+ 3NiwiwVilYNE9+dGtgmM/AsYGVYxyqbkVunmJmbmFKcm6xYnJ+blpRbpmujlZpbopaaUbmIE\r
+ h6Ak/w7GbweVDjEKcDAq8fD++HcoRIg1say4MvcQoyQHk5Io76pfh0OE+JLyUyozEosz4otK\r
+ c1KLDzFKcDArifBe2ACU401JrKxKLcqHSUlzsCiJ8276wRciJJCeWJKanZpakFoEk5Xh4FCS\r
+ 4F3MdSRESLAoNT21Ii0zpwQhzcTBCTKcB2h4N0gNb3FBYm5xZjpE/hSjopQ4bzFIQgAkkVGa\r
+ B9cLSxGvGMWBXhHm3QdSxQNML3Ddr4AGMwENLth+AGRwSSJCSqqBsWdZZ5hrqr61ub+nRtOD\r
+ +jfNxrrTb9vckk58Pm95QVW3wBu1rjkdbeVesitOJm1+9+Vku/WR/DmMfqVr7/65Xb6Ibc8D\r
+ ldjbm/YwmSayLi5hE5rj5LM4/uuXDxM+eappr/HvmCjKncNYNCO48FR/NAtf3jblW2W8Z5s9\r
+ Pv5yTjJlvXnGY2GpEktxRqKhFnNRcSIAptdlW+wCAAA=\r
+Cc: tomi.ollila@iki.fi\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: Sat, 24 Jan 2015 21:17:23 -0000\r
+\r
+The new function, `notmuch-get-bodypart-binary', replaces\r
+`notmuch-get-bodypart-internal'. Whereas the old function was really\r
+meant for internal use in `notmuch-get-bodypart-content', it was used\r
+in a few other places. Since the difference between\r
+`notmuch-get-bodypart-content' and `notmuch-get-bodypart-internal' was\r
+unclear, these other uses were always confusing and potentially\r
+inconsistent. The new call clearly requests the part as undecoded\r
+binary.\r
+\r
+This is step 1 of 2 in separating `notmuch-get-bodypart-content' into\r
+two APIs for retrieving either undecoded binary or decoded text.\r
+---\r
+ emacs/notmuch-lib.el | 28 ++++++++++++++--------------\r
+ emacs/notmuch-show.el | 22 +++++++++-------------\r
+ 2 files changed, 23 insertions(+), 27 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index fd25f7c..d4b6684 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -529,25 +529,25 @@ (defun notmuch-parts-filter-by-type (parts type)\r
+ (lambda (part) (notmuch-match-content-type (plist-get part :content-type) type))\r
+ parts))\r
+ \r
+-;; Helper for parts which are generally not included in the default\r
+-;; SEXP output.\r
+-(defun notmuch-get-bodypart-internal (query part-number process-crypto)\r
+- (let ((args '("show" "--format=raw"))\r
+- (part-arg (format "--part=%s" part-number)))\r
+- (setq args (append args (list part-arg)))\r
+- (if process-crypto\r
+- (setq args (append args '("--decrypt"))))\r
+- (setq args (append args (list query)))\r
++(defun notmuch-get-bodypart-binary (msg part process-crypto)\r
++ "Return the unprocessed content of PART in MSG.\r
++\r
++This returns the \"raw\" content of the given part after content\r
++transfer decoding, but with no further processing (see the\r
++discussion of --format=raw in man notmuch-show). In particular,\r
++this does no charset conversion."\r
++ (let ((args `("show" "--format=raw"\r
++ ,(format "--part=%d" (plist-get part :id))\r
++ ,@(when process-crypto '("--decrypt"))\r
++ ,(notmuch-id-to-query (plist-get msg :id)))))\r
+ (with-temp-buffer\r
+ (let ((coding-system-for-read 'no-conversion))\r
+- (progn\r
+- (apply 'call-process (append (list notmuch-command nil (list t nil) nil) args))\r
+- (buffer-string))))))\r
++ (apply #'call-process notmuch-command nil '(t nil) nil args)\r
++ (buffer-string)))))\r
+ \r
+ (defun notmuch-get-bodypart-content (msg part process-crypto)\r
+ (or (plist-get part :content)\r
+- (notmuch-get-bodypart-internal (notmuch-id-to-query (plist-get msg :id))\r
+- (plist-get part :id) process-crypto)))\r
++ (notmuch-get-bodypart-binary msg part process-crypto)))\r
+ \r
+ ;; Workaround: The call to `mm-display-part' below triggers a bug in\r
+ ;; Emacs 24 if it attempts to use the shr renderer to display an HTML\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index df2389e..b3e339e 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -579,16 +579,14 @@ (defun notmuch-show-w3m-cid-retrieve (url &rest args)\r
+ (let* ((msg (nth 1 matching-part))\r
+ (part (nth 2 matching-part))\r
+ (content (nth 3 matching-part))\r
+- (message-id (plist-get msg :id))\r
+- (part-number (plist-get part :id))\r
+ (content-type (plist-get part :content-type)))\r
+ ;; If we don't already have the content, get it and cache\r
+ ;; it, as some messages reference the same cid: part many\r
+ ;; times (hundreds!), which results in many calls to\r
+ ;; `notmuch part'.\r
+ (unless content\r
+- (setq content (notmuch-get-bodypart-internal (notmuch-id-to-query message-id)\r
+- part-number notmuch-show-process-crypto))\r
++ (setq content (notmuch-get-bodypart-binary\r
++ msg part notmuch-show-process-crypto))\r
+ (with-current-buffer w3m-current-buffer\r
+ (notmuch-show-w3m-cid-store-internal url msg part content)))\r
+ (insert content)\r
+@@ -2162,15 +2160,14 @@ (defun notmuch-show-stash-git-send-email (&optional no-in-reply-to)\r
+ \r
+ ;; Interactive part functions and their helpers\r
+ \r
+-(defun notmuch-show-generate-part-buffer (message-id nth)\r
++(defun notmuch-show-generate-part-buffer (msg part)\r
+ "Return a temporary buffer containing the specified part's content."\r
+ (let ((buf (generate-new-buffer " *notmuch-part*"))\r
+ (process-crypto notmuch-show-process-crypto))\r
+ (with-current-buffer buf\r
+- (setq notmuch-show-process-crypto process-crypto)\r
+- ;; Always acquires the part via `notmuch part', even if it is\r
+- ;; available in the SEXP output.\r
+- (insert (notmuch-get-bodypart-internal message-id nth notmuch-show-process-crypto)))\r
++ ;; This is always used in the content of mm handles, which\r
++ ;; expect undecoded, binary part content.\r
++ (insert (notmuch-get-bodypart-binary msg part process-crypto)))\r
+ buf))\r
+ \r
+ (defun notmuch-show-current-part-handle ()\r
+@@ -2178,10 +2175,9 @@ (defun notmuch-show-current-part-handle ()\r
+ \r
+ This creates a temporary buffer for the part's content; the\r
+ caller is responsible for killing this buffer as appropriate."\r
+- (let* ((part (notmuch-show-get-part-properties))\r
+- (message-id (notmuch-show-get-message-id))\r
+- (nth (plist-get part :id))\r
+- (buf (notmuch-show-generate-part-buffer message-id nth))\r
++ (let* ((msg (notmuch-show-get-message-properties))\r
++ (part (notmuch-show-get-part-properties))\r
++ (buf (notmuch-show-generate-part-buffer msg part))\r
+ (computed-type (plist-get part :computed-type))\r
+ (filename (plist-get part :filename))\r
+ (disposition (if filename `(attachment (filename . ,filename)))))\r
+-- \r
+2.1.3\r
+\r