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.
This commit is contained in:
djcb 2015-12-29 18:55:58 +02:00
parent f645a12075
commit 74aa4679d3
1 changed files with 22 additions and 20 deletions

View File

@ -206,26 +206,28 @@ be changed by setting `mu4e-view-prefer-html'."
(defun mu4e-message-contact-field-matches (msg cfield rx) (defun mu4e-message-contact-field-matches (msg cfield rx)
"Checks whether any of the of the contacts in field "Checks whether any of the of the contacts in field
CFIELD (either :to, :from, :cc or :bcc) of msg MSG matches (with CFIELD (either :to, :from, :cc or :bcc, or a list of those) of
their name or e-mail address) regular expressions RX. If there is a msg MSG matches (with their name or e-mail address) regular
match, return non-nil; otherwise return nil. RX can also be a list expressions RX. If there is a match, return non-nil; otherwise
of regular expressions, in which case any of those are tried for a return nil. RX can also be a list of regular expressions, in
match." which case any of those are tried for a match."
(unless (member cfield '(:to :from :bcc :cc)) (if (and cfield (listp cfield))
(mu4e-error "Not a contacts field (%S)" cfield)) (or (mu4e-message-contact-field-matches msg (car cfield) rx)
(if (listp rx) (mu4e-message-contact-field-matches msg (cdr cfield) rx))
;; if rx is a list, try each one of them for a match (when cfield
(find-if (if (listp rx)
(lambda (a-rx) (mu4e-message-contact-field-matches msg cfield a-rx)) ;; if rx is a list, try each one of them for a match
rx) (find-if
;; not a list, check the rx (lambda (a-rx) (mu4e-message-contact-field-matches msg cfield a-rx))
(find-if rx)
(lambda (ct) ;; not a list, check the rx
(let ((name (car ct)) (email (cdr ct))) (find-if
(or (lambda (ct)
(and name (string-match rx name)) (let ((name (car ct)) (email (cdr ct)))
(and email (string-match rx email))))) (or
(mu4e-message-field msg cfield)))) (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) (defun mu4e-message-contact-field-matches-me (msg cfield)
"Checks whether any of the of the contacts in field "Checks whether any of the of the contacts in field