Function: rfc6068-parse-mailto-url

rfc6068-parse-mailto-url is an autoloaded and byte-compiled function defined in rfc6068.el.gz.

Signature

(rfc6068-parse-mailto-url MAILTO-URL)

Documentation

Parse MAILTO-URL, and return an alist of header-name, header-value pairs.

MAILTO-URL should be a RFC 6068 (mailto) compliant url. A cons cell w/ a key of Body is a special case and is considered a header for this purpose. The returned alist is intended for use w/ the compose-mail interface. Note: make sure MAILTO-URL has been "unhtmlized" (e.g., & -> &), before calling this function.

Probably introduced at or before Emacs version 28.1.

Source Code

;; Defined in /usr/src/emacs/lisp/mail/rfc6068.el.gz
(defun rfc6068-parse-mailto-url (mailto-url)
  "Parse MAILTO-URL, and return an alist of header-name, header-value pairs.
MAILTO-URL should be a RFC 6068 (mailto) compliant url.  A cons cell w/ a
key of `Body' is a special case and is considered a header for this purpose.
The returned alist is intended for use w/ the `compose-mail' interface.
Note: make sure MAILTO-URL has been \"unhtmlized\" (e.g., & -> &), before
calling this function."
  (let ((case-fold-search t)
	headers-alist)
    (setq mailto-url (string-replace "\n" " " mailto-url))
    (when (string-match "^\\(mailto:\\)\\([^?]+\\)?\\(\\?\\(.*\\)\\)*"
                        mailto-url)
      (let ((address (match-string 2 mailto-url))
            (query (match-string 4 mailto-url)))
	;; Build alist of header name-value pairs.
	(when query
	  (setq headers-alist
		(mapcar
		 (lambda (x)
		   (let* ((pair (split-string x "="))
			  (name (car pair))
			  (value (cadr pair)))
		     ;; Return ("Header-Name" . "header-value").
		     (cons
		      (capitalize (rfc6068-unhexify-string name))
		      (rfc6068-unhexify-string value))))
		 (split-string query "&"))))

	(when address
	  (setq address (rfc6068-unhexify-string address))
	  ;; Deal with multiple 'To' recipients.
	  (if-let ((elem (assoc "To" headers-alist)))
	      (setcdr elem (concat address ", " (cdr elem)))
            (push (cons "To" address) headers-alist)))

	headers-alist))))