[PATCH] emacs: show: allow user to hide some mime types by default.

Mark Walters markwalters1009 at gmail.com
Thu Jan 22 13:07:32 PST 2015


This commit adds a customize variable that allows the user to choose
to hide some mime types by default. They can still choose to view the
part by toggling the part button.

One use is for hiding all text/html parts. This would mean that some
explicit user action was required before the part was loaded which
would mitigate some of the problems of remote image loading by the
emacs html renderer as detailed by dkg in
id:87ppa7q25w.fsf at alice.fifthhorseman.net.
---

I think this might be useful anyway (dkg asked for it before he found
the bug) but seems particularly relevant now.

To use set the variable notmuch-show-always-hide-types to '(text/html)
or use the customize setting to add text/html to the list.

Given the lack of control we have over the emacs renderers (so
possibility of future problems) we could even set this by default.

Best wishes

Mark

emacs/notmuch-show.el | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 9f6fe07..8f49f17 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -234,6 +234,15 @@ every user interaction with notmuch."
   :type 'function
   :group 'notmuch-show)
 
+(defcustom notmuch-show-always-hide-types nil
+  "List of mime types that should always be hidden.
+
+This is a list of mime types that should be initally displayed in
+the show buffer as hidden parts; they can be displayed by
+toggling the part button. Wildcards are allowed in the list."
+  :type '(repeat string)
+  :group 'notmuch-show)
+
 (defmacro with-current-notmuch-show-message (&rest body)
   "Evaluate body with current buffer set to the text of current message"
   `(save-excursion
@@ -798,6 +807,12 @@ message at DEPTH in the current thread."
 		(intern (concat "notmuch-show-insert-part-" content-type))))
     result))
 
+(defun notmuch-show-always-hide (mime-type)
+  "Is mime-type in notmuch-show-always-hide-types"
+  (let (match)
+    (dolist (type notmuch-show-always-hide-types match)
+      (setq match (or match (notmuch-match-content-type mime-type type))))))
+
 ;; 
 
 (defun notmuch-show-insert-bodypart-internal (msg part content-type nth depth button)
@@ -900,7 +915,8 @@ useful for quoting in replies)."
 	 (nth (plist-get part :id))
 	 (beg (point))
 	 ;; Hide the part initially if HIDE is t.
-	 (show-part (not (equal hide t)))
+	 (show-part (and (not (equal hide t))
+			 (not (notmuch-show-always-hide mime-type))))
 	 ;; 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)
-- 
2.1.4



More information about the notmuch mailing list