Mercurial > emacs
annotate lisp/mail/rfc2368.el @ 62643:253d903435d5
*** empty log message ***
author | Martin Stjernholm <mast@lysator.liu.se> |
---|---|
date | Mon, 23 May 2005 00:06:28 +0000 |
parents | 455a962a0dba |
children | 18a818a2ee7c 4c90ffeb71c5 |
rev | line source |
---|---|
28496 | 1 ;;; rfc2368.el --- support for rfc2368 |
2 | |
28520
afc8a292184c
Correct author's email address.
Gerd Moellmann <gerd@gnu.org>
parents:
28500
diff
changeset
|
3 ;; Author: Sen Nagata <sen@eccosys.com> |
28496 | 4 ;; Keywords: mail |
5 | |
6 ;; Copyright (C) 1998, 2000 Free Software Foundation, Inc. | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
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) | |
13 ;; any later version. | |
14 | |
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. | |
19 | |
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. | |
24 | |
25 ;;; Commentary: | |
26 ;; | |
27 ;; notes: | |
28 ;; | |
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 | |
32 ;; is planned! | |
33 ;; | |
34 ;; historical note: | |
35 ;; | |
36 ;; this is intended as a replacement for mailto.el | |
37 ;; | |
38 ;; acknowledgements: | |
39 ;; | |
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. | |
43 | |
44 ;;; History: | |
45 ;; | |
46 ;; 0.3: | |
47 ;; | |
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) | |
52 ;; | |
53 ;; 0.2: | |
54 ;; | |
55 ;; started to use checkdoc | |
56 ;; | |
57 ;; 0.1: | |
58 ;; | |
59 ;; initial implementation | |
60 | |
61 ;;; Code: | |
62 | |
63 ;; only an approximation? | |
64 ;; see rfc 1738 | |
65 (defconst rfc2368-mailto-regexp | |
66 "^\\(mailto:\\)\\([^?]+\\)*\\(\\?\\(.*\\)\\)*" | |
67 "Regular expression to match and aid in parsing a mailto url.") | |
68 | |
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 '?'.") | |
78 | |
79 (defun rfc2368-unhexify-string (string) | |
80 "Unhexify STRING -- e.g. 'hello%20there' -> 'hello there'." | |
54306
b3fd1d53ef39
(rfc2368-unhexify-char): Deleted.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
81 (replace-regexp-in-string "%[[:xdigit:]]\\{2\\}" |
b3fd1d53ef39
(rfc2368-unhexify-char): Deleted.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
82 (lambda (match) |
b3fd1d53ef39
(rfc2368-unhexify-char): Deleted.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
83 (string (string-to-number (substring match 1) |
b3fd1d53ef39
(rfc2368-unhexify-char): Deleted.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
84 16))) |
b3fd1d53ef39
(rfc2368-unhexify-char): Deleted.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
85 string t t)) |
28496 | 86 |
87 (defun rfc2368-parse-mailto-url (mailto-url) | |
88 "Parse MAILTO-URL, and return an alist of header-name, header-value pairs. | |
89 MAILTO-URL should be a RFC 2368 (mailto) compliant url. A cons cell w/ a | |
90 key of 'Body' is a special case and is considered a header for this purpose. | |
91 The returned alist is intended for use w/ the `compose-mail' interface. | |
92 Note: make sure MAILTO-URL has been 'unhtmlized' (e.g. & -> &), before | |
93 calling this function." | |
94 (let ((case-fold-search t) | |
95 prequery query headers-alist) | |
96 | |
97 (if (string-match rfc2368-mailto-regexp mailto-url) | |
98 (progn | |
99 | |
100 (setq prequery | |
101 (match-string rfc2368-mailto-prequery-index mailto-url)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
28520
diff
changeset
|
102 |
28496 | 103 (setq query |
104 (match-string rfc2368-mailto-query-index mailto-url)) | |
105 | |
106 ;; build alist of header name-value pairs | |
107 (if (not (null query)) | |
108 (setq headers-alist | |
109 (mapcar | |
110 (lambda (x) | |
111 (let* ((temp-list (split-string x "=")) | |
112 (header-name (car temp-list)) | |
113 (header-value (cadr temp-list))) | |
114 ;; return ("Header-Name" . "header-value") | |
115 (cons | |
116 (capitalize (rfc2368-unhexify-string header-name)) | |
117 (rfc2368-unhexify-string header-value)))) | |
118 (split-string query "&")))) | |
119 | |
120 ;; deal w/ multiple 'To' recipients | |
121 (if prequery | |
122 (progn | |
55529
455a962a0dba
(rfc2368-parse-mailto-url): Make the results of
Eli Zaretskii <eliz@gnu.org>
parents:
54306
diff
changeset
|
123 (setq prequery (rfc2368-unhexify-string prequery)) |
28496 | 124 (if (assoc "To" headers-alist) |
125 (let* ((our-cons-cell | |
126 (assoc "To" headers-alist)) | |
127 (our-cdr | |
128 (cdr our-cons-cell))) | |
55529
455a962a0dba
(rfc2368-parse-mailto-url): Make the results of
Eli Zaretskii <eliz@gnu.org>
parents:
54306
diff
changeset
|
129 (setcdr our-cons-cell (concat prequery ", " our-cdr))) |
28496 | 130 (setq headers-alist |
131 (cons (cons "To" prequery) headers-alist))))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
28520
diff
changeset
|
132 |
28496 | 133 headers-alist) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
28520
diff
changeset
|
134 |
28496 | 135 (error "Failed to match a mailto: url")) |
136 )) | |
137 | |
138 (provide 'rfc2368) | |
139 | |
52401 | 140 ;;; arch-tag: ea804934-ad96-4f69-957b-857a76e4fd95 |
28496 | 141 ;;; rfc2368.el ends here |