Next: , Previous: , Up: Extending mu4e   [Contents]

12.3 Message functions

Many functions in mu4e deal with message plists (property lists). They contain information about messages, such as sender and recipient, subject, date and so on. To deal with these plists, there are a number of mu4e-message- functions (in mu4e-message.el), such as mu4e-message-field and mu4e-message-at-point, and a shortcut to combine the two, mu4e-message-field-at-point.

For example, to get the subject of the message at point, in either the headers view or the message view, you could write:

(mu4e-message-field (mu4e-message-at-point) :subject)

Note that:

Note that in headers-mode, you only have access to a reduced message plist, without the information about the message-body or mime-parts; mu4e does this for performance reasons. And even in view-mode, you do not have access to arbitrary message-headers.

However, it is possible to get the information indirectly, using the raw-message and some third-party tool like procmail’s formail:

(defun my-mu4e-any-message-field-at-point (hdr)
  "Quick & dirty way to get an arbitrary header HDR at
point. Requires the 'formail' tool from procmail."
  (replace-regexp-in-string "\n$" ""
      (concat "formail -x " hdr " -c < "
        (shell-quote-argument (mu4e-message-field-at-point :path))))))

12.3.1 Rewriting the message body

Message body rewriting allows you to modify the message text that is presented in the message view. This can be useful if the message needs special processing, for instance for special filling or cleaning up encoding artifacts (this is what mu4e uses this for internally).

To enable this, you can append your rewrite-function to mu4e-message-body-rewrite-functions; your function is expected to take two parameters MSG and TXT, which are the message-plist and the body-text, which could be the result of earlier transformations, including html->text conversion as per mu4e-html2-text-command. The function is expected to return the transformed text.

As a fairly useless example, suppose we insist on reading mu4e as MU4E:

(defun mu4e-to-MU4E-rewrite (msg txt)
  (replace-regexp-in-string "mu4e" "MU4E" txt))

(add-to-list 'mu4e-message-body-rewrite-functions 'mu4e-to-MU4E-rewrite t)

Next: , Previous: , Up: Extending mu4e   [Contents]