diff --git a/mu4e/mu4e-draft.el b/mu4e/mu4e-draft.el index f3df28d0..e739c33d 100644 --- a/mu4e/mu4e-draft.el +++ b/mu4e/mu4e-draft.el @@ -36,7 +36,7 @@ (defcustom mu4e-compose-dont-reply-to-self nil "If non-nil, don't include self. -\(that is, member of `(mu4e-personal-addresses)') in replies." +(as decided by `mu4e-personal-address-p')" :type 'boolean :group 'mu4e-compose) @@ -182,10 +182,7 @@ of the original, we simple copy the list form the original." (if mu4e-compose-dont-reply-to-self (cl-delete-if (lambda (to-cell) - (cl-member-if - (lambda (addr) - (string= (downcase addr) (downcase (cdr to-cell)))) - (mu4e-personal-addresses))) + (mu4e-personal-address-p (cdr to-cell))) reply-to) reply-to))) @@ -246,10 +243,7 @@ REPLY-ALL." cc-lst (cl-delete-if (lambda (cc-cell) - (cl-member-if - (lambda (addr) - (string= (downcase addr) (downcase (cdr cc-cell)))) - (mu4e-personal-addresses))) + (mu4e-personal-address-p (cdr cc-cell))) cc-lst)))) cc-lst))) diff --git a/mu4e/mu4e-headers.el b/mu4e/mu4e-headers.el index d118c240..641c1139 100644 --- a/mu4e/mu4e-headers.el +++ b/mu4e/mu4e-headers.el @@ -604,7 +604,7 @@ cdr element the To: prefix.") (defun mu4e~headers-from-or-to (msg) "When the from address for message MSG is one of the the user's addresses, -\(as per `mu4e-personal-addresses'), show the To address; +\(as per `mu4e-personal-address-p'), show the To address; otherwise ; show the from address; prefixed with the appropriate `mu4e-headers-from-or-to-prefix'." (let ((addr (cdr-safe (car-safe (mu4e-message-field msg :from))))) diff --git a/mu4e/mu4e-icalendar.el b/mu4e/mu4e-icalendar.el index c39f702a..48949d88 100644 --- a/mu4e/mu4e-icalendar.el +++ b/mu4e/mu4e-icalendar.el @@ -76,8 +76,8 @@ (let* ((handle (car data)) (status (cadr data)) (event (caddr data)) - (gnus-icalendar-additional-identities (mu4e-personal-addresses)) - (reply (gnus-icalendar-with-decoded-handle + (gnus-icalendar-additional-identities (mu4e-personal-addresses 'no-regexp)) + (reply (gnus-icalendar-with-decoded-handle1 handle (let ((gnus-icalendar-find-if (lambda(pred seq) nil))) (gnus-icalendar-event-reply-from-buffer diff --git a/mu4e/mu4e-main.el b/mu4e/mu4e-main.el index e52af25f..80563dc8 100644 --- a/mu4e/mu4e-main.el +++ b/mu4e/mu4e-main.el @@ -275,11 +275,11 @@ When REFRESH is non nil refresh infos from server." (mu4e~key-val "personal addresses" (if addrs (mapconcat #'identity addrs ", " ) "none")))) (if mu4e-main-buffer-hide-personal-addresses "" - (when (and user-mail-address (not (member user-mail-address addrs))) + (unless (mu4e-personal-address-p user-mail-address) (mu4e-message (concat - "Note: `user-mail-address' ('%s') is not part " - "of mu's addresses; add it with 'mu init --my-address='") - user-mail-address))) + "Tip: `user-mail-address' ('%s') is not part " + "of mu's addresses; add it with 'mu init + --my-address='") user-mail-address))) (mu4e-main-mode) (goto-char pos)))) diff --git a/mu4e/mu4e-message.el b/mu4e/mu4e-message.el index 3e89f90e..9ec0db3c 100644 --- a/mu4e/mu4e-message.el +++ b/mu4e/mu4e-message.el @@ -275,19 +275,17 @@ expressions, in which case any of those are tried for a match." (mu4e-message-field msg cfield)))))) (defun mu4e-message-contact-field-matches-me (msg cfield) - "Does contact-field CFIELD in MSG match me? -Checks whether any of the of the contacts in field -CFIELD (either :to, :from, :cc or :bcc) of msg MSG matches *me*, -that is, any of the e-mail address in -`(mu4e-personal-addresses)'. Returns the contact cell that -matched, or nil." + "Does contact-field CFIELD in MSG match me? Checks whether any +of the of the contacts in field CFIELD (either :to, :from, :cc or +:bcc) of msg MSG matches *me*, that is, any of the addresses for +which `mu4e-personal-address-p' return t. Returns the contact +cell that matched, or nil." (cl-find-if (lambda (cc-cell) (cl-member-if (lambda (addr) - (string= (downcase addr) (downcase (cdr cc-cell)))) - (mu4e-personal-addresses))) - (mu4e-message-field msg cfield))) + (mu4e-personal-address-p (cdr cc-cell))) + (mu4e-message-field msg cfield))))) (defsubst mu4e-message-part-field (msgpart field) "Get some FIELD from MSGPART. diff --git a/mu4e/mu4e-utils.el b/mu4e/mu4e-utils.el index 1421a58b..95c711cb 100644 --- a/mu4e/mu4e-utils.el +++ b/mu4e/mu4e-utils.el @@ -63,15 +63,22 @@ (kill-new path) (mu4e-message "Saved '%s' to kill-ring" path))) -(defun mu4e-user-mail-address-p (addr) - "If ADDR is one of user's e-mail addresses return t, nil otherwise. -User's addresses are set in `(mu4e-personal-addresses)'. Case -insensitive comparison is used." - (when (and addr (mu4e-personal-addresses) - (cl-find addr (mu4e-personal-addresses) - :test (lambda (s1 s2) - (eq t (compare-strings s1 nil nil s2 nil nil t))))) - t)) +(defun mu4e-personal-address-p (addr) + "Is ADDR a personal address? +Evaluate to nil if ADDR matches any of the personal addresses. +Uses (mu4e-personal-addresses) for the addresses with both the plain +addresses and /regular expressions/." + (seq-find + (lambda (m) + (if (string-match "/\\(.*\\)/" m) + (let ((rx (match-string 1 m)) + (case-fold-search t)) + (if (string-match rx addr) t nil)) + (eq t (compare-strings addr nil nil m nil nil 'case-insensitive)))) + (mu4e-personal-addresses))) + +(define-obsolete-function-alias 'mu4e-user-mail-address-p + 'mu4e-personal-address-p "1.5.5") (defmacro with~mu4e-context-vars (context &rest body) "Evaluate BODY, with variables let-bound for CONTEXT (if any). diff --git a/mu4e/mu4e-vars.el b/mu4e/mu4e-vars.el index 1837758e..12802d77 100644 --- a/mu4e/mu4e-vars.el +++ b/mu4e/mu4e-vars.el @@ -1049,9 +1049,14 @@ mu4e-compose.") (mu4e-error "database-path unknown; did you start mu4e?")) path)) -(defun mu4e-personal-addresses() - "Get the user's personal addresses, if any." - (when mu4e~server-props (plist-get mu4e~server-props :personal-addresses))) +(defun mu4e-personal-addresses(&optional no-regexp) + "Get the list user's personal addresses, as passed to `mu init --my-address=...'. + The address are either plain e-mail address or /regular + expressions/. When NO_REGEXP is non-nil, do not include regexp + address patterns (if any)." + (seq-remove + (lambda(addr) (and no-regexp (string-match-p "^/.*/" addr))) + (when mu4e~server-props (plist-get mu4e~server-props :personal-addresses)))) (defun mu4e-server-version() "Get the server version, which should match mu4e's." @@ -1060,7 +1065,6 @@ mu4e-compose.") (mu4e-error "version unknown; did you start mu4e?")) version)) - ;;; Handler functions ;; diff --git a/mu4e/mu4e-view.el b/mu4e/mu4e-view.el index cb2ee79e..ff981775 100644 --- a/mu4e/mu4e-view.el +++ b/mu4e/mu4e-view.el @@ -404,7 +404,8 @@ article-mode." (gnus-blocked-images ".") ;; don't load external images. ;; Possibly add headers (before "Attachments") (gnus-display-mime-function (mu4e~view-gnus-display-mime msg)) - (gnus-icalendar-additional-identities (mu4e-personal-addresses))) + (gnus-icalendar-additional-identities + (mu4e-personal-addresses 'no-regexp))) (gnus-article-prepare-display)) (setq mu4e~gnus-article-mime-handles gnus-article-mime-handles) (setq mu4e~view-message msg)