From fd46fc1977e3b0712c07cc4610edee2d91ec5ee0 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sat, 14 May 2022 08:26:38 -0300 Subject: [PATCH] emacs: document/defcustom notmuch-multipart/alternative-discouraged This variable is important for people who want to change the default behaviour when displaying multipart/alternative messages. Previously it was undocumented. Add a defcustom to help users and copy some documentation from the wiki. The usual machinery of re-using docstrings is a bit tricky to use here because it mangles the example lisp code, and the link to the info node should not be in e.g. the html page. Add a simple test to make sure the switch from defvar to defcustom did not break something obvious. --- doc/notmuch-emacs.rst | 21 +++++++ emacs/notmuch-lib.el | 12 +++- test/T450-emacs-show.sh | 4 ++ .../notmuch-show-multipart-alternative | 62 +++++++++++++++++++ 4 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 test/emacs-show.expected-output/notmuch-show-multipart-alternative diff --git a/doc/notmuch-emacs.rst b/doc/notmuch-emacs.rst index 67dbfc2b..ec7dee78 100644 --- a/doc/notmuch-emacs.rst +++ b/doc/notmuch-emacs.rst @@ -238,6 +238,27 @@ Display of messages can be controlled by the following variables :index:`notmuch-show-header-line` |docstring::notmuch-show-header-line| +:index:`notmuch-multipart/alternative-discouraged` + + Which mime types to hide by default for multipart messages. + + Can either be a list of mime types (as strings) or a function + mapping a plist representing the current message to such a list. + The following example function would discourage `text/html` and + `multipart/related` generally, but discourage `text/plain` should + the message be sent from `whatever@example.com`. + + .. code:: lisp + + (defun my--determine-discouraged (msg) + (let* ((headers (plist-get msg :headers)) + (from (or (plist-get headers :From) ""))) + (cond + ((string-match "whatever@example.com" from) + (list "text/plain")) + (t + (list "text/html" "multipart/related"))))) + .. _show-copy: Copy to kill-ring diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 1cc7e9c4..1e631d0e 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -567,12 +567,20 @@ Take wildcards into account." (string= (downcase t1) (downcase t2)))))) -(defvar notmuch-multipart/alternative-discouraged +(defcustom notmuch-multipart/alternative-discouraged '(;; Avoid HTML parts. "text/html" ;; multipart/related usually contain a text/html part and some ;; associated graphics. - "multipart/related")) + "multipart/related") + "Which mime types to hide by default for multipart messages. + +Can either be a list of mime types (as strings) or a function +mapping a plist representing the current message to such a list. +See Info node `(notmuch-emacs) notmuch-show' for a sample function." + :group 'notmuch-show + :type '(radio (repeat :tag "MIME Types" string) + (function :tag "Function"))) (defun notmuch-multipart/alternative-determine-discouraged (msg) "Return the discouraged alternatives for the specified message." diff --git a/test/T450-emacs-show.sh b/test/T450-emacs-show.sh index 6266ffc5..678efd8b 100755 --- a/test/T450-emacs-show.sh +++ b/test/T450-emacs-show.sh @@ -209,6 +209,10 @@ test_emacs '(notmuch-show "id:'$gen_msg_id'") output=$(head -1 OUTPUT.raw|cut -f1-4 -d' ') test_expect_equal "$output" "Notmuch Test Suite " +test_begin_subtest "multipart/alternative hides html by default" +test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com") + (test-visible-output)' +test_expect_equal_file $EXPECTED/notmuch-show-multipart-alternative OUTPUT # switching to the crypto corpus, using gpg from here on: add_gnupg_home diff --git a/test/emacs-show.expected-output/notmuch-show-multipart-alternative b/test/emacs-show.expected-output/notmuch-show-multipart-alternative new file mode 100644 index 00000000..e44926bc --- /dev/null +++ b/test/emacs-show.expected-output/notmuch-show-multipart-alternative @@ -0,0 +1,62 @@ +Alex Botero-Lowry (2009-11-17) (attachment inbox) +Subject: [notmuch] preliminary FreeBSD support +To: notmuch@notmuchmail.org +Date: Tue, 17 Nov 2009 11:36:14 -0800 + +[ multipart/mixed ] +[ multipart/alternative ] +[ text/plain ] +I saw the announcement this morning, and was very excited, as I had been +hoping sup would be turned into a library, +since I like the concept more than the UI (I'd rather an emacs interface). + +I did a preliminary compile which worked out fine, but +sysconf(_SC_SC_GETPW_R_SIZE_MAX) returns -1 on +FreeBSD, so notmuch_config_open segfaulted. + +Attached is a patch that supplies a default buffer size of 64 in cases where +-1 is returned. + +http://www.opengroup.org/austin/docs/austin_328.txt - seems to indicate this +is acceptable behavior, +and +http://mail-index.netbsd.org/pkgsrc-bugs/2006/06/07/msg016808.htmlspecifically +uses 64 as the +buffer size. +[ text/html (hidden) ] +[ 0001-Deal-with-situation-where-sysconf-_SC_GETPW_R_SIZE_M.patch: application/octet-stream (as text/x-diff) ] +From e3bc4bbd7b9d0d086816ab5f8f2d6ffea1dd3ea4 Mon Sep 17 00:00:00 2001 +From: Alexander Botero-Lowry +Date: Tue, 17 Nov 2009 11:30:39 -0800 +Subject: [PATCH] Deal with situation where sysconf(_SC_GETPW_R_SIZE_MAX) returns -1 + +--- + notmuch-config.c | 2 ++ + 1 files changed, 2 insertions(+), 0 deletions(-) + +diff --git a/notmuch-config.c b/notmuch-config.c +index 248149c..e7220d8 100644 +--- a/notmuch-config.c ++++ b/notmuch-config.c +@@ -77,6 +77,7 @@ static char * + get_name_from_passwd_file (void *ctx) + { + long pw_buf_size = sysconf(_SC_GETPW_R_SIZE_MAX); ++ if (pw_buf_size == -1) pw_buf_size = 64; + char *pw_buf = talloc_zero_size (ctx, pw_buf_size); + struct passwd passwd, *ignored; + char *name; +@@ -101,6 +102,7 @@ static char * + get_username_from_passwd_file (void *ctx) + { + long pw_buf_size = sysconf(_SC_GETPW_R_SIZE_MAX); ++ if (pw_buf_size == -1) pw_buf_size = 64; + char *pw_buf = talloc_zero_size (ctx, pw_buf_size); + struct passwd passwd, *ignored; + char *name; +-- +1.6.5.2 + +[ text/plain ] +[ 4-line signature. Click/Enter to show. ] + Carl Worth (2009-11-17) (inbox unread)