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


12.4 Contact functions

It can sometimes be useful to rewrite the contact information that mu4e provides, for example to convert them to some standardized format, or to fix spelling errors. And sometimes, you may want to remove certain contacts altogether.

For this, mu4e provides mu4e-contact-rewrite-function, which passes each contact to a user-provided function, which is expected to return either the possibly rewritten contact or nil to remove the contact from the list - note that the latter can also be achieved using mu4e-compose-complete-ignore-address-regexp.

Each of the contacts are property-lists (’plists’), with properties :name (which may be nil), and :mail, and a number of other properties which you should return unchanged.

Let’s look at an example:

(defun my-rewrite-function (contact)
  (let ((name (or (plist-get contact :name) ""))
         (mail (plist-get contact :mail)))
    (cond
      ;; jonh smiht --> John Smith
      ((string= "jonh smiht" name) 
        (plist-put contact :name "John C. Smith")
        contact) 
      ;; remove evilspammer from the contacts list
      ((string= "evilspammer@example.com" mail) nil)
      ;; others stay as the are
      (t contact))))

(setq mu4e-contact-rewrite-function 'my-rewrite-function)

This function is called for each of your contacts.