mirror of https://github.com/djcb/mu.git
mu4e: Improve personal-address handling
Make mu4e-personal-address-p safe for being called with nil. Upgrade code that used mu4e-user-mail-address-p to mu4e-personal-address-p. Update docs. Add some more helpers to mu4e-message, and avoid some byte-compiler warnings.
This commit is contained in:
parent
6fc294102b
commit
4985f5c959
|
@ -608,7 +608,7 @@ cdr element the To: prefix.")
|
||||||
otherwise ; show the from address; prefixed with the appropriate
|
otherwise ; show the from address; prefixed with the appropriate
|
||||||
`mu4e-headers-from-or-to-prefix'."
|
`mu4e-headers-from-or-to-prefix'."
|
||||||
(let ((addr (cdr-safe (car-safe (mu4e-message-field msg :from)))))
|
(let ((addr (cdr-safe (car-safe (mu4e-message-field msg :from)))))
|
||||||
(if (and addr (mu4e-user-mail-address-p addr))
|
(if (and addr (mu4e-personal-address-p addr))
|
||||||
(concat (cdr mu4e-headers-from-or-to-prefix)
|
(concat (cdr mu4e-headers-from-or-to-prefix)
|
||||||
(mu4e~headers-contact-str (mu4e-message-field msg :to)))
|
(mu4e~headers-contact-str (mu4e-message-field msg :to)))
|
||||||
(concat (car mu4e-headers-from-or-to-prefix)
|
(concat (car mu4e-headers-from-or-to-prefix)
|
||||||
|
|
|
@ -31,6 +31,11 @@
|
||||||
(require 'flow-fill)
|
(require 'flow-fill)
|
||||||
(require 'shr)
|
(require 'shr)
|
||||||
|
|
||||||
|
(declare-function mu4e-error "mu4e-utils")
|
||||||
|
(declare-function mu4e-warn "mu4e-utils")
|
||||||
|
(declare-function mu4e-personal-address-p "mu4e-utils")
|
||||||
|
(declare-function mu4e-make-temp-file "mu4e-utils")
|
||||||
|
|
||||||
(defvar mu4e~view-message)
|
(defvar mu4e~view-message)
|
||||||
(defvar shr-inhibit-images)
|
(defvar shr-inhibit-images)
|
||||||
|
|
||||||
|
@ -287,6 +292,19 @@ cell that matched, or nil."
|
||||||
(cl-find-if (lambda (cell) (mu4e-personal-address-p (cdr cell)))
|
(cl-find-if (lambda (cell) (mu4e-personal-address-p (cdr cell)))
|
||||||
(mu4e-message-field msg cfield)))
|
(mu4e-message-field msg cfield)))
|
||||||
|
|
||||||
|
(defun mu4e-message-sent-by-me (msg)
|
||||||
|
"Is this message (to be) sent by me?
|
||||||
|
Checks if the from field matches user's personal addresses."
|
||||||
|
(mu4e-message-contact-field-matches-me msg :from))
|
||||||
|
|
||||||
|
(defun mu4e-message-personal-p (msg)
|
||||||
|
"Does message have user's personal address in any of the
|
||||||
|
contact fields?"
|
||||||
|
(cl-some
|
||||||
|
(lambda (field)
|
||||||
|
(mu4e-message-contact-field-matches-me msg field))
|
||||||
|
'(:from :to :cc :bcc)))
|
||||||
|
|
||||||
(defsubst mu4e-message-part-field (msgpart field)
|
(defsubst mu4e-message-part-field (msgpart field)
|
||||||
"Get some FIELD from MSGPART.
|
"Get some FIELD from MSGPART.
|
||||||
A part would look something like:
|
A part would look something like:
|
||||||
|
|
|
@ -68,14 +68,15 @@
|
||||||
Evaluate to nil if ADDR matches any of the personal addresses.
|
Evaluate to nil if ADDR matches any of the personal addresses.
|
||||||
Uses (mu4e-personal-addresses) for the addresses with both the plain
|
Uses (mu4e-personal-addresses) for the addresses with both the plain
|
||||||
addresses and /regular expressions/."
|
addresses and /regular expressions/."
|
||||||
(seq-find
|
(when addr
|
||||||
(lambda (m)
|
(seq-find
|
||||||
(if (string-match "/\\(.*\\)/" m)
|
(lambda (m)
|
||||||
(let ((rx (match-string 1 m))
|
(if (string-match "/\\(.*\\)/" m)
|
||||||
(case-fold-search t))
|
(let ((rx (match-string 1 m))
|
||||||
(if (string-match rx addr) t nil))
|
(case-fold-search t))
|
||||||
|
(if (string-match rx addr) t nil))
|
||||||
(eq t (compare-strings addr nil nil m nil nil 'case-insensitive))))
|
(eq t (compare-strings addr nil nil m nil nil 'case-insensitive))))
|
||||||
(mu4e-personal-addresses)))
|
(mu4e-personal-addresses))))
|
||||||
|
|
||||||
(define-obsolete-function-alias 'mu4e-user-mail-address-p
|
(define-obsolete-function-alias 'mu4e-user-mail-address-p
|
||||||
'mu4e-personal-address-p "1.5.5")
|
'mu4e-personal-address-p "1.5.5")
|
||||||
|
|
|
@ -270,7 +270,7 @@ found."
|
||||||
(:from-or-to
|
(:from-or-to
|
||||||
(let* ((from (mu4e-message-field msg :from))
|
(let* ((from (mu4e-message-field msg :from))
|
||||||
(from (and from (cdar from))))
|
(from (and from (cdar from))))
|
||||||
(if (mu4e-user-mail-address-p from)
|
(if (mu4e-personal-address-p from)
|
||||||
(mu4e~view-construct-contacts-header msg :to)
|
(mu4e~view-construct-contacts-header msg :to)
|
||||||
(mu4e~view-construct-contacts-header msg :from))))
|
(mu4e~view-construct-contacts-header msg :from))))
|
||||||
;; date
|
;; date
|
||||||
|
|
|
@ -2766,8 +2766,7 @@ message. An example should clarify this:
|
||||||
((mu4e-message-contact-field-matches msg :to
|
((mu4e-message-contact-field-matches msg :to
|
||||||
"mu-discuss@@googlegroups.com")
|
"mu-discuss@@googlegroups.com")
|
||||||
"/mu")
|
"/mu")
|
||||||
;; messages sent directly to me go to /archive
|
;; messages sent directly to some spefic address me go to /private
|
||||||
;; also `mu4e-user-mail-address-p' can be used
|
|
||||||
((mu4e-message-contact-field-matches msg :to "me@@example.com")
|
((mu4e-message-contact-field-matches msg :to "me@@example.com")
|
||||||
"/private")
|
"/private")
|
||||||
;; messages with football or soccer in the subject go to /football
|
;; messages with football or soccer in the subject go to /football
|
||||||
|
@ -2775,9 +2774,7 @@ message. An example should clarify this:
|
||||||
(mu4e-message-field msg :subject))
|
(mu4e-message-field msg :subject))
|
||||||
"/football")
|
"/football")
|
||||||
;; messages sent by me go to the sent folder
|
;; messages sent by me go to the sent folder
|
||||||
((find-if
|
((mu4e-message-sent-by-me msg
|
||||||
(lambda (addr)
|
|
||||||
(mu4e-message-contact-field-matches msg :from addr))
|
|
||||||
(mu4e-personal-addresses))
|
(mu4e-personal-addresses))
|
||||||
mu4e-sent-folder)
|
mu4e-sent-folder)
|
||||||
;; everything else goes to /archive
|
;; everything else goes to /archive
|
||||||
|
|
Loading…
Reference in New Issue