--- /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 5EFF8431FC3\r
+ for <notmuch@notmuchmail.org>; Mon, 21 Apr 2014 11:38:44 -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 rpLKhZAtG2dk for <notmuch@notmuchmail.org>;\r
+ Mon, 21 Apr 2014 11:38:39 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu\r
+ [18.7.68.37])\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 63D2C431FD9\r
+ for <notmuch@notmuchmail.org>; Mon, 21 Apr 2014 11:38:08 -0700 (PDT)\r
+X-AuditID: 12074425-f79906d000000cf9-30-5355658f8c71\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+ (using TLS with cipher AES256-SHA (256/256 bits))\r
+ (Client did not present a certificate)\r
+ by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id BA.F3.03321.F8565535; Mon, 21 Apr 2014 14:38:07 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s3LIbuiq022319; \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 s3LIbslQ029716\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-0003l3-Di; Mon, 21 Apr 2014 14:37:54 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 05/11] emacs: Create an API for fetching parts as undecoded\r
+ binary\r
+Date: Mon, 21 Apr 2014 14:37:42 -0400\r
+Message-Id: <1398105468-14317-6-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+NgFtrMIsWRmVeSWpSXmKPExsUixG6nrtufGhpscG6vpcX1mzOZHRg9nq26\r
+ xRzAGMVlk5Kak1mWWqRvl8CV0dV2kr3goHbFhtsr2RoYHyl3MXJySAiYSEyfMIsZwhaTuHBv\r
+ PVsXIxeHkMBsJolv608wQjgbGSVWNjyDcu4wSfxt72GFcOYySpw/eJMFpJ9NQENi2/7ljCC2\r
+ iIC0xM67s4GKODiYBdQk/nSpgISFBYIkDm74DVbCIqAqsffOPrBWXgEHiU/rn7JBnCEncfLY\r
+ ZFYQm1PAUaJt9Ut2EFsIqGbD3jVMExj5FzAyrGKUTcmt0s1NzMwpTk3WLU5OzMtLLdK10MvN\r
+ LNFLTSndxAgOGxfVHYwTDikdYhTgYFTi4S0wCg0WYk0sK67MPcQoycGkJMr7KgooxJeUn1KZ\r
+ kVicEV9UmpNafIhRgoNZSYR3vSZQjjclsbIqtSgfJiXNwaIkzvvW2ipYSCA9sSQ1OzW1ILUI\r
+ JivDwaEkwZuWAtQoWJSanlqRlplTgpBm4uAEGc4DNDwKpIa3uCAxtzgzHSJ/ilFRSpy3DSQh\r
+ AJLIKM2D64XF9StGcaBXhHndQap4gCkBrvsV0GAmoMFPtoSADC5JREhJNTCukuPUnRy246Hr\r
+ sRl1u6yvaHz1/du+yvluj75S0Wa5wjqZ37Kun4UUur9H6wlOteSVaXqXZiSz9vyVMv17Z0oY\r
+ fGLu79AOSXs4d+s+jz1753wrSb31/lSqwHMGG5/e5fEqqi0bD3+cznI76ecE1VN2Wo7h0588\r
+ FdvZt3amj515yuYd55gmFt1QYinOSDTUYi4qTgQAUoxbP8YCAAA=\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:44 -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 35b9065..4711098 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -503,25 +503,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 455cfee..e9867fd 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -557,16 +557,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
+@@ -2067,15 +2065,14 @@ (defun notmuch-show-stash-mlarchive-link-and-go (&optional mla)\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
+@@ -2083,10 +2080,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
+1.9.1\r
+\r