123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- (defconst rfc2368-mailto-regexp
- "^\\(mailto:\\)\\([^?]+\\)*\\(\\?\\(.*\\)\\)*"
- "Regular expression to match and aid in parsing a mailto url.")
- (defconst rfc2368-mailto-scheme-index 1
- "Describes the 'mailto:' portion of the url.")
- (defconst rfc2368-mailto-prequery-index 2
- "Describes the portion of the url between 'mailto:' and '?'.")
- (defconst rfc2368-mailto-query-index 4
- "Describes the portion of the url after '?'.")
- (defun rfc2368-unhexify-string (string)
- "Unhexify STRING -- e.g. 'hello%20there' -> 'hello there'."
- (replace-regexp-in-string "%[[:xdigit:]]\\{2\\}"
- (lambda (match)
- (string (string-to-number (substring match 1)
- 16)))
- string t t))
- (defun rfc2368-parse-mailto-url (mailto-url)
- "Parse MAILTO-URL, and return an alist of header-name, header-value pairs.
- MAILTO-URL should be a RFC 2368 (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)
- prequery query headers-alist)
- (setq mailto-url (replace-regexp-in-string "\n" " " mailto-url))
- (if (string-match rfc2368-mailto-regexp mailto-url)
- (progn
- (setq prequery
- (match-string rfc2368-mailto-prequery-index mailto-url))
- (setq query
- (match-string rfc2368-mailto-query-index mailto-url))
-
- (if (not (null query))
- (setq headers-alist
- (mapcar
- (lambda (x)
- (let* ((temp-list (split-string x "="))
- (header-name (car temp-list))
- (header-value (cadr temp-list)))
-
- (cons
- (capitalize (rfc2368-unhexify-string header-name))
- (rfc2368-unhexify-string header-value))))
- (split-string query "&"))))
-
- (if prequery
- (progn
- (setq prequery (rfc2368-unhexify-string prequery))
- (if (assoc "To" headers-alist)
- (let* ((our-cons-cell
- (assoc "To" headers-alist))
- (our-cdr
- (cdr our-cons-cell)))
- (setcdr our-cons-cell (concat prequery ", " our-cdr)))
- (setq headers-alist
- (cons (cons "To" prequery) headers-alist)))))
- headers-alist)
- (error "Failed to match a mailto: url"))))
- (provide 'rfc2368)
|