Colour-coded mailbox labels

13 views
Skip to first unread message

Joost Kremers

unread,
Jun 7, 2024, 7:30:21 AMJun 7
to mu-di...@googlegroups.com
Hi all,

I thought I'd share a little code snippet that I put together yesterday. It's
not a full-fledged solution that others can drop into their configuration and
forget about, but it might inspire someone. :-)

I have three mail accounts, in one of which mail is sorted by the server into a
bunch of mail boxes, corresponding to local maildirs. The past few weeks, I've
started to rely more and more on bookmarks that show me the most recent and/or
unread messages across my three mail accounts and all mailboxes, rather than
visiting each mail box one by one.

Because of this, I wanted to add the maildir to fields in the headers list,
because it's still relevant information for me to have. `mu4e-header-info` has a
`:maildir` entry, but it includes the account name, which makes it rather long
and a little jarring. So I created a custom header field, which shows only the
maildir name (which in my case is always a direct subdirectory of the account,
i.e., I don't have mailboxes such as /Fastmail/Parent/Child/Grandchild). In
order to distinguish the Inbox of one account from the Inbox of the others, I
decided to give them a colourized background.

I set up the header field like this:

```
(add-to-list 'mu4e-header-info-custom
'(:short-maildir . (:name "Short maildir name"
:shortname "Maildir"
:help "Short, colour-coded maildir"
:function jk/mu4e-short-maildir)))
```

`jk/mu4e-short-maildir` takes a message and returns the colour-coded string:

```
(defun jk/mu4e-short-maildir (msg)
"Shorten maildir for MSG."
(let* ((maildir (mu4e-message-field msg :maildir))
(path (split-string maildir "/" t))
(account (car path))
(dir (if (string= account "Trash") "Trash" (cadr path)))
(pad (max 0 (- 15 (length dir))))
(pad-left (make-string (/ pad 2) ?\s))
(pad-right (make-string (/ (1+ pad) 2) ?\s))
(face (pcase account
("Fastmail" '(:background "LightSkyBlue1" :box (:line-width (3 . 1) :color "LightSkyBlue1")))
("Gmail" '(:background "pale green" :box (:line-width (3 . 1) :color "pale green")))
("NldSchool" '(:background "orange" :box (:line-width (3 . 1) :color "orange")))
;; ("Trash" '(:background nil :box nil))
)))
(propertize (concat pad-left dir pad-right) 'face face)))
```

Trash is handled separately, because it's a maildir directly under ~/Mail/, so
it's not linked to one specific account. And I'm adding coloured boxes because I
found that the highlight for the current message actually overrides the
background colour of the text, but it doesn't override the box.

Finally, I added the new field to `mu4e-header-fields`:

```
(setq-default mu4e-headers-fields '((:date . 20)
(:flags . 6)
(:short-maildir . 15)
(:from-or-to . 22)
(:thread-subject)))
```

I'm attaching a screen shot to show what it looks like.


--
Joost Kremers
Life has its moments

Screenshot from 2024-06-07 11-42-26.png

Christopher M. Miles

unread,
Jun 8, 2024, 8:18:22 AMJun 8
to mu-di...@googlegroups.com
This looks interesting. I want to take a try on my conifg. Thanks for sharing.

--

[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
signature.asc

Benjamin Slade

unread,
Jun 16, 2024, 1:41:39 PMJun 16
to mu-di...@googlegroups.com

Many thanks, Joost, for this. I’ve been using more or less the same visual setup for mu4e for more than a decade, and this much improves the experience.

Here’s the modified version I’m using, with (a) some more colour customisation, (b) escaping of Gmail’s weird directory structure (most things other than INBOX are subdirectories of a `[Gmail]` directory), (c) prefixing part of the account name the the coloured label (I like redundancy in quickly identifying things):

(add-to-list 'mu4e-header-info-custom
             '(:short-maildir . (:name "Short maildir name"
                                       :shortname "Maildir"
                                       :help "Short, colour-coded maildir"
                                       :function jk/mu4e-short-maildir)))

(defun jk/mu4e-short-maildir (msg)
  "Shorten maildir for MSG."
  (let* ((maildir (mu4e-message-field msg :maildir))
         (path (split-string maildir "/" t))
         (account (car path))
         ;; 'escape' Gmail's superfluous subfoldering 
         (subaccount (if (string= (cadr path) "[Gmail]")
                     (caddr path)
                   (cadr path)))
         (dir
          (concat
           ;; downcase account and abbreviate to first 8 letters unless shorter already:
           (downcase (substring (car path)
                                0
                                (if ((length (car path)) 8)
                                    (length (car path))
                                  8)))
           " ("
           subaccount
           ")"))
         (pad (max 0 (- 15 (length dir))))
         (pad-left (make-string (/ pad 2) ?\s))
         (pad-right (make-string ((1+ pad) 2) ?\s))
         (face (pcase
 account
                 ("Professional" '(:background "midnight blue" :foreground "cyan3" :box (:line-width (3 . 1) :color "cyan3")))
                 ("Personal" '(:background "MediumOrchid4" :foreground "plum1" :box (:line-width (3 . 1) :color "plum1")))
                 ("UniofU" '(:background "#CC0000" :foreground "pink1" :box (:line-width (3 . 1) :color "pink1")))
                 ("OldWork" '(:background "tomato4" :foreground "RosyBrown1" :box (:line-width (3 . 1) :color "tomato3")))
                 ("SlopGmail" '(:background "DarkOrange3" :foreground "peach puff" :box (:line-width (3 . 1) :color "DarkOrange1")))
                 ("Beowulf" '(:background "gold3" :foreground "khaki1" :box (:line-width (3 . 1) :color "gold1")))
                 ("Offlist" '(:background "gray13" :foreground "green yellow" :box (:line-width (3 . 1) :color "green yellow")))
                 ("Mobile" '(:background "DeepPink3" :foreground "thistle" :box (:line-width (3 . 1) :color "DeepPink1")))
                 )))
    (propertize (concat pad-left dir pad-right) 'face face)))

(setq-default mu4e-headers-fields '((:more-human-date . 10)
                                    (:short-maildir . 18)
                                    (:flags . 6)
                                    (:mailing-list . 8)
                                    (:from-or-to . 23)
                                    (:thread-subject)))

 best,
 —Benjamin

 –
 '(Dr Benjamin Slade (he/him)
     (website . https://lambda-y.net)
     `(pgp_fp: ,(B20E 444C FA80 B5F8 15FA  4AD8 6FBF CD68 3B05 2B84))
       “sent by mu4e 1.12.5 in Emacs 30.0.50 with org-msg on EndeavourOS Linux”)

         (path (split-string maildir ““ t))


         (account (car path))
         (dir (if (string= account ”Trash“) ”Trash" (cadr path)))
         (pad (max 0 (- 15 (length dir))))

         (pad-left (make-string ( pad 2) ?\s))


         (pad-right (make-string (/ (1+ pad) 2) ?\s))
         (face (pcase account
                 (”Fastmail“ ’(:background ”LightSkyBlue1“ :box (:line-width (3 . 1) :color ”LightSkyBlue1“)))
                 (”Gmail“ ’(:background ”pale green“ :box (:line-width (3 . 1) :color ”pale green“)))
                 (”NldSchool“ ’(:background ”orange“ :box (:line-width (3 . 1) :color ”orange“)))
                 ;; (”Trash" ’(:background nil :box nil))
                 )))
    (propertize (concat pad-left dir pad-right) ’face face)))
```

Trash is handled separately, because it’s a maildir directly under ~/Mail/, so
it’s not linked to one specific account. And I’m adding coloured boxes because I
found that the highlight for the current message actually overrides the
background colour of the text, but it doesn’t override the box.

Finally, I added the new field to `mu4e-header-fields`:

```
(setq-default mu4e-headers-fields ’((:date . 20)
                                    (:flags . 6)
                                    (:short-maildir . 15)
                                    (:from-or-to . 22)
                                    (:thread-subject)))
```

I’m attaching a screen shot to show what it looks like.


Joost Kremers
Life has its moments


You received this message because you are subscribed to the Google Groups “mu-discuss” group.
To unsubscribe from this group and stop receiving emails from it, send an email to mu-discuss+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mu-discuss/865xul9eij.fsf%40fastmail.fm.

[2. image/png; Screenshot from 2024-06-07 11-42-26.png]…

Reply all
Reply to author
Forward
0 new messages