From 74aa4679d38a9578a10c910a7c8cf0dae8b2238b Mon Sep 17 00:00:00 2001 From: djcb Date: Tue, 29 Dec 2015 18:55:58 +0200 Subject: [PATCH] mu4e: improve mu4e-message-contact-field-matches Improve mu4e-message-contact-field-matches so you can pass it a list of header fields to match instead of having to check each of them separately. --- mu4e/mu4e-message.el | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/mu4e/mu4e-message.el b/mu4e/mu4e-message.el index 8e8aba94..c5eb75fb 100644 --- a/mu4e/mu4e-message.el +++ b/mu4e/mu4e-message.el @@ -206,26 +206,28 @@ be changed by setting `mu4e-view-prefer-html'." (defun mu4e-message-contact-field-matches (msg cfield rx) "Checks whether any of the of the contacts in field -CFIELD (either :to, :from, :cc or :bcc) of msg MSG matches (with -their name or e-mail address) regular expressions RX. If there is a -match, return non-nil; otherwise return nil. RX can also be a list -of regular expressions, in which case any of those are tried for a -match." - (unless (member cfield '(:to :from :bcc :cc)) - (mu4e-error "Not a contacts field (%S)" cfield)) - (if (listp rx) - ;; if rx is a list, try each one of them for a match - (find-if - (lambda (a-rx) (mu4e-message-contact-field-matches msg cfield a-rx)) - rx) - ;; not a list, check the rx - (find-if - (lambda (ct) - (let ((name (car ct)) (email (cdr ct))) - (or - (and name (string-match rx name)) - (and email (string-match rx email))))) - (mu4e-message-field msg cfield)))) +CFIELD (either :to, :from, :cc or :bcc, or a list of those) of +msg MSG matches (with their name or e-mail address) regular +expressions RX. If there is a match, return non-nil; otherwise +return nil. RX can also be a list of regular expressions, in +which case any of those are tried for a match." + (if (and cfield (listp cfield)) + (or (mu4e-message-contact-field-matches msg (car cfield) rx) + (mu4e-message-contact-field-matches msg (cdr cfield) rx)) + (when cfield + (if (listp rx) + ;; if rx is a list, try each one of them for a match + (find-if + (lambda (a-rx) (mu4e-message-contact-field-matches msg cfield a-rx)) + rx) + ;; not a list, check the rx + (find-if + (lambda (ct) + (let ((name (car ct)) (email (cdr ct))) + (or + (and name (string-match rx name)) + (and email (string-match rx email))))) + (mu4e-message-field msg cfield)))))) (defun mu4e-message-contact-field-matches-me (msg cfield) "Checks whether any of the of the contacts in field