From 77529b105e569d566d00fbd89850d9094168cded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hinrik=20=C3=96rn=20Sigur=C3=B0sson?= Date: Fri, 13 Nov 2015 23:59:45 +0000 Subject: [PATCH] Allow specifying list shortnames with regexes This way mu4e will intelligently shorten mailing list names which contain dots: (setq mu4e-mailing-list-patterns '("\\([a-z0-9.]+\\)\.lists\.company\.com")) --- mu4e/mu4e-lists.el | 5 +++++ mu4e/mu4e-utils.el | 9 ++++++++- mu4e/mu4e.texi | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/mu4e/mu4e-lists.el b/mu4e/mu4e-lists.el index a9676c28..96029e60 100644 --- a/mu4e/mu4e-lists.el +++ b/mu4e/mu4e-lists.el @@ -85,4 +85,9 @@ "A list of (MAILING-LIST-ID . SHORTNAME); these are used in addition to the 'built-in' list `mu4e~user-lists'.") +(defvar mu4e-mailing-list-patterns nil + "A list of regex patterns to capture a shortname out of a list ID. For +the first regex that matches, its first matchgroup will be used as the +shortname.") + (provide 'mu4e-lists) diff --git a/mu4e/mu4e-utils.el b/mu4e/mu4e-utils.el index 57abc8a3..687a381e 100644 --- a/mu4e/mu4e-utils.el +++ b/mu4e/mu4e-utils.el @@ -517,7 +517,8 @@ that has a live window), and vice versa." (defun mu4e-get-mailing-list-shortname (list-id) "Get the shortname for a mailing-list with list-id LIST-ID. based - on `mu4e~mailing-lists' and `mu4e-user-mailing-lists'." +on `mu4e~mailing-lists', `mu4e-user-mailing-lists', and +`mu4e-mailing-list-patterns'." (unless mu4e~lists-hash (setq mu4e~lists-hash (make-hash-table :test 'equal)) (dolist (cell mu4e~mailing-lists) @@ -526,6 +527,12 @@ that has a live window), and vice versa." (puthash (car cell) (cdr cell) mu4e~lists-hash))) (or (gethash list-id mu4e~lists-hash) + (and (boundp 'mu4e-mailing-list-patterns) + (cl-member-if + (lambda (pattern) + (string-match pattern list-id)) + mu4e-mailing-list-patterns) + (match-string 1 list-id)) ;; if it's not in the db, take the part until the first dot if there is one; ;; otherwise just return the whole thing (if (string-match "\\([^.]*\\)\\." list-id) diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index f7159081..a686a551 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -799,8 +799,8 @@ in the example above). To determine whether a message was sent by you, your e-mail addresses. @item The 'List' field shows the mailing-list a message is sent to; @code{mu4e} tries to create a convenient shortcut for the mailing-list name; -the variable @code{mu4e-user-mailing-lists} can be used to add your own -shortcuts. +the variables @code{mu4e-user-mailing-lists} and +@code{mu4e-mailing-list-patterns} can be used to add your own shortcuts. @item The letters in the 'Flags' field correspond to the following: D=@emph{draft}, F=@emph{flagged} (i.e., 'starred'), N=@emph{new}, P=@emph{passed} (i.e., forwarded), R=@emph{replied}, S=@emph{seen}, T=@emph{trashed},