mu4e: improve mu4e-compose-dont-reply-to-self handling

Use mu4e-personal-or-alternative-address to decide on whether an address
belongs to "this user". Update docs.
This commit is contained in:
Dirk-Jan C. Binnema 2023-10-28 11:43:21 +03:00
parent ea78fab0ef
commit 00191a3ec7
2 changed files with 20 additions and 24 deletions

View File

@ -192,7 +192,11 @@ predicate function. A value of nil keeps all the addresses."
(defcustom mu4e-compose-dont-reply-to-self nil (defcustom mu4e-compose-dont-reply-to-self nil
"If non-nil, do not include self. "If non-nil, do not include self.
Selfness is decided by `mu4e-personal-address-p'"
Whether a given address belongs to this user (the \"self\") is
determined by `mu4e-personal-or-alternative-address', which
overrides `message-dont-reply-to-names' when replying to
messages, if `mu4e-compose-dont-reply-to-self' is non-nil."
:type 'boolean :type 'boolean
:group 'mu4e-compose) :group 'mu4e-compose)
@ -635,22 +639,6 @@ This function uses `message-cite-function', and its settings apply."
(goto-char (point-min)) (goto-char (point-min))
(buffer-string))) (buffer-string)))
(defun mu4e--address-blacklist ()
"Get the list of addresses *not* to send mail to in wide-replies."
(let ((ignored mu4e-compose-reply-ignore-address)
(addrs (mu4e-personal-addresses))
(is-rx (lambda (addr) (string-match-p "^/.*/" addr))))
(when mu4e-compose-dont-reply-to-self
(setq ignored
(append ignored
(list
(regexp-opt
(seq-filter (lambda (addr)
(not (funcall is-rx addr))) addrs))
(seq-filter (lambda (addr)
(funcall is-rx addr)) addrs)))))
(flatten-list ignored)))
(defvar mu4e-user-agent-string (defvar mu4e-user-agent-string
(format "mu4e %s; emacs %s" mu4e-mu-version emacs-version) (format "mu4e %s; emacs %s" mu4e-mu-version emacs-version)
"The User-Agent string for mu4e, or nil.") "The User-Agent string for mu4e, or nil.")
@ -796,7 +784,10 @@ of message."
(mu4e--compose-setup (mu4e--compose-setup
'reply 'reply
(lambda (parent) (lambda (parent)
(let ((message-dont-reply-to-names (mu4e--address-blacklist))) (let ((message-dont-reply-to-names
(if mu4e-compose-dont-reply-to-self
message-dont-reply-to-names
#'mu4e-personal-or-alternative-address)))
(message-reply nil wide) (message-reply nil wide)
(insert (mu4e--compose-cite parent)))))) (insert (mu4e--compose-cite parent))))))

View File

@ -124,9 +124,10 @@ predicate function. A value of nil keeps all the addresses."
;;; user mail address ;;; user mail address
(defun mu4e-personal-addresses (&optional no-regexp) (defun mu4e-personal-addresses (&optional no-regexp)
"Get the list user's personal addresses, as passed to mu init. "Get the list user's personal addresses, as passed to \"mu init\".
The address are either plain e-mail address or /regular
expressions/. When NO-REGEXP is non-nil, do not include regexp The address are either plain e-mail addresses or regexps (strings
wrapped / /). When NO-REGEXP is non-nil, do not include regexp
address patterns (if any)." address patterns (if any)."
(seq-remove (seq-remove
(lambda (addr) (and no-regexp (string-match-p "^/.*/" addr))) (lambda (addr) (and no-regexp (string-match-p "^/.*/" addr)))
@ -152,15 +153,19 @@ with both the plain addresses and /regular expressions/."
"Return a function matching user's addresses. "Return a function matching user's addresses.
Function takes one parameter, an address. This glues mu4e's Function takes one parameter, an address. This glues mu4e's
personal addresses together with gnus' personal addresses together with gnus'
`message-alternative-emails'." `message-alternative-emails'.
(let* ((alts message-alternative-emails))
Note that this expanded definition of user-addresses is only for the
message composition."
(let* ((alts message-alternative-emails))
(lambda (addr) (lambda (addr)
(or (mu4e-personal-address-p addr) (or (mu4e-personal-address-p addr)
(cond (cond
((functionp alts) (funcall alts addr)) ((functionp alts) (funcall alts addr))
((stringp alts) (string-match alts addr)) ((stringp alts) (string-match alts addr))
(t nil)))))) (t nil))))))
;; Helpers ;; Helpers