1 ;;; rfc2368.el --- support for rfc2368
3 ;; Author: Sen Nagata <sen@eccosys.com>
6 ;; Copyright (C) 1998, 2000 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 ;; -repeat after me: "the colon is not part of the header name..."
30 ;; -if w3 becomes part of emacs, then it may make sense to have this
31 ;; file depend on w3 -- the maintainer of w3 says merging w/ Emacs
36 ;; this is intended as a replacement for mailto.el
40 ;; the functions that deal w/ unhexifying in this file were basically
41 ;; taken from w3 -- i hope to replace them w/ something else soon OR
42 ;; perhaps if w3 becomes a part of emacs soon, use the functions from w3.
48 ;; added the constant rfc2368-version
49 ;; implemented first potential fix for a bug in rfc2368-mailto-regexp
50 ;; implemented first potential fix for a bug in rfc2368-parse-mailto
51 ;; (both bugs reported by Kenichi OKADA)
55 ;; started to use checkdoc
59 ;; initial implementation
63 ;; only an approximation?
65 (defconst rfc2368-mailto-regexp
66 "^\\(mailto:\\)\\([^?]+\\)*\\(\\?\\(.*\\)\\)*"
67 "Regular expression to match and aid in parsing a mailto url.")
69 ;; describes 'mailto:'
70 (defconst rfc2368-mailto-scheme-index
1
71 "Describes the 'mailto:' portion of the url.")
72 ;; i'm going to call this part the 'prequery'
73 (defconst rfc2368-mailto-prequery-index
2
74 "Describes the portion of the url between 'mailto:' and '?'.")
75 ;; i'm going to call this part the 'query'
76 (defconst rfc2368-mailto-query-index
4
77 "Describes the portion of the url after '?'.")
79 (defun rfc2368-unhexify-string (string)
80 "Unhexify STRING -- e.g. 'hello%20there' -> 'hello there'."
83 (while (string-match "+\\|%\\(0D%0A\\|\\([0-9a-fA-F][0-9a-fA-F]\\)\\)"
85 (push (substring string start
(match-beginning 0)) buf
)
88 (vector (string-to-number (match-string 2 string
) 16)))
89 ((match-beginning 1) "\n")
92 (setq start
(match-end 0)))
93 (apply 'concat
(nreverse (cons (substring string start
) buf
)))))
95 (defun rfc2368-parse-mailto-url (mailto-url)
96 "Parse MAILTO-URL, and return an alist of header-name, header-value pairs.
97 MAILTO-URL should be a RFC 2368 (mailto) compliant url. A cons cell w/ a
98 key of 'Body' is a special case and is considered a header for this purpose.
99 The returned alist is intended for use w/ the `compose-mail' interface.
100 Note: make sure MAILTO-URL has been 'unhtmlized' (e.g. & -> &), before
101 calling this function."
102 (let ((case-fold-search t
)
103 prequery query headers-alist
)
108 (goto-char (point-min))
109 (while (re-search-forward "\n" nil t
)
112 (if (string-match rfc2368-mailto-regexp mailto-url
)
116 (match-string rfc2368-mailto-prequery-index mailto-url
))
119 (match-string rfc2368-mailto-query-index mailto-url
))
121 ;; build alist of header name-value pairs
122 (if (not (null query
))
126 (let* ((temp-list (split-string x
"="))
127 (header-name (car temp-list
))
128 (header-value (cadr temp-list
)))
129 ;; return ("Header-Name" . "header-value")
131 (capitalize (rfc2368-unhexify-string header-name
))
132 (rfc2368-unhexify-string header-value
))))
133 (split-string query
"&"))))
135 ;; deal w/ multiple 'To' recipients
138 (setq prequery
(rfc2368-unhexify-string prequery
))
139 (if (assoc "To" headers-alist
)
140 (let* ((our-cons-cell
141 (assoc "To" headers-alist
))
143 (cdr our-cons-cell
)))
144 (setcdr our-cons-cell
(concat prequery
", " our-cdr
)))
146 (cons (cons "To" prequery
) headers-alist
)))))
150 (error "Failed to match a mailto: url"))
155 ;;; rfc2368.el ends here