[QUESTION] how to apply custom face on specific From: sender email?

8 views
Skip to first unread message

stardiviner

unread,
Mar 25, 2025, 1:13:52 AMMar 25
to mu4e
I try to auto add face color to specific messages match some conditions like email from a contact or address in `mu4e-headers-mode` buffer.

Here is my code but not working:

#+begin_src emacs-lisp
;;; TODO: it's not working
(defun my/mu4e-colorize-message ()
  "Colorize `mu4e-headers-mode' buffer message."
  (unless (eq (line-end-position) (point-max))
    (let* ((msg (get-text-property (point) 'msg))
           (docid (mu4e-message-field msg :docid))
           (flags (mu4e-message-field msg :flags))
           (unread (memq 'unread flags)))
      (let* ((marked-senders '(("Ihor Radchenko" . "yant...@posteo.net")
                               ("Stefan Kangas" . "stefan...@gmail.com"))))
        ;; reference `mu4e-view-fields'
        (when (or (member (plist-get (car (mu4e-message-field msg :from)) :name)
                          (mapcar 'car marked-senders))
                  (member (plist-get (car (mu4e-message-field msg :from)) :email)
                          (mapcar 'cdr marked-senders)))
          (let ((inhibit-read-only t))
            (add-text-properties (line-beginning-position) (line-end-position)
                                 '(face '(:background "light gray")))))
        (let* ((ov (make-overlay (line-beginning-position) (line-end-position)))
               (info (nerd-icons-faicon "nf-fa-mailchimp")))
          (overlay-put ov 'mu4e-msg-colorized t)
          (overlay-put ov 'before-string info))
        ))))

(defun my/mu4e-colorize-all-messages ()
  "Colorize `mu4e-headers-mode' buffer all messages."
  (save-excursion
    (goto-char (point-min))
    (catch 'done
      (while (not (eobp))
        (my/mu4e-colorize-message)
        (unless (mu4e-headers-next) ; `forward-line'
          (throw 'done t))))))

(add-hook 'mu4e-headers-mode-hook #'my/mu4e-colorize-all-messages)
#+end_src


[stardiviner]           <Hack this world!>      GPG key ID: 47C32433
IRC(freeenode): stardiviner                     Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/
Reply all
Reply to author
Forward
0 new messages