4.6 Custom headers

Sometimes the normal headers that mu4e offers (Date, From, To, Subject, etc.) may not be enough. For these cases, mu4e offers custom headers in both the headers-view and the message-view.

You can do so by adding a description of your custom header to mu4e-header-info-custom, which is a list of custom headers.

Let’s look at an example — suppose we want to add a custom header that shows the number of recipients for a message, i.e., the sum of the number of recipients in the To: and Cc: fields. Let’s further suppose that our function takes a message-plist as its argument (Message functions).

(add-to-list 'mu4e-header-info-custom
  '(:recipnum .
     ( :name "Number of recipients"  ;; long name, as seen in the message-view
       :shortname "Recip#"           ;; short name, as seen in the headers view
       :help "Number of recipients for this message" ;; tooltip
       :function (lambda (msg)
          (format "%d"
            (+ (length (mu4e-message-field msg :to))
               (length (mu4e-message-field msg :cc))))))))

Or, let’s get the contents of the Jabber-ID header.

(add-to-list 'mu4e-header-info-custom
 '(:jabber-id .
     ( :name "Jabber-ID"     ;; long name, as seen in the message-view
       :shortname "JID"      ;; short name, as seen in the headers view
       :help "The Jabber ID" ;; tooltip
       ;; uses mu4e-fetch-field which is rel. slow, so only appropriate
       ;; for mu4e-view-fields, and _not_ mu4e-headers-fields
       :function (lambda (msg)
           (or (mu4e-fetch-field msg "Jabber-ID") "")))))

You can then add the custom header to your mu4e-headers-fields or mu4e-view-fields, just like the built-in headers. However, there is an important caveat: when your custom header in mu4e-headers-fields, the function is invoked for each of your message headers in search results, and if it is slow, would dramatically slow down mu4e.