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
|
||||
`mu4e-headers-from-or-to-prefix'."
|
||||
(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)
|
||||
(mu4e~headers-contact-str (mu4e-message-field msg :to)))
|
||||
(concat (car mu4e-headers-from-or-to-prefix)
|
||||
|
|
|
@ -31,6 +31,11 @@
|
|||
(require 'flow-fill)
|
||||
(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 shr-inhibit-images)
|
||||
|
||||
|
@ -287,6 +292,19 @@ cell that matched, or nil."
|
|||
(cl-find-if (lambda (cell) (mu4e-personal-address-p (cdr cell)))
|
||||
(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)
|
||||
"Get some FIELD from MSGPART.
|
||||
A part would look something like:
|
||||
|
|
|
@ -68,14 +68,15 @@
|
|||
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))
|
||||
(when addr
|
||||
(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)))
|
||||
(mu4e-personal-addresses))))
|
||||
|
||||
(define-obsolete-function-alias 'mu4e-user-mail-address-p
|
||||
'mu4e-personal-address-p "1.5.5")
|
||||
|
|
|
@ -270,7 +270,7 @@ found."
|
|||
(:from-or-to
|
||||
(let* ((from (mu4e-message-field msg :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 :from))))
|
||||
;; date
|
||||
|
|
|
@ -2766,8 +2766,7 @@ message. An example should clarify this:
|
|||
((mu4e-message-contact-field-matches msg :to
|
||||
"mu-discuss@@googlegroups.com")
|
||||
"/mu")
|
||||
;; messages sent directly to me go to /archive
|
||||
;; also `mu4e-user-mail-address-p' can be used
|
||||
;; messages sent directly to some spefic address me go to /private
|
||||
((mu4e-message-contact-field-matches msg :to "me@@example.com")
|
||||
"/private")
|
||||
;; 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))
|
||||
"/football")
|
||||
;; messages sent by me go to the sent folder
|
||||
((find-if
|
||||
(lambda (addr)
|
||||
(mu4e-message-contact-field-matches msg :from addr))
|
||||
((mu4e-message-sent-by-me msg
|
||||
(mu4e-personal-addresses))
|
||||
mu4e-sent-folder)
|
||||
;; everything else goes to /archive
|
||||
|
|
Loading…
Reference in New Issue