mirror of https://github.com/djcb/mu.git
* mu4e: allow for custom header fields (see `mu4e-header-info-custom')
This commit is contained in:
parent
631e9c20f8
commit
4b0cb4d1df
|
@ -411,6 +411,16 @@ date. The formats used for date and time are
|
|||
(propertize (mu4e-get-mailing-list-shortname list) 'help-echo list)
|
||||
""))
|
||||
|
||||
(defun mu4e~headers-custom-field (msg field)
|
||||
"Show some custom header field, or raise an error if it is not
|
||||
found."
|
||||
(let* ((item (or (assoc field mu4e-header-info-custom)
|
||||
(mu4e-error "field %S not found" field)))
|
||||
(func (or (plist-get (cdr-safe item) :function)
|
||||
(mu4e-error "no :function defined for field %S %S" field (cdr item)))))
|
||||
(funcall func msg)))
|
||||
|
||||
|
||||
;; note: this function is very performance-sensitive
|
||||
(defun mu4e~headers-header-handler (msg &optional point)
|
||||
"Create a one line description of MSG in this buffer, at POINT,
|
||||
|
@ -441,7 +451,7 @@ if provided, or at the end of the buffer otherwise."
|
|||
'help-echo (format "%S" val)))
|
||||
(:tags (propertize (mapconcat 'identity val ", ")))
|
||||
(:size (mu4e-display-size val))
|
||||
(t (mu4e-error "Unsupported header field (%S)" field))))
|
||||
(t (mu4e~headers-custom-field msg field))))
|
||||
(when str
|
||||
(setq line
|
||||
(concat line
|
||||
|
@ -677,7 +687,8 @@ after the end of the search results."
|
|||
(mapcar
|
||||
(lambda (item)
|
||||
(let* ((field (car item)) (width (cdr item))
|
||||
(info (cdr (assoc field mu4e-header-info)))
|
||||
(info (cdr (assoc field
|
||||
(append mu4e-header-info mu4e-header-info-custom))))
|
||||
(sortable (plist-get info :sortable))
|
||||
(help (plist-get info :help))
|
||||
(uparrow (if mu4e-use-fancy-chars " ▲" " ^"))
|
||||
|
|
|
@ -505,7 +505,6 @@ I.e. a message with the draft flag set."
|
|||
:group 'mu4e-faces)
|
||||
|
||||
|
||||
|
||||
;; headers info
|
||||
(defconst mu4e-header-info
|
||||
'( (:attachments .
|
||||
|
@ -608,7 +607,26 @@ symbol for /another/ field. For example, the `:human-date' field
|
|||
uses `:date' for that.
|
||||
|
||||
Note, `:sortable' does not work for custom header fields.")
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
(defvar mu4e-header-info-custom
|
||||
"A list of custom (user-defined) headerr. The format is similar
|
||||
to `mu4e-header-info', but addds a :function property, which should
|
||||
point to a function that takes a message p-list as argument, and
|
||||
returns a string. See the default value of `mu4e-header-info-custom
|
||||
for an example."
|
||||
'( (:recipnum .
|
||||
( :name "Number of recipients"
|
||||
:shortname "Recip#"
|
||||
:help "Number of recipients for this message"
|
||||
:function
|
||||
(lambda (msg)
|
||||
(format "%d"
|
||||
(+ (length (mu4e-message-field msg :to))
|
||||
(length (mu4e-message-field msg :cc)))))))))
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
|
@ -149,6 +149,16 @@ messages - for example, `mu4e-org'."
|
|||
;; need an extra policy...
|
||||
(mu4e~proc-view msgid mu4e-view-show-images mu4e-decryption-policy))
|
||||
|
||||
(defun mu4e~view-custom-field (msg field)
|
||||
"Show some custom header field, or raise an error if it is not
|
||||
found."
|
||||
(let* ((item (or (assoc field mu4e-header-info-custom)
|
||||
(mu4e-error "field %S not found" field)))
|
||||
(func (or (plist-get (cdr-safe item) :function)
|
||||
(mu4e-error "no :function defined for field %S %S"
|
||||
field (cdr item)))))
|
||||
(funcall func msg)))
|
||||
|
||||
|
||||
(defun mu4e-view-message-text (msg)
|
||||
"Return the message to display (as a string), based on the MSG plist."
|
||||
|
@ -193,7 +203,8 @@ messages - for example, `mu4e-org'."
|
|||
(:attachments (mu4e~view-construct-attachments-header msg))
|
||||
;; pgp-signatures
|
||||
(:signature (mu4e~view-construct-signature-header msg))
|
||||
(t (mu4e-error "Unsupported field: %S" field)))))
|
||||
(t (mu4e~view-construct-header field
|
||||
(mu4e~view-custom-field msg field))))))
|
||||
mu4e-view-fields "")
|
||||
"\n"
|
||||
(mu4e-message-body-text msg)))
|
||||
|
@ -255,7 +266,8 @@ marking if it still had that."
|
|||
"Return header field FIELD (as in `mu4e-header-info') with value
|
||||
VAL if VAL is non-nil. If DONT-PROPERTIZE-VAL is non-nil, do not
|
||||
add text-properties to VAL."
|
||||
(let* ((info (cdr (assoc field mu4e-header-info)))
|
||||
(let* ((info (cdr (assoc field
|
||||
(append mu4e-header-info mu4e-header-info-custom))))
|
||||
(key (plist-get info :name))
|
||||
(help (plist-get info :help)))
|
||||
(if (and val (> (length val) 0))
|
||||
|
|
|
@ -720,7 +720,9 @@ Some notes to explain what you see in the example:
|
|||
@itemize
|
||||
@item The fields shown in the headers view can be influenced by customizing
|
||||
the variable @code{mu4e-headers-fields}; see @code{mu4e-header-info} for the
|
||||
list of available fields.
|
||||
list of built-in fields. Apart from the built-in fields, you can also create
|
||||
custom fields using @code{mu4e-header-info-custom}; see its documentation for
|
||||
the details.
|
||||
@item By default, the date is shown with the @t{:human-date} field, which
|
||||
shows the @emph{time} for today's messages, and the @emph{date} for older
|
||||
messages. If you want to distinguish between 'today' and 'older', you can use
|
||||
|
@ -967,7 +969,10 @@ An example message view:
|
|||
|
||||
Some notes:
|
||||
@itemize
|
||||
@item The variable @code{mu4e-view-fields} determines the header fields to be shown.
|
||||
@item The variable @code{mu4e-view-fields} determines the header fields to be
|
||||
shown; see @code{mu4e-header-info} for a list of built-in fields. Apart from
|
||||
the built-in fields, you can also create custom fields using
|
||||
@code{mu4e-header-info-custom}; see its documentation for the details.
|
||||
@item You can set the date format with the variable
|
||||
@code{mu4e-date-format-long}.
|
||||
@item By default, only the names of contacts in address fields are visible
|
||||
|
|
Loading…
Reference in New Issue