--- /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 21E62431FBD\r
+ for <notmuch@notmuchmail.org>; Mon, 21 Apr 2014 11:38:13 -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 jMEI27mNBzIb for <notmuch@notmuchmail.org>;\r
+ Mon, 21 Apr 2014 11:38:09 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-1.mit.edu (dmz-mailsec-scanner-1.mit.edu\r
+ [18.9.25.12])\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 C4267431FC2\r
+ for <notmuch@notmuchmail.org>; Mon, 21 Apr 2014 11:37:59 -0700 (PDT)\r
+X-AuditID: 1209190c-f794a6d000000c27-5f-535565873125\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+ (using TLS with cipher AES256-SHA (256/256 bits))\r
+ (Client did not present a certificate)\r
+ by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 9F.C9.03111.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-3.mit.edu (8.13.8/8.9.2) with ESMTP id s3LIbu8r018334; \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 s3LIbsGQ029718\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-0003l6-EL; Mon, 21 Apr 2014 14:37:54 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 06/11] emacs: Remove broken `notmuch-get-bodypart-content' API\r
+Date: Mon, 21 Apr 2014 14:37:43 -0400\r
+Message-Id: <1398105468-14317-7-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+NgFtrAIsWRmVeSWpSXmKPExsUixCmqrdueGhps0HZC3uL6zZnMDowez1bd\r
+ Yg5gjOKySUnNySxLLdK3S+DK+LLnGXtBp0ZFy7yjLA2MxxS6GDk5JARMJDYsmsEKYYtJXLi3\r
+ ng3EFhKYzSSxpUGji5ELyN7IKLFm+xEmCOcOk8Tpb7OYIKrmMkp8Op8HYrMJaEhs27+cEcQW\r
+ EZCW2Hl3NtBUDg5mATWJP10qIKawgJ/ElZslIBUsAqoST27OA9vLK+Ag0TzrChvEDXISJ49N\r
+ BotzCjhKtK1+yQ6xyUFiw941TBMY+RcwMqxilE3JrdLNTczMKU5N1i1OTszLSy3SNdTLzSzR\r
+ S00p3cQIDhhJnh2Mbw4qHWIU4GBU4uGVMAgNFmJNLCuuzD3EKMnBpCTK+yoKKMSXlJ9SmZFY\r
+ nBFfVJqTWnyIUYKDWUmEd70mUI43JbGyKrUoHyYlzcGiJM771toqWEggPbEkNTs1tSC1CCYr\r
+ w8GhJMFrlwLUKFiUmp5akZaZU4KQZuLgBBnOAzQ8CqSGt7ggMbc4Mx0if4pRUUqclzEZKCEA\r
+ ksgozYPrhUX0K0ZxoFeEed1B2nmAyQCu+xXQYCagwU+2hIAMLklESEk1MBo8vL4le+Izns2P\r
+ Z6/QkOuxl3++x2zpw/0somWsLsc9881EVUSCimZXJZ+XcpHnqL58Y+K9K187824vszdme3A7\r
+ YHs+x9qA+cmSVwTrhNxETZuedzXXVXhWe1nrm85b39ffvf5qSb5skljx+RVOfLKz7PlPls86\r
+ MOPzhr0NwkaPNN88y36ZrcRSnJFoqMVcVJwIAJy2+QrDAgAA\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:13 -0000\r
+\r
+`notmuch-get-bodypart-content' could do two very different things,\r
+depending on conditions: for text/* parts other than text/html, it\r
+would return the part content as a multibyte Lisp string *after*\r
+charset conversion, while for other parts (including text/html), it\r
+would return binary part content without charset conversion.\r
+\r
+This commit completes the split of `notmuch-get-bodypart-content' into\r
+two different and explicit APIs: `notmuch-get-bodypart-binary' and\r
+`notmuch-get-bodypart-text'. It updates all callers to use one or the\r
+other depending on what's appropriate.\r
+---\r
+ emacs/notmuch-lib.el | 37 ++++++++++++++++++++++++++++---------\r
+ emacs/notmuch-show.el | 8 ++++----\r
+ 2 files changed, 32 insertions(+), 13 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index 4711098..ece29c3 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -519,9 +519,25 @@ (defun notmuch-get-bodypart-binary (msg part process-crypto)\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-binary msg part process-crypto)))\r
++(defun notmuch-get-bodypart-text (msg part process-crypto)\r
++ "Return the text content of PART in MSG.\r
++\r
++This returns the content of the given part as a multibyte Lisp\r
++string after performing content transfer decoding and any\r
++necessary charset decoding. It is an error to use this for\r
++non-text/* parts."\r
++ (let ((content (plist-get part :content)))\r
++ (when (not content)\r
++ ;; Use show --format=sexp to fetch decoded content\r
++ (let* ((args `("show" "--format=sexp" "--include-html"\r
++ ,(format "--part=%s" (plist-get part :id))\r
++ ,@(when process-crypto '("--decrypt"))\r
++ ,(notmuch-id-to-query (plist-get msg :id))))\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
++ content))\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
+@@ -542,18 +558,21 @@ (defun notmuch-mm-display-part-inline (msg part content-type process-crypto)\r
+ current buffer, if possible."\r
+ (let ((display-buffer (current-buffer)))\r
+ (with-temp-buffer\r
+- ;; In case there is :content, the content string is already converted\r
+- ;; into emacs internal format. `gnus-decoded' is a fake charset,\r
+- ;; which means no further decoding (to be done by mm- functions).\r
+- (let* ((charset (if (plist-member part :content)\r
+- 'gnus-decoded\r
++ ;; In case we already have :content, use it and tell mm-* that\r
++ ;; it's already been charset-decoded by using the fake\r
++ ;; `gnus-decoded' charset. Otherwise, we'll fetch the binary\r
++ ;; part content and let mm-* decode it.\r
++ (let* ((have-content (plist-member part :content))\r
++ (charset (if have-content 'gnus-decoded\r
+ (plist-get part :content-charset)))\r
+ (handle (mm-make-handle (current-buffer) `(,content-type (charset . ,charset)))))\r
+ ;; If the user wants the part inlined, insert the content and\r
+ ;; test whether we are able to inline it (which includes both\r
+ ;; capability and suitability tests).\r
+ (when (mm-inlined-p handle)\r
+- (insert (notmuch-get-bodypart-content msg part process-crypto))\r
++ (if have-content\r
++ (insert (notmuch-get-bodypart-text msg part process-crypto))\r
++ (insert (notmuch-get-bodypart-binary msg part process-crypto)))\r
+ (when (mm-inlinable-p handle)\r
+ (set-buffer display-buffer)\r
+ (mm-display-part handle)\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index e9867fd..537c558 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -680,7 +680,7 @@ (defun notmuch-show-insert-part-text/plain (msg part content-type nth depth butt\r
+ (let ((start (if button\r
+ (button-start button)\r
+ (point))))\r
+- (insert (notmuch-get-bodypart-content msg part notmuch-show-process-crypto))\r
++ (insert (notmuch-get-bodypart-text msg part notmuch-show-process-crypto))\r
+ (save-excursion\r
+ (save-restriction\r
+ (narrow-to-region start (point-max))\r
+@@ -689,9 +689,9 @@ (defun notmuch-show-insert-part-text/plain (msg part content-type nth depth butt\r
+ \r
+ (defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth button)\r
+ (insert (with-temp-buffer\r
+- (insert (notmuch-get-bodypart-content msg part notmuch-show-process-crypto))\r
+- ;; notmuch-get-bodypart-content provides "raw", non-converted\r
+- ;; data. Replace CRLF with LF before icalendar can use it.\r
++ (insert (notmuch-get-bodypart-text msg part notmuch-show-process-crypto))\r
++ ;; notmuch-get-bodypart-text does no newline conversion.\r
++ ;; Replace CRLF with LF before icalendar can use it.\r
+ (goto-char (point-min))\r
+ (while (re-search-forward "\r\n" nil t)\r
+ (replace-match "\n" nil nil))\r
+-- \r
+1.9.1\r
+\r