From: Austin Clements Date: Sat, 24 Jan 2015 21:16:57 +0000 (+1900) Subject: [PATCH v2 2/8] emacs: Create an API for fetching parts as undecoded binary X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b58b588516c1478f156b82f66e466c2b5921ca83;p=notmuch-archives.git [PATCH v2 2/8] emacs: Create an API for fetching parts as undecoded binary --- diff --git a/34/21f0df5afa0a0932c833cdb51c1c613e8d75a5 b/34/21f0df5afa0a0932c833cdb51c1c613e8d75a5 new file mode 100644 index 000000000..a027b4af2 --- /dev/null +++ b/34/21f0df5afa0a0932c833cdb51c1c613e8d75a5 @@ -0,0 +1,199 @@ +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 BFB0C431FAF + for ; Sat, 24 Jan 2015 13:17:22 -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 YyaQVkyMB5bE for ; + Sat, 24 Jan 2015 13:17:19 -0800 (PST) +Received: from dmz-mailsec-scanner-4.mit.edu (dmz-mailsec-scanner-4.mit.edu + [18.9.25.15]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id AF61B431FD5 + for ; Sat, 24 Jan 2015 13:17:13 -0800 (PST) +X-AuditID: 1209190f-f79716d000000d1a-f8-54c40bd7d5d6 +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-4.mit.edu (Symantec Messaging Gateway) with SMTP + id 24.30.03354.7DB04C45; Sat, 24 Jan 2015 16:17:11 -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 t0OLH94W027945; + 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 t0OLH6Bn007450 + (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-0005RU-KV; Sat, 24 Jan 2015 16:17:05 -0500 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v2 2/8] emacs: Create an API for fetching parts as undecoded + binary +Date: Sat, 24 Jan 2015 16:16:57 -0500 +Message-Id: <1422134223-20739-3-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+NgFrrJIsWRmVeSWpSXmKPExsUixCmqrXud+0iIweXrwhY3WrsZLfbd2cJk + sXouj8X1mzOZLd6snMfqwOqx6/lfJo+ds+6yexz+upDF49mqW8weWw69Zw5gjeKySUnNySxL + LdK3S+DK2HfmDnvBUe2KX1/fszQwPlPuYuTkkBAwkXgw6y0LhC0mceHeerYuRi4OIYHFTBJ7 + N/9nh3A2Mkose72VBcK5yCTRcv8oM0iLkMAkRolDs9JAbDYBDYnftxYzgdgiAtISO+/OZgWx + mQXqJP7OOc8IYgsLBEss/H6ODcRmEVCVODl/BzuIzSvgIPH53xmgXg6gM+Qktq7zBglzCjhK + 3NiwiwVilYNE9+dGtgmM/AsYGVYxyqbkVunmJmbmFKcm6xYnJ+blpRbpmujlZpbopaaUbmIE + h6Ak/w7GbweVDjEKcDAq8fD++HcoRIg1say4MvcQoyQHk5Io76pfh0OE+JLyUyozEosz4otK + c1KLDzFKcDArifBe2ACU401JrKxKLcqHSUlzsCiJ8276wRciJJCeWJKanZpakFoEk5Xh4FCS + 4F3MdSRESLAoNT21Ii0zpwQhzcTBCTKcB2h4N0gNb3FBYm5xZjpE/hSjopQ4bzFIQgAkkVGa + B9cLSxGvGMWBXhHm3QdSxQNML3Ddr4AGMwENLth+AGRwSSJCSqqBsWdZZ5hrqr61ub+nRtOD + +jfNxrrTb9vckk58Pm95QVW3wBu1rjkdbeVesitOJm1+9+Vku/WR/DmMfqVr7/65Xb6Ibc8D + ldjbm/YwmSayLi5hE5rj5LM4/uuXDxM+eappr/HvmCjKncNYNCO48FR/NAtf3jblW2W8Z5s9 + Pv5yTjJlvXnGY2GpEktxRqKhFnNRcSIAptdlW+wCAAA= +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:17:23 -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 fd25f7c..d4b6684 100644 +--- a/emacs/notmuch-lib.el ++++ b/emacs/notmuch-lib.el +@@ -529,25 +529,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 df2389e..b3e339e 100644 +--- a/emacs/notmuch-show.el ++++ b/emacs/notmuch-show.el +@@ -579,16 +579,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) +@@ -2162,15 +2160,14 @@ (defun notmuch-show-stash-git-send-email (&optional no-in-reply-to) + + ;; 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 () +@@ -2178,10 +2175,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))))) +-- +2.1.3 +