--- /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 6789A431FBD\r
+ for <notmuch@notmuchmail.org>; Thu, 24 Apr 2014 23:42:10 -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 3rljN1cILgEi for <notmuch@notmuchmail.org>;\r
+ Thu, 24 Apr 2014 23:42:04 -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 093AB431FAE\r
+ for <notmuch@notmuchmail.org>; Thu, 24 Apr 2014 23:42:04 -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 1WdZph-0003ze-Il; Fri, 25 Apr 2014 07:42:01 +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 1WdZph-0007Wc-1X; Fri, 25 Apr 2014 07:42:01 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Austin Clements <amdragon@MIT.EDU>\r
+Subject: Re: [PATCH 08/11] emacs: Support caching in\r
+ notmuch-get-bodypart-{binary, text}\r
+In-Reply-To: <20140424181216.GO25817@mit.edu>\r
+References: <1398105468-14317-1-git-send-email-amdragon@mit.edu>\r
+ <1398105468-14317-9-git-send-email-amdragon@mit.edu>\r
+ <87sip3t37f.fsf@qmul.ac.uk> <20140424181216.GO25817@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: Fri, 25 Apr 2014 07:42:00 +0100\r
+Message-ID: <87d2g5uczr.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: 14239cbd11f4e8c3a5792e1fe7b93f1a (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
+Cc: notmuch@notmuchmail.org\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: Fri, 25 Apr 2014 06:42:10 -0000\r
+\r
+\r
+On Thu, 24 Apr 2014, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> Quoth Mark Walters on Apr 24 at 11:46 am:\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
+> No, your familiarity with Elisp serves you well. I'm completely\r
+> cheating here. According to the specification of plist-put, it's\r
+> allowed to return a new list but in reality this only happens when the\r
+> original plist is nil. We lean on this already all over the\r
+> notmuch-emacs code, but maybe that doesn't excuse me adding one more\r
+> cheat.\r
+>\r
+> I could add a comment here explaining what's going on, I could\r
+> manually do the list insertion in a way that's guaranteed to mutate it\r
+> in place, or I could add a nil :binary-content property when parts are\r
+> created (since plist-put is guaranteed to mutate existing keys in\r
+> place).\r
+\r
+I think a comment is fine. \r
+\r
+(Incidentally what is the best way of telling if emacs has changed an\r
+object or returned a new one for other commands? Something like (setq\r
+oldobject object) (setq object (operation-on object)) (if (eq object\r
+oldobject) ... ))\r
+\r
+Also, I think the function should have a comment about the lifetime of\r
+the caching. I think in some cases the addition of :binary-content could\r
+occur on load and thus the plist with binary content added would get\r
+saved in the buffer when the msg plist was saved as a\r
+text-property. However, maybe in other cases this gets called after the\r
+initial insertion and thus the cached value is just used during this\r
+operation on msg? Sorry that is a little incoherent as I haven't checked\r
+all callers.\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+\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