1 ;;; rfc2368.el --- support for rfc2368
3 ;; Author: Sen Nagata <sen@eccosys.com>
6 ;; Copyright (C) 1998, 2000, 2002, 2003, 2004,
7 ;; 2005 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
30 ;; -repeat after me: "the colon is not part of the header name..."
31 ;; -if w3 becomes part of emacs, then it may make sense to have this
32 ;; file depend on w3 -- the maintainer of w3 says merging w/ Emacs
37 ;; this is intended as a replacement for mailto.el
41 ;; the functions that deal w/ unhexifying in this file were basically
42 ;; taken from w3 -- i hope to replace them w/ something else soon OR
43 ;; perhaps if w3 becomes a part of emacs soon, use the functions from w3.
49 ;; added the constant rfc2368-version
50 ;; implemented first potential fix for a bug in rfc2368-mailto-regexp
51 ;; implemented first potential fix for a bug in rfc2368-parse-mailto
52 ;; (both bugs reported by Kenichi OKADA)
56 ;; started to use checkdoc
60 ;; initial implementation
64 ;; only an approximation?
66 (defconst rfc2368-mailto-regexp
67 "^\\(mailto:\\)\\([^?]+\\)*\\(\\?\\(.*\\)\\)*"
68 "Regular expression to match and aid in parsing a mailto url.")
70 ;; describes 'mailto:'
71 (defconst rfc2368-mailto-scheme-index
1
72 "Describes the 'mailto:' portion of the url.")
73 ;; i'm going to call this part the 'prequery'
74 (defconst rfc2368-mailto-prequery-index
2
75 "Describes the portion of the url between 'mailto:' and '?'.")
76 ;; i'm going to call this part the 'query'
77 (defconst rfc2368-mailto-query-index
4
78 "Describes the portion of the url after '?'.")
80 (defun rfc2368-unhexify-string (string)
81 "Unhexify STRING -- e.g. 'hello%20there' -> 'hello there'."
82 (replace-regexp-in-string "%[[:xdigit:]]\\{2\\}"
84 (string (string-to-number (substring match
1)
88 (defun rfc2368-parse-mailto-url (mailto-url)
89 "Parse MAILTO-URL, and return an alist of header-name, header-value pairs.
90 MAILTO-URL should be a RFC 2368 (mailto) compliant url. A cons cell w/ a
91 key of 'Body' is a special case and is considered a header for this purpose.
92 The returned alist is intended for use w/ the `compose-mail' interface.
93 Note: make sure MAILTO-URL has been 'unhtmlized' (e.g. & -> &), before
94 calling this function."
95 (let ((case-fold-search t
)
96 prequery query headers-alist
)
98 (if (string-match rfc2368-mailto-regexp mailto-url
)
102 (match-string rfc2368-mailto-prequery-index mailto-url
))
105 (match-string rfc2368-mailto-query-index mailto-url
))
107 ;; build alist of header name-value pairs
108 (if (not (null query
))
112 (let* ((temp-list (split-string x
"="))
113 (header-name (car temp-list
))
114 (header-value (cadr temp-list
)))
115 ;; return ("Header-Name" . "header-value")
117 (capitalize (rfc2368-unhexify-string header-name
))
118 (rfc2368-unhexify-string header-value
))))
119 (split-string query
"&"))))
121 ;; deal w/ multiple 'To' recipients
124 (setq prequery
(rfc2368-unhexify-string prequery
))
125 (if (assoc "To" headers-alist
)
126 (let* ((our-cons-cell
127 (assoc "To" headers-alist
))
129 (cdr our-cons-cell
)))
130 (setcdr our-cons-cell
(concat prequery
", " our-cdr
)))
132 (cons (cons "To" prequery
) headers-alist
)))))
136 (error "Failed to match a mailto: url"))
141 ;;; arch-tag: ea804934-ad96-4f69-957b-857a76e4fd95
142 ;;; rfc2368.el ends here