Merge pull request #2267 from Chris00/master

Make mu4e-message-contact-field-matches accept a list of fields
This commit is contained in:
Dirk-Jan C. Binnema 2022-05-28 23:54:17 +03:00 committed by GitHub
commit dd1b854eca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 24 deletions

View File

@ -138,30 +138,30 @@ list of those) of msg MSG matches (with their name or e-mail
address) regular expressions RX. If there is a match, return address) regular expressions RX. If there is a match, return
non-nil; otherwise return nil. RX can also be a list of regular 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." expressions, in which case any of those are tried for a match."
(if (and cfield (listp cfield)) (cond
(or (mu4e-message-contact-field-matches ((null cfield))
msg (mu4e-contact-name cfield) rx) ((listp cfield)
(mu4e-message-contact-field-matches (seq-find (lambda (cf) (mu4e-message-contact-field-matches msg cf rx))
msg (mu4e-contact-email cfield) rx)) cfield))
(when cfield ((listp rx)
(if (listp rx) ;; if rx is a list, try each one of them for a match
;; if rx is a list, try each one of them for a match (seq-find
(seq-find (lambda (a-rx) (mu4e-message-contact-field-matches msg cfield a-rx))
(lambda (a-rx) (mu4e-message-contact-field-matches msg cfield a-rx)) rx))
rx) (t
;; not a list, check the rx ;; not a list, check the rx
(seq-find (seq-find
(lambda (ct) (lambda (ct)
(let ((name (mu4e-contact-name ct)) (let ((name (mu4e-contact-name ct))
(email (mu4e-contact-email ct)) (email (mu4e-contact-email ct))
;; the 'rx' may be some `/rx/` from mu4e-personal-addresses; ;; the 'rx' may be some `/rx/` from mu4e-personal-addresses;
;; so let's detect and extract in that case. ;; so let's detect and extract in that case.
(rx (if (string-match-p "^\\(.*\\)/$" rx) (rx (if (string-match-p "^\\(.*\\)/$" rx)
(substring rx 1 -1) rx))) (substring rx 1 -1) rx)))
(or (or
(and name (string-match rx name)) (and name (string-match rx name))
(and email (string-match rx email))))) (and email (string-match rx email)))))
(mu4e-message-field msg cfield)))))) (mu4e-message-field msg cfield)))))
(defun mu4e-message-contact-field-matches-me (msg cfield) (defun mu4e-message-contact-field-matches-me (msg cfield)
"Does contact-field CFIELD in MSG match me? "Does contact-field CFIELD in MSG match me?