From 0783a1f6bb4033c597ea57face47721594d558d0 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Sun, 25 Jan 2015 16:17:00 +1900 Subject: [PATCH] [PATCH v2 5/8] emacs: Support caching in notmuch-get-bodypart-{binary, text} --- aa/8b022b70b73aa1143cbf94cab315261dc5ac8a | 180 ++++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 aa/8b022b70b73aa1143cbf94cab315261dc5ac8a diff --git a/aa/8b022b70b73aa1143cbf94cab315261dc5ac8a b/aa/8b022b70b73aa1143cbf94cab315261dc5ac8a new file mode 100644 index 000000000..57a38633e --- /dev/null +++ b/aa/8b022b70b73aa1143cbf94cab315261dc5ac8a @@ -0,0 +1,180 @@ +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 1F765431FAE + for ; Sat, 24 Jan 2015 13:17:19 -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 MrD7Oc5j5wk6 for ; + Sat, 24 Jan 2015 13:17:15 -0800 (PST) +Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu + [18.9.25.14]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id D8F83431FCB + for ; Sat, 24 Jan 2015 13:17:12 -0800 (PST) +X-AuditID: 1209190e-f799e6d000000cfe-91-54c40bd6bd45 +Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) + (using TLS with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP + id 24.73.03326.6DB04C45; Sat, 24 Jan 2015 16:17:10 -0500 (EST) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id t0OLH9fM000700; + 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 t0OLH6P5007459 + (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-0005Rf-Lu; Sat, 24 Jan 2015 16:17:05 -0500 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v2 5/8] emacs: Support caching in + notmuch-get-bodypart-{binary, text} +Date: Sat, 24 Jan 2015 16:17:00 -0500 +Message-Id: <1422134223-20739-6-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+NgFrrFIsWRmVeSWpSXmKPExsUixG6nonuN+0iIwbeTchY3WrsZLfbd2cJk + sXouj8X1mzOZLd6snMfqwOqx6/lfJo+ds+6yexz+upDF49mqW8weWw69Zw5gjeKySUnNySxL + LdK3S+DKaD85kb1gvXLFl4cz2BoYF8h0MXJySAiYSGw5+oAJwhaTuHBvPVsXIxeHkMBiJon+ + k9dYIJyNjBIvtqxkhnAuMklcPNDECOFMYpTomvWdEaSfTUBD4vetxWCzRASkJXbenc0KYjML + 1En8nXMerEZYIETi/8wPYHEWAVWJ7+uWs4PYvAIOEqfvPACKcwDdISexdZ03SJhTwFHixoZd + LCC2EFBJ9+dGtgmM/AsYGVYxyqbkVunmJmbmFKcm6xYnJ+blpRbpGuvlZpbopaaUbmIEBSGn + JN8Oxq8HlQ4xCnAwKvHwBjAeDhFiTSwrrsw9xCjJwaQkyrvqF1CILyk/pTIjsTgjvqg0J7X4 + EKMEB7OSCO+FDUA53pTEyqrUonyYlDQHi5I476YffCFCAumJJanZqakFqUUwWRkODiUJXkZg + tAkJFqWmp1akZeaUIKSZODhBhvMADWcFqeEtLkjMLc5Mh8ifYlSUEuf9ygWUEABJZJTmwfXC + ksQrRnGgV4R560GqeIAJBq77FdBgJqDBBdsPgAwuSURISTUwKviE3OaU9oyvv1S34p2lZ9em + ygcuZ4WUxfX/Jy3sDHojkfFqzdZE0bWr8mbWMohuXacXvuZZZJzVe8ZX+x/mB8W0Rd1/k1Nz + embk7tArnsy83gxVvXszc6Y3pr2/n9z0dl6hg2XOrWNbvypb5X6UmFX5/E6AiuaLW2ru2w3u + CcZfV3faMFFbiaU4I9FQi7moOBEAXsVqY+0CAAA= +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:19 -0000 + +(The actual code change here is small, but requires re-indenting +existing code.) +--- + emacs/notmuch-lib.el | 64 ++++++++++++++++++++++++++++++++-------------------- + 1 file changed, 40 insertions(+), 24 deletions(-) + +diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el +index 3154725..f8e5165 100644 +--- a/emacs/notmuch-lib.el ++++ b/emacs/notmuch-lib.el +@@ -529,39 +529,53 @@ (defun notmuch-parts-filter-by-type (parts type) + (lambda (part) (notmuch-match-content-type (plist-get part :content-type) type)) + parts)) + +-(defun notmuch-get-bodypart-binary (msg part process-crypto) ++(defun notmuch-get-bodypart-binary (msg part process-crypto &optional cache) + "Return the unprocessed content of PART in MSG as a unibyte string. + + 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 +- ;; Emacs internally uses a UTF-8-like multibyte string +- ;; representation by default (regardless of the coding system, +- ;; which only affects how it goes from outside data to this +- ;; internal representation). This *almost* never matters. +- ;; Annoyingly, it does matter if we use this data in an image +- ;; descriptor, since Emacs will use its internal data buffer +- ;; directly and this multibyte representation corrupts binary +- ;; image formats. Since the caller is asking for binary data, a +- ;; unibyte string is a more appropriate representation anyway. +- (set-buffer-multibyte nil) +- (let ((coding-system-for-read 'no-conversion)) +- (apply #'call-process notmuch-command nil '(t nil) nil args) +- (buffer-string))))) +- +-(defun notmuch-get-bodypart-text (msg part process-crypto) ++this does no charset conversion. ++ ++If CACHE is non-nil, the content of this part will be saved in ++MSG (if it isn't already)." ++ (let ((data (plist-get part :binary-content))) ++ (when (not data) ++ (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 ++ ;; Emacs internally uses a UTF-8-like multibyte string ++ ;; representation by default (regardless of the coding ++ ;; system, which only affects how it goes from outside data ++ ;; to this internal representation). This *almost* never ++ ;; matters. Annoyingly, it does matter if we use this data ++ ;; in an image descriptor, since Emacs will use its internal ++ ;; data buffer directly and this multibyte representation ++ ;; corrupts binary image formats. Since the caller is ++ ;; asking for binary data, a unibyte string is a more ++ ;; appropriate representation anyway. ++ (set-buffer-multibyte nil) ++ (let ((coding-system-for-read 'no-conversion)) ++ (apply #'call-process notmuch-command nil '(t nil) nil args) ++ (setq data (buffer-string))))) ++ (when cache ++ ;; Cheat. part is non-nil, and `plist-put' always modifies ++ ;; the list in place if it's non-nil. ++ (plist-put part :binary-content data))) ++ data)) ++ ++(defun notmuch-get-bodypart-text (msg part process-crypto &optional cache) + "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." ++non-text/* parts. ++ ++If CACHE is non-nil, the content of this part will be saved in ++MSG (if it isn't already)." + (let ((content (plist-get part :content))) + (when (not content) + ;; Use show --format=sexp to fetch decoded content +@@ -572,7 +586,9 @@ (defun notmuch-get-bodypart-text (msg part process-crypto) + (npart (apply #'notmuch-call-notmuch-sexp args))) + (setq content (plist-get npart :content)) + (when (not content) +- (error "Internal error: No :content from %S" args)))) ++ (error "Internal error: No :content from %S" args))) ++ (when cache ++ (plist-put part :content content))) + content)) + + ;; Workaround: The call to `mm-display-part' below triggers a bug in +-- +2.1.3 + -- 2.26.2