Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 21E62431FBD for ; Mon, 21 Apr 2014 11:38:13 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jMEI27mNBzIb for ; Mon, 21 Apr 2014 11:38:09 -0700 (PDT) Received: from dmz-mailsec-scanner-1.mit.edu (dmz-mailsec-scanner-1.mit.edu [18.9.25.12]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id C4267431FC2 for ; Mon, 21 Apr 2014 11:37:59 -0700 (PDT) X-AuditID: 1209190c-f794a6d000000c27-5f-535565873125 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) (using TLS with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP id 9F.C9.03111.78565535; Mon, 21 Apr 2014 14:37:59 -0400 (EDT) Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s3LIbu8r018334; Mon, 21 Apr 2014 14:37:57 -0400 Received: from drake.dyndns.org (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [216.15.114.40]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s3LIbsGQ029718 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Mon, 21 Apr 2014 14:37:56 -0400 Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1WcJ6I-0003l6-EL; Mon, 21 Apr 2014 14:37:54 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 06/11] emacs: Remove broken `notmuch-get-bodypart-content' API Date: Mon, 21 Apr 2014 14:37:43 -0400 Message-Id: <1398105468-14317-7-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1398105468-14317-1-git-send-email-amdragon@mit.edu> References: <1398105468-14317-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrAIsWRmVeSWpSXmKPExsUixCmqrdueGhps0HZC3uL6zZnMDowez1bd Yg5gjOKySUnNySxLLdK3S+DK+LLnGXtBp0ZFy7yjLA2MxxS6GDk5JARMJDYsmsEKYYtJXLi3 ng3EFhKYzSSxpUGji5ELyN7IKLFm+xEmCOcOk8Tpb7OYIKrmMkp8Op8HYrMJaEhs27+cEcQW EZCW2Hl3NtBUDg5mATWJP10qIKawgJ/ElZslIBUsAqoST27OA9vLK+Ag0TzrChvEDXISJ49N BotzCjhKtK1+yQ6xyUFiw941TBMY+RcwMqxilE3JrdLNTczMKU5N1i1OTszLSy3SNdTLzSzR S00p3cQIDhhJnh2Mbw4qHWIU4GBU4uGVMAgNFmJNLCuuzD3EKMnBpCTK+yoKKMSXlJ9SmZFY nBFfVJqTWnyIUYKDWUmEd70mUI43JbGyKrUoHyYlzcGiJM771toqWEggPbEkNTs1tSC1CCYr w8GhJMFrlwLUKFiUmp5akZaZU4KQZuLgBBnOAzQ8CqSGt7ggMbc4Mx0if4pRUUqclzEZKCEA ksgozYPrhUX0K0ZxoFeEed1B2nmAyQCu+xXQYCagwU+2hIAMLklESEk1MBo8vL4le+Izns2P Z6/QkOuxl3++x2zpw/0somWsLsc9881EVUSCimZXJZ+XcpHnqL58Y+K9K187824vszdme3A7 YHs+x9qA+cmSVwTrhNxETZuedzXXVXhWe1nrm85b39ffvf5qSb5skljx+RVOfLKz7PlPls86 MOPzhr0NwkaPNN88y36ZrcRSnJFoqMVcVJwIAJy2+QrDAgAA X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Apr 2014 18:38:13 -0000 `notmuch-get-bodypart-content' could do two very different things, depending on conditions: for text/* parts other than text/html, it would return the part content as a multibyte Lisp string *after* charset conversion, while for other parts (including text/html), it would return binary part content without charset conversion. This commit completes the split of `notmuch-get-bodypart-content' into two different and explicit APIs: `notmuch-get-bodypart-binary' and `notmuch-get-bodypart-text'. It updates all callers to use one or the other depending on what's appropriate. --- emacs/notmuch-lib.el | 37 ++++++++++++++++++++++++++++--------- emacs/notmuch-show.el | 8 ++++---- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 4711098..ece29c3 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -519,9 +519,25 @@ (defun notmuch-get-bodypart-binary (msg part process-crypto) (apply #'call-process notmuch-command nil '(t nil) nil args) (buffer-string))))) -(defun notmuch-get-bodypart-content (msg part process-crypto) - (or (plist-get part :content) - (notmuch-get-bodypart-binary msg part process-crypto))) +(defun notmuch-get-bodypart-text (msg part process-crypto) + "Return the text content of PART in MSG. + +This returns the content of the given part as a multibyte Lisp +string after performing content transfer decoding and any +necessary charset decoding. It is an error to use this for +non-text/* parts." + (let ((content (plist-get part :content))) + (when (not content) + ;; Use show --format=sexp to fetch decoded content + (let* ((args `("show" "--format=sexp" "--include-html" + ,(format "--part=%s" (plist-get part :id)) + ,@(when process-crypto '("--decrypt")) + ,(notmuch-id-to-query (plist-get msg :id)))) + (npart (apply #'notmuch-call-notmuch-sexp args))) + (setq content (plist-get npart :content)) + (when (not content) + (error "Internal error: No :content from %S" args)))) + content)) ;; Workaround: The call to `mm-display-part' below triggers a bug in ;; Emacs 24 if it attempts to use the shr renderer to display an HTML @@ -542,18 +558,21 @@ (defun notmuch-mm-display-part-inline (msg part content-type process-crypto) current buffer, if possible." (let ((display-buffer (current-buffer))) (with-temp-buffer - ;; In case there is :content, the content string is already converted - ;; into emacs internal format. `gnus-decoded' is a fake charset, - ;; which means no further decoding (to be done by mm- functions). - (let* ((charset (if (plist-member part :content) - 'gnus-decoded + ;; In case we already have :content, use it and tell mm-* that + ;; it's already been charset-decoded by using the fake + ;; `gnus-decoded' charset. Otherwise, we'll fetch the binary + ;; part content and let mm-* decode it. + (let* ((have-content (plist-member part :content)) + (charset (if have-content 'gnus-decoded (plist-get part :content-charset))) (handle (mm-make-handle (current-buffer) `(,content-type (charset . ,charset))))) ;; If the user wants the part inlined, insert the content and ;; test whether we are able to inline it (which includes both ;; capability and suitability tests). (when (mm-inlined-p handle) - (insert (notmuch-get-bodypart-content msg part process-crypto)) + (if have-content + (insert (notmuch-get-bodypart-text msg part process-crypto)) + (insert (notmuch-get-bodypart-binary msg part process-crypto))) (when (mm-inlinable-p handle) (set-buffer display-buffer) (mm-display-part handle) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index e9867fd..537c558 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -680,7 +680,7 @@ (defun notmuch-show-insert-part-text/plain (msg part content-type nth depth butt (let ((start (if button (button-start button) (point)))) - (insert (notmuch-get-bodypart-content msg part notmuch-show-process-crypto)) + (insert (notmuch-get-bodypart-text msg part notmuch-show-process-crypto)) (save-excursion (save-restriction (narrow-to-region start (point-max)) @@ -689,9 +689,9 @@ (defun notmuch-show-insert-part-text/plain (msg part content-type nth depth butt (defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth button) (insert (with-temp-buffer - (insert (notmuch-get-bodypart-content msg part notmuch-show-process-crypto)) - ;; notmuch-get-bodypart-content provides "raw", non-converted - ;; data. Replace CRLF with LF before icalendar can use it. + (insert (notmuch-get-bodypart-text msg part notmuch-show-process-crypto)) + ;; notmuch-get-bodypart-text does no newline conversion. + ;; Replace CRLF with LF before icalendar can use it. (goto-char (point-min)) (while (re-search-forward "\r\n" nil t) (replace-match "\n" nil nil)) -- 1.9.1