2

I currently use mutt but am trying to switch email to emacs. One of the features I rely heavily on is the ability to see which of my many email addresses a message was sent to in the mail summary pane just by the colour.

All the mail arrives in the same mbox via offlineimap so I would prefer to label it purely on the contents of the to: field. Any ideas on how best to approach this?

Currently I'm experimenting with mu4e but I have not yet committed to it, so switching to another mail package is ok if it can provide a solution to this.

2
  • Do you need to have messages sent to both email addresses visible at the same time? It's very easy to filter your inbox to only show messages sent to one of your addresses at a time with mu4e.
    – Tyler
    Commented May 8, 2017 at 18:31
  • Yeah, I like to see all new mail at once, and then I can immediately spot if something interesting has arrived at one of my less used email addresses. ie if I get a new photo commission it stands out in red and i will open it immediately.
    – Iain
    Commented May 9, 2017 at 1:21

1 Answer 1

2

Using font-lock-mode with search based fontification can do this. For this to work the to address must be displayed in the buffer on the header line. It can be way over to the right where it is out of sight though. Because the :to field is often displayed as the recipients name this also requires a custom header field that displays the real to address to be set up in mu4e.

First the custom header field:

(add-to-list 'mu4e-header-info-custom
   '(:real-to .
       (:name "Real :to Address"
        :shortname "realto"
        :help ":to address without any aliases"
        :function (lambda (msg)
                     (cdr (nth 0 (mu4e-message-field msg :to)))))))

Next setup the headers display:

(setq mu4e-headers-fields
  '((:human-date .  12)
    (:flags      .   6)
    (:from       .  22)
    (:subject    . 80)
    (:real-to    . nil)))

At this point the new custom header field should be visible in the mu4e headers buffer. Then the regexp patterns need to be set up to match the email addresses. These patterns will match the address anywhere on the line but could be simplified a little just to match the pattern on the end of the line:

(setq header-highlights
  '((".*public@mydomain.*" . email-public-face)
    (".*teacher@mydomain.*" . email-teacher-face)
    (".*iain@mydomain.*" . email-iain-face)
    (".*photos@mydomain.*" . email-photos-face)
    (".*[email protected].*" . email-wiserobot-face)
    (".*@hotmail.com.*" . email-hotmail-face)
    (".*\\([email protected]\\|[email protected]\\).*" . email-me-face)))

(add-hook 'mu4e-headers-mode-hook
      (lambda ()
        (setq font-lock-defaults '(header-highlights))))

Note that this is using custom faces. This is not necessary, any predefined face would do, but then redoing colour schemes might get confusing. I will include my code for completeness, but there is probably a neater way to do it. I had to define variables for each face which I don't think is supposed to be necessary.

(defface email-public
  '((t :foreground "#bf9f00"))
  "Face for mail headers to public@mydomain"
  :group `basic-faces)
(defface email-teacher
  '((t :foreground "#9f009f"))
  "Face for mail headers to Teacher@mydomain"
  :group 'basic-faces)
(defface email-iain
  '((t :foreground "#009f00"))
  "Face for mail headers to iain@mydomain"
  :group 'basic-faces)
(defface email-photos
  '((t :foreground "#ef1010"))
  "Face for mail headers to photos@mydomain"
  :group 'basic-faces)
(defface email-wiserobot
  '((t :foreground "#0000e8"))
  "Face for mail headers to iain@workdomain"
  :group 'basic-faces)
(defface email-hotmail
  '((t :foreground "#7840f8"))
  "Face for mail headers to [email protected]"
  :group 'basic-faces)
(defface email-me
  '((t :foreground "#00c080"))
  "Face for mail headers to [email protected]"
  :group 'basic-faces)


(setq email-public-face `email-public
  email-teacher-face 'email-teacher
  email-iain-face 'email-iain
  email-photos-face 'email-photos
  email-wiserobot-face 'email-wiserobot
  email-hotmail-face 'email-hotmail
  email-me-face 'email-me)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.