--- /dev/null
+Return-Path: <m.walters@qmul.ac.uk>\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 C5257431FAF\r
+ for <notmuch@notmuchmail.org>; Thu, 24 Apr 2014 03:46:50 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.502\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.502 tagged_above=-999 required=5\r
+ tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+ NML_ADSP_CUSTOM_MED=1.2, 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 TC9hcCucmCBx for <notmuch@notmuchmail.org>;\r
+ Thu, 24 Apr 2014 03:46:43 -0700 (PDT)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\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 CDEEB431FAE\r
+ for <notmuch@notmuchmail.org>; Thu, 24 Apr 2014 03:46:42 -0700 (PDT)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+ by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1WdHAm-0004oP-0w; Thu, 24 Apr 2014 11:46:36 +0100\r
+Received: from 5751dfa2.skybroadband.com ([87.81.223.162] helo=localhost)\r
+ by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1WdHAl-00085x-L2; Thu, 24 Apr 2014 11:46:31 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 08/11] emacs: Support caching in\r
+ notmuch-get-bodypart-{binary, text}\r
+In-Reply-To: <1398105468-14317-9-git-send-email-amdragon@mit.edu>\r
+References: <1398105468-14317-1-git-send-email-amdragon@mit.edu>\r
+ <1398105468-14317-9-git-send-email-amdragon@mit.edu>\r
+User-Agent: Notmuch/0.15.2+615~g78e3a93 (http://notmuchmail.org) Emacs/23.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Thu, 24 Apr 2014 11:46:28 +0100\r
+Message-ID: <87sip3t37f.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 87.81.223.162\r
+X-QM-Geographic: According to ripencc,\r
+ this message was delivered by a machine in Britain (UK) (GB).\r
+X-QM-SPAM-Info: Sender has good ham record. :)\r
+X-QM-Body-MD5: 61734a60742b5b0478ef6dceac2f28de (of first 20000 bytes)\r
+X-SpamAssassin-Score: -0.1\r
+X-SpamAssassin-SpamBar: /\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+ determine if it is\r
+ spam. We require at least 5.0 points to mark a message as spam.\r
+ This message scored -0.1 points.\r
+ Summary of the scoring: \r
+ * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+ provider * (markwalters1009[at]gmail.com)\r
+ * -0.1 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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: Thu, 24 Apr 2014 10:46:50 -0000\r
+\r
+\r
+On Mon, 21 Apr 2014, Austin Clements <amdragon@MIT.EDU> wrote:\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
+I am a little puzzled by this but that could be lack of familiarity with\r
+elisp. As far as I can see plist-put will sometimes modify the original\r
+plist and sometimes return a new plist. If the latter happens then I\r
+think it works out as if we hadn't cached anything as the part passed to\r
+the function is unmodified. That might not matter in this case (though I\r
+find the lack of determinism disturbing).\r
+\r
+Or is something else going on?\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+\r
+\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
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r