mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-25 04:18:08 +01:00
emacs: Allow part preferences to depend on message content.
Currently the preference for which sub-part of a multipart/alternative part is shown is global. Allow to the user to override the settings on a per-message basis by providing the ability to call a function that has access to the message to return the discouraged type list. The original approach is retained as the default.
This commit is contained in:
parent
d93d3779b8
commit
f0881394bd
2 changed files with 17 additions and 5 deletions
|
@ -520,11 +520,23 @@ This replaces spaces, percents, and double quotes in STR with
|
|||
"multipart/related"
|
||||
))
|
||||
|
||||
(defun notmuch-multipart/alternative-choose (types)
|
||||
"Return a list of preferred types from the given list of types"
|
||||
(defun notmuch-multipart/alternative-determine-discouraged (msg)
|
||||
"Return the discouraged alternatives for the specified message."
|
||||
;; If a function, return the result of calling it.
|
||||
(if (functionp notmuch-multipart/alternative-discouraged)
|
||||
(funcall notmuch-multipart/alternative-discouraged msg)
|
||||
;; Otherwise simply return the value of the variable, which is
|
||||
;; assumed to be a list of discouraged alternatives. This is the
|
||||
;; default behaviour.
|
||||
notmuch-multipart/alternative-discouraged))
|
||||
|
||||
(defun notmuch-multipart/alternative-choose (msg types)
|
||||
"Return a list of preferred types from the given list of types
|
||||
for this message, if present."
|
||||
;; Based on `mm-preferred-alternative-precedence'.
|
||||
(let ((seq types))
|
||||
(dolist (pref (reverse notmuch-multipart/alternative-discouraged))
|
||||
(let ((discouraged (notmuch-multipart/alternative-determine-discouraged msg))
|
||||
(seq types))
|
||||
(dolist (pref (reverse discouraged))
|
||||
(dolist (elem (copy-sequence seq))
|
||||
(when (string-match pref elem)
|
||||
(setq seq (nconc (delete elem seq) (list elem))))))
|
||||
|
|
|
@ -607,7 +607,7 @@ will return nil if the CID is unknown or cannot be retrieved."
|
|||
(plist-get part :content)))
|
||||
|
||||
(defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth button)
|
||||
(let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))
|
||||
(let ((chosen-type (car (notmuch-multipart/alternative-choose msg (notmuch-show-multipart/*-to-list part))))
|
||||
(inner-parts (plist-get part :content))
|
||||
(start (point)))
|
||||
;; This inserts all parts of the chosen type rather than just one,
|
||||
|
|
Loading…
Reference in a new issue