--- /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 A8852431E62\r
+ for <notmuch@notmuchmail.org>; Mon, 21 Apr 2014 11:38:14 -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 Ea7DYpC9RmEE for <notmuch@notmuchmail.org>;\r
+ Mon, 21 Apr 2014 11:38:10 -0700 (PDT)\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 3671B431FC3\r
+ for <notmuch@notmuchmail.org>; Mon, 21 Apr 2014 11:38:00 -0700 (PDT)\r
+X-AuditID: 1209190f-f790b6d000000c3a-cd-535565874487\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+ (using TLS with cipher 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 26.C8.03130.78565535; Mon, 21 Apr 2014 14:37:59 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id s3LIbuwI009463; \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 s3LIbsO6029722\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-0003lC-GB; Mon, 21 Apr 2014 14:37:54 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 08/11] emacs: Support caching in notmuch-get-bodypart-{binary,\r
+ text}\r
+Date: Mon, 21 Apr 2014 14:37:45 -0400\r
+Message-Id: <1398105468-14317-9-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+NgFtrEIsWRmVeSWpSXmKPExsUixG6notueGhpscOCLkMX1mzOZHRg9nq26\r
+ xRzAGMVlk5Kak1mWWqRvl8CVsXDXHeaCnXIVJ68dZmpg3CjRxcjJISFgIrFi7wMmCFtM4sK9\r
+ 9WwgtpDAbCaJhi9GXYxcQPZGRonm4+dYIZw7TBLTZ/xhgnDmMkrc23GbFaSFTUBDYtv+5Ywg\r
+ toiAtMTOu7OB4hwczAJqEn+6VEDCwgLBEt9mtoKVsAioSmzfcZkFxOYVcJBYcHING8QVchIn\r
+ j00GG8kp4CjRtvolO8RFDhIb9q5hmsDIv4CRYRWjbEpulW5uYmZOcWqybnFyYl5eapGuiV5u\r
+ ZoleakrpJkZQ0HBK8u9g/HZQ6RCjAAejEg+vhEFosBBrYllxZe4hRkkOJiVR3ldRQCG+pPyU\r
+ yozE4oz4otKc1OJDjBIczEoivOs1gXK8KYmVValF+TApaQ4WJXHet9ZWwUIC6YklqdmpqQWp\r
+ RTBZGQ4OJQnehSlAjYJFqempFWmZOSUIaSYOTpDhPEDDL4LU8BYXJOYWZ6ZD5E8xKkqJ87aB\r
+ JARAEhmleXC9sKh+xSgO9IowbwtIFQ8wIcB1vwIazAQ0+MmWEJDBJYkIKakGRjuLGcfurPb5\r
+ ES0R/Gtihsj2K+qxHcu61ecenKV+qm27sMD3qgfTYzYya+vqlMi+u9+6espfgTougbfb9Neo\r
+ Z/Ut3TNn9YPkRIMt9/+++zq/tlBE7boAu9PGYPZf3r/dEySPbFt/xie7N6PGcvV+c/ZFAmbm\r
+ QhEMq+eZvfcq3Pqm789nlykWjkosxRmJhlrMRcWJAJUML5HFAgAA\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:15 -0000\r
+\r
+(The actual code change here is small, but requires re-indenting\r
+existing code.)\r
+---\r
+ emacs/notmuch-lib.el | 52 ++++++++++++++++++++++++++++++----------------------\r
+ 1 file changed, 30 insertions(+), 22 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index fc67b14..fee8512 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -503,33 +503,39 @@ (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
+-(defun notmuch-get-bodypart-binary (msg part process-crypto)\r
++(defun notmuch-get-bodypart-binary (msg part process-crypto &optional cache)\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
+ 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
+- ;; 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
+-(defun notmuch-get-bodypart-text (msg part process-crypto)\r
++ (let ((data (plist-get part :binary-content)))\r
++ (when (not data)\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
++ ;; Emacs internally uses a UTF-8-like multibyte string\r
++ ;; representation by default (regardless of the coding\r
++ ;; system, which only affects how it goes from outside data\r
++ ;; to this internal representation). This *almost* never\r
++ ;; matters. Annoyingly, it does matter if we use this data\r
++ ;; in an image descriptor, since Emacs will use its internal\r
++ ;; data buffer directly and this multibyte representation\r
++ ;; corrupts binary image formats. Since the caller is\r
++ ;; asking for binary data, a unibyte string is a more\r
++ ;; 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
++ (setq data (buffer-string)))))\r
++ (when cache\r
++ (plist-put part :binary-content data)))\r
++ data))\r
++\r
++(defun notmuch-get-bodypart-text (msg part process-crypto &optional cache)\r
+ "Return the text content of PART in MSG.\r
+ \r
+ This returns the content of the given part as a multibyte Lisp\r
+@@ -546,7 +552,9 @@ (defun notmuch-get-bodypart-text (msg part process-crypto)\r
+ (npart (apply #'notmuch-call-notmuch-sexp args)))\r
+ (setq content (plist-get npart :content))\r
+ (when (not content)\r
+- (error "Internal error: No :content from %S" args))))\r
++ (error "Internal error: No :content from %S" args)))\r
++ (when cache\r
++ (plist-put part :content content)))\r
+ content))\r
+ \r
+ ;; Workaround: The call to `mm-display-part' below triggers a bug in\r
+-- \r
+1.9.1\r
+\r