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 5EFF8431FC3 for ; Mon, 21 Apr 2014 11:38:44 -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 rpLKhZAtG2dk for ; Mon, 21 Apr 2014 11:38:39 -0700 (PDT) Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu [18.7.68.37]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 63D2C431FD9 for ; Mon, 21 Apr 2014 11:38:08 -0700 (PDT) X-AuditID: 12074425-f79906d000000cf9-30-5355658f8c71 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) (using TLS with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP id BA.F3.03321.F8565535; Mon, 21 Apr 2014 14:38:07 -0400 (EDT) Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s3LIbuiq022319; 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 s3LIbslQ029716 (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-0003l3-Di; Mon, 21 Apr 2014 14:37:54 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 05/11] emacs: Create an API for fetching parts as undecoded binary Date: Mon, 21 Apr 2014 14:37:42 -0400 Message-Id: <1398105468-14317-6-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+NgFtrMIsWRmVeSWpSXmKPExsUixG6nrtufGhpscG6vpcX1mzOZHRg9nq26 xRzAGMVlk5Kak1mWWqRvl8CV0dV2kr3goHbFhtsr2RoYHyl3MXJySAiYSEyfMIsZwhaTuHBv PVsXIxeHkMBsJolv608wQjgbGSVWNjyDcu4wSfxt72GFcOYySpw/eJMFpJ9NQENi2/7ljCC2 iIC0xM67s4GKODiYBdQk/nSpgISFBYIkDm74DVbCIqAqsffOPrBWXgEHiU/rn7JBnCEncfLY ZFYQm1PAUaJt9Ut2EFsIqGbD3jVMExj5FzAyrGKUTcmt0s1NzMwpTk3WLU5OzMtLLdK10MvN LNFLTSndxAgOGxfVHYwTDikdYhTgYFTi4S0wCg0WYk0sK67MPcQoycGkJMr7KgooxJeUn1KZ kVicEV9UmpNafIhRgoNZSYR3vSZQjjclsbIqtSgfJiXNwaIkzvvW2ipYSCA9sSQ1OzW1ILUI JivDwaEkwZuWAtQoWJSanlqRlplTgpBm4uAEGc4DNDwKpIa3uCAxtzgzHSJ/ilFRSpy3DSQh AJLIKM2D64XF9StGcaBXhHndQap4gCkBrvsV0GAmoMFPtoSADC5JREhJNTCukuPUnRy246Hr sRl1u6yvaHz1/du+yvluj75S0Wa5wjqZ37Kun4UUur9H6wlOteSVaXqXZiSz9vyVMv17Z0oY fGLu79AOSXs4d+s+jz1753wrSb31/lSqwHMGG5/e5fEqqi0bD3+cznI76ecE1VN2Wo7h0588 FdvZt3amj515yuYd55gmFt1QYinOSDTUYi4qTgQAUoxbP8YCAAA= 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:44 -0000 The new function, `notmuch-get-bodypart-binary', replaces `notmuch-get-bodypart-internal'. Whereas the old function was really meant for internal use in `notmuch-get-bodypart-content', it was used in a few other places. Since the difference between `notmuch-get-bodypart-content' and `notmuch-get-bodypart-internal' was unclear, these other uses were always confusing and potentially inconsistent. The new call clearly requests the part as undecoded binary. This is step 1 of 2 in separating `notmuch-get-bodypart-content' into two APIs for retrieving either undecoded binary or decoded text. --- emacs/notmuch-lib.el | 28 ++++++++++++++-------------- emacs/notmuch-show.el | 22 +++++++++------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 35b9065..4711098 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -503,25 +503,25 @@ (defun notmuch-parts-filter-by-type (parts type) (lambda (part) (notmuch-match-content-type (plist-get part :content-type) type)) parts)) -;; Helper for parts which are generally not included in the default -;; SEXP output. -(defun notmuch-get-bodypart-internal (query part-number process-crypto) - (let ((args '("show" "--format=raw")) - (part-arg (format "--part=%s" part-number))) - (setq args (append args (list part-arg))) - (if process-crypto - (setq args (append args '("--decrypt")))) - (setq args (append args (list query))) +(defun notmuch-get-bodypart-binary (msg part process-crypto) + "Return the unprocessed content of PART in MSG. + +This returns the \"raw\" content of the given part after content +transfer decoding, but with no further processing (see the +discussion of --format=raw in man notmuch-show). In particular, +this does no charset conversion." + (let ((args `("show" "--format=raw" + ,(format "--part=%d" (plist-get part :id)) + ,@(when process-crypto '("--decrypt")) + ,(notmuch-id-to-query (plist-get msg :id))))) (with-temp-buffer (let ((coding-system-for-read 'no-conversion)) - (progn - (apply 'call-process (append (list notmuch-command nil (list t nil) nil) args)) - (buffer-string)))))) + (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-internal (notmuch-id-to-query (plist-get msg :id)) - (plist-get part :id) process-crypto))) + (notmuch-get-bodypart-binary msg part process-crypto))) ;; 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 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 455cfee..e9867fd 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -557,16 +557,14 @@ (defun notmuch-show-w3m-cid-retrieve (url &rest args) (let* ((msg (nth 1 matching-part)) (part (nth 2 matching-part)) (content (nth 3 matching-part)) - (message-id (plist-get msg :id)) - (part-number (plist-get part :id)) (content-type (plist-get part :content-type))) ;; If we don't already have the content, get it and cache ;; it, as some messages reference the same cid: part many ;; times (hundreds!), which results in many calls to ;; `notmuch part'. (unless content - (setq content (notmuch-get-bodypart-internal (notmuch-id-to-query message-id) - part-number notmuch-show-process-crypto)) + (setq content (notmuch-get-bodypart-binary + msg part notmuch-show-process-crypto)) (with-current-buffer w3m-current-buffer (notmuch-show-w3m-cid-store-internal url msg part content))) (insert content) @@ -2067,15 +2065,14 @@ (defun notmuch-show-stash-mlarchive-link-and-go (&optional mla) ;; Interactive part functions and their helpers -(defun notmuch-show-generate-part-buffer (message-id nth) +(defun notmuch-show-generate-part-buffer (msg part) "Return a temporary buffer containing the specified part's content." (let ((buf (generate-new-buffer " *notmuch-part*")) (process-crypto notmuch-show-process-crypto)) (with-current-buffer buf - (setq notmuch-show-process-crypto process-crypto) - ;; Always acquires the part via `notmuch part', even if it is - ;; available in the SEXP output. - (insert (notmuch-get-bodypart-internal message-id nth notmuch-show-process-crypto))) + ;; This is always used in the content of mm handles, which + ;; expect undecoded, binary part content. + (insert (notmuch-get-bodypart-binary msg part process-crypto))) buf)) (defun notmuch-show-current-part-handle () @@ -2083,10 +2080,9 @@ (defun notmuch-show-current-part-handle () This creates a temporary buffer for the part's content; the caller is responsible for killing this buffer as appropriate." - (let* ((part (notmuch-show-get-part-properties)) - (message-id (notmuch-show-get-message-id)) - (nth (plist-get part :id)) - (buf (notmuch-show-generate-part-buffer message-id nth)) + (let* ((msg (notmuch-show-get-message-properties)) + (part (notmuch-show-get-part-properties)) + (buf (notmuch-show-generate-part-buffer msg part)) (computed-type (plist-get part :computed-type)) (filename (plist-get part :filename)) (disposition (if filename `(attachment (filename . ,filename))))) -- 1.9.1