[PATCH] emacs: show: hide large text attachments by default
authorMark Walters <markwalters1009@gmail.com>
Sat, 28 Mar 2015 11:08:59 +0000 (11:08 +0000)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:48:37 +0000 (14:48 -0700)
b8/f809c5ce21de3092622c948cf703b5aa79d7cc [new file with mode: 0644]

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