From 614f88df919c3e2d6fb5beb9823cbf37e996d874 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 22 Apr 2014 14:37:45 +2000 Subject: [PATCH] [PATCH 08/11] emacs: Support caching in notmuch-get-bodypart-{binary, text} --- 39/efea7c16ae589bfe956a7e463bf8e8c1911838 | 162 ++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 39/efea7c16ae589bfe956a7e463bf8e8c1911838 diff --git a/39/efea7c16ae589bfe956a7e463bf8e8c1911838 b/39/efea7c16ae589bfe956a7e463bf8e8c1911838 new file mode 100644 index 000000000..4c8f3a440 --- /dev/null +++ b/39/efea7c16ae589bfe956a7e463bf8e8c1911838 @@ -0,0 +1,162 @@ +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 A8852431E62 + for ; Mon, 21 Apr 2014 11:38:14 -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 Ea7DYpC9RmEE for ; + Mon, 21 Apr 2014 11:38:10 -0700 (PDT) +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 3671B431FC3 + for ; Mon, 21 Apr 2014 11:38:00 -0700 (PDT) +X-AuditID: 1209190f-f790b6d000000c3a-cd-535565874487 +Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP + id 26.C8.03130.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-2.mit.edu (8.13.8/8.9.2) with ESMTP id s3LIbuwI009463; + 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 s3LIbsO6029722 + (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-0003lC-GB; Mon, 21 Apr 2014 14:37:54 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH 08/11] emacs: Support caching in notmuch-get-bodypart-{binary, + text} +Date: Mon, 21 Apr 2014 14:37:45 -0400 +Message-Id: <1398105468-14317-9-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+NgFtrEIsWRmVeSWpSXmKPExsUixG6notueGhpscOCLkMX1mzOZHRg9nq26 + xRzAGMVlk5Kak1mWWqRvl8CVsXDXHeaCnXIVJ68dZmpg3CjRxcjJISFgIrFi7wMmCFtM4sK9 + 9WwgtpDAbCaJhi9GXYxcQPZGRonm4+dYIZw7TBLTZ/xhgnDmMkrc23GbFaSFTUBDYtv+5Ywg + toiAtMTOu7OB4hwczAJqEn+6VEDCwgLBEt9mtoKVsAioSmzfcZkFxOYVcJBYcHING8QVchIn + j00GG8kp4CjRtvolO8RFDhIb9q5hmsDIv4CRYRWjbEpulW5uYmZOcWqybnFyYl5eapGuiV5u + ZoleakrpJkZQ0HBK8u9g/HZQ6RCjAAejEg+vhEFosBBrYllxZe4hRkkOJiVR3ldRQCG+pPyU + yozE4oz4otKc1OJDjBIczEoivOs1gXK8KYmVValF+TApaQ4WJXHet9ZWwUIC6YklqdmpqQWp + RTBZGQ4OJQnehSlAjYJFqempFWmZOSUIaSYOTpDhPEDDL4LU8BYXJOYWZ6ZD5E8xKkqJ87aB + JARAEhmleXC9sKh+xSgO9IowbwtIFQ8wIcB1vwIazAQ0+MmWEJDBJYkIKakGRjuLGcfurPb5 + ES0R/Gtihsj2K+qxHcu61ecenKV+qm27sMD3qgfTYzYya+vqlMi+u9+6espfgTougbfb9Neo + Z/Ut3TNn9YPkRIMt9/+++zq/tlBE7boAu9PGYPZf3r/dEySPbFt/xie7N6PGcvV+c/ZFAmbm + QhEMq+eZvfcq3Pqm789nlykWjkosxRmJhlrMRcWJAJUML5HFAgAA +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:15 -0000 + +(The actual code change here is small, but requires re-indenting +existing code.) +--- + emacs/notmuch-lib.el | 52 ++++++++++++++++++++++++++++++---------------------- + 1 file changed, 30 insertions(+), 22 deletions(-) + +diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el +index fc67b14..fee8512 100644 +--- a/emacs/notmuch-lib.el ++++ b/emacs/notmuch-lib.el +@@ -503,33 +503,39 @@ (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) ++ (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 ++ (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 +@@ -546,7 +552,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 +-- +1.9.1 + -- 2.26.2