Function: mail-header-parse-address-lax
mail-header-parse-address-lax is a byte-compiled function defined in
mail-parse.el.gz.
Signature
(mail-header-parse-address-lax STRING)
Documentation
Parse STRING as a mail address.
Returns a mail/name pair.
This function will first try to parse STRING as a standards-compliant address string, and if that fails, try to use heuristics to determine the email address and the name in the string.
Probably introduced at or before Emacs version 28.1.
Source Code
;; Defined in /usr/src/emacs/lisp/mail/mail-parse.el.gz
(defun mail-header-parse-address-lax (string)
"Parse STRING as a mail address.
Returns a mail/name pair.
This function will first try to parse STRING as a
standards-compliant address string, and if that fails, try to use
heuristics to determine the email address and the name in the
string."
(with-temp-buffer
(insert (string-clean-whitespace string))
;; Find the bit with the @ and guess that that's the mail.
(goto-char (point-max))
(when (search-backward "@" nil t)
(if (re-search-backward " " nil t)
(forward-char 1)
(goto-char (point-min)))
(let* ((start (point))
(mail (buffer-substring
start (or (re-search-forward " " nil t)
(goto-char (point-max))))))
(delete-region start (point))
;; We've now removed the email bit, so the rest of the stuff
;; has to be the name.
(cons (string-trim mail "[<]+" "[>]+")
(let ((name (string-trim (buffer-string)
"[ \t\n\r(]+" "[ \t\n\r)]+")))
(if (length= name 0)
nil
name)))))))