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 914B5431FD5 for ; Sat, 24 Jan 2015 13:18:02 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.138 X-Spam-Level: X-Spam-Status: No, score=0.138 tagged_above=-999 required=5 tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_MED=-2.3] 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 9K2thYHTkCG8 for ; Sat, 24 Jan 2015 13:17:59 -0800 (PST) Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu [18.7.68.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 59341429E29 for ; Sat, 24 Jan 2015 13:17:21 -0800 (PST) X-AuditID: 12074423-f797b6d000000cfe-e0-54c40be07960 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) (using TLS with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP id DE.64.03326.0EB04C45; Sat, 24 Jan 2015 16:17:20 -0500 (EST) 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 t0OLH9Mh027943; Sat, 24 Jan 2015 16:17:09 -0500 Received: from drake (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 t0OLH6UH007454 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Sat, 24 Jan 2015 16:17:07 -0500 Received: from amthrax by drake with local (Exim 4.84) (envelope-from ) id 1YF84n-0005RX-Ky; Sat, 24 Jan 2015 16:17:05 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v2 3/8] emacs: Remove broken `notmuch-get-bodypart-content' API Date: Sat, 24 Jan 2015 16:16:58 -0500 Message-Id: <1422134223-20739-4-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1422134223-20739-1-git-send-email-amdragon@mit.edu> References: <1422134223-20739-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrJIsWRmVeSWpSXmKPExsUixCmqrfuA+0iIwfHJihY3WrsZLfbd2cJk sXouj8X1mzOZLd6snMfqwOqx6/lfJo+ds+6yexz+upDF49mqW8weWw69Zw5gjeKySUnNySxL LdK3S+DKmHGqm6mgU6Pix/QTrA2MxxS6GDk5JARMJJacvMwEYYtJXLi3ng3EFhJYzCRx8bZ9 FyMXkL2RUeLpuk+MEM5FJokbZy6zQDiTGCVezpwP1s4moCHx+9ZiMFtEQFpi593ZrCA2s0Cd xN855xlBbGEBf4kLV7rZQWwWAVWJNzeXgtm8Ag4SS1c3Aa3mADpDTmLrOm+QMKeAo8SNDbtY IC5ykOj+3Mg2gZF/ASPDKkbZlNwq3dzEzJzi1GTd4uTEvLzUIl0zvdzMEr3UlNJNjKAQZHdR 3sH456DSIUYBDkYlHt4f/w6FCLEmlhVX5h5ilORgUhLlXfXrcIgQX1J+SmVGYnFGfFFpTmrx IUYJDmYlEd4LG4ByvCmJlVWpRfkwKWkOFiVx3k0/+EKEBNITS1KzU1MLUotgsjIcHEoSvIzA WBMSLEpNT61Iy8wpQUgzcXCCDOcBGs4KUsNbXJCYW5yZDpE/xagoJc77lQsoIQCSyCjNg+uF pYhXjOJArwjz1oNU8QDTC1z3K6DBTECDC7YfABlckoiQkmpgXD/n+A5J/32GvtMMrPibUiND T2tXmFpMzV7Rp2jF4L+4Xul77sKrGR8Ddi5ez7FmUdJHNZXssu3OT+pl31yfVyCzbMNmNX+l S1JrrlcGr591VLKye9d18950XZF3eobPOX+FaZiFnlCdE7D3WcXcrvIDO9Y+vauc5PFp+R61 gNklD36s8fZpVmIpzkg01GIuKk4EAPTnEprsAgAA Cc: tomi.ollila@iki.fi 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: Sat, 24 Jan 2015 21:18:03 -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 d4b6684..a0a95d8 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -545,9 +545,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 @@ -568,18 +584,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 b3e339e..f29428a 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -702,7 +702,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)) @@ -711,9 +711,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)) -- 2.1.3