From: Mark Walters Date: Sat, 28 Mar 2015 11:08:59 +0000 (+0000) Subject: [PATCH] emacs: show: hide large text attachments by default X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=26aea281122db1688b263b9cab2835ab66128531;p=notmuch-archives.git [PATCH] emacs: show: hide large text attachments by default --- diff --git a/b8/f809c5ce21de3092622c948cf703b5aa79d7cc b/b8/f809c5ce21de3092622c948cf703b5aa79d7cc new file mode 100644 index 000000000..bde59cfe5 --- /dev/null +++ b/b8/f809c5ce21de3092622c948cf703b5aa79d7cc @@ -0,0 +1,126 @@ +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 A46BA431FB6 + for ; Sat, 28 Mar 2015 04:08:17 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 2.639 +X-Spam-Level: ** +X-Spam-Status: No, score=2.639 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + DNS_FROM_AHBL_RHSBL=2.438, FREEMAIL_ENVFROM_END_DIGIT=1, + FREEMAIL_FROM=0.001, 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 BlZt97eDsxAo for ; + Sat, 28 Mar 2015 04:08:14 -0700 (PDT) +Received: from mail-wg0-f41.google.com (mail-wg0-f41.google.com + [74.125.82.41]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client + certificate requested) by olra.theworths.org (Postfix) with ESMTPS id + 432B1431FAF for ; Sat, 28 Mar 2015 04:08:14 -0700 + (PDT) +Received: by wgbdm7 with SMTP id dm7so17633174wgb.1 + for ; Sat, 28 Mar 2015 04:08:13 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id; + bh=iu2mTT7BON9Mgfd6c8wJioc9uW8X7F3tTsGjfsbOWgg=; + b=SU6jB9HUT8gdTr6hoNgKALgxed+klzq115yzhkluLCOBzb+LwbAaLFIL8rFf9rJt9u + vxfEr1wn+5+rVLUi5xjjMEqfj/y8yP370ZV6X5ID36mHOwBpZDsvPohIGXZrx3Im/pQT + rq63mnGAtopB7aAIO4VHouht7Qg6yXBZZSgwssGajpM2vFWnnSH6b63GN2uJTYUtcMoc + T5WlT2oXK0x6ehQr0/o44RogK29BTt+Ahe6xS3tUb8OYIpW7MEBnTRrY7+g2+dafAu3T + /3x/IPIkIya8knB1qoQZ+5DAhQPeNAm6KzDfUrdljFdIiFBIrZmLzfns7Ils5QOslg0s + Ve6A== +X-Received: by 10.180.82.9 with SMTP id e9mr5344813wiy.88.1427540893023; + Sat, 28 Mar 2015 04:08:13 -0700 (PDT) +Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) + by mx.google.com with ESMTPSA id nb4sm6731097wjc.20.2015.03.28.04.08.12 + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Sat, 28 Mar 2015 04:08:12 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [PATCH] emacs: show: hide large text attachments by default +Date: Sat, 28 Mar 2015 11:08:59 +0000 +Message-Id: <1427540939-10055-1-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 2.1.4 +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, 28 Mar 2015 11:08:17 -0000 + +notmuch-show can be slow displaying large attachments so hide them by +default. The default maximum size is 10000 bytes/characters but it is +customizable. + +Note that notmuch-show-insert-bodypart is also called from the reply +code so we need to be a little careful. +--- + +This code is getting a little fragile -- there are quite a lot of +factors in deciding whether to show or hide a part and the code is +called from both show and reply -- but it seems to work. For testing I +suggest setting notmuch-show-max-text-part-size to something small +like 100 or 1000. + +Best wishes + +Mark + + +emacs/notmuch-show.el | 17 +++++++++++++++-- + 1 file changed, 15 insertions(+), 2 deletions(-) + +diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +index f4ad802..2a53461 100644 +--- a/emacs/notmuch-show.el ++++ b/emacs/notmuch-show.el +@@ -99,6 +99,13 @@ visible for any given message." + :group 'notmuch-show + :group 'notmuch-hooks) + ++(defcustom notmuch-show-max-text-part-size 10000 ++ "Maximum size of a text part to be shown by default in characters. ++ ++Set to 0 to show the part regardless of size." ++ :type 'integer ++ :group 'notmuch-show) ++ + ;; Mostly useful for debugging. + (defcustom notmuch-show-all-multipart/alternative-parts nil + "Should all parts of multipart/alternative parts be shown?" +@@ -937,14 +944,20 @@ useful for quoting in replies)." + "text/x-diff") + content-type)) + (nth (plist-get part :id)) ++ (long (and (notmuch-match-content-type mime-type "text/*") ++ (> notmuch-show-max-text-part-size 0) ++ (> (length (plist-get part :content)) notmuch-show-max-text-part-size))) + (beg (point)) +- ;; Hide the part initially if HIDE is t. +- (show-part (not (equal hide t))) + ;; We omit the part button for the first (or only) part if + ;; this is text/plain, or HIDE is 'no-buttons. + (button (unless (or (equal hide 'no-buttons) + (and (string= mime-type "text/plain") (<= nth 1))) + (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename)))) ++ ;; Hide the part initially if HIDE is t, or if it is too long ++ ;; and we have a button to allow toggling (thus reply which ++ ;; uses 'no-buttons automatically includes long parts) ++ (show-part (not (or (equal hide t) ++ (and long button)))) + (content-beg (point))) + + ;; Store the computed mime-type for later use (e.g. by attachment handlers). +-- +2.1.4 +