annotate lisp/tl/tl-822.el @ 35:279432d5c479

Added tag r19-15b100 for changeset d620409f5eb8
author cvs
date Mon, 13 Aug 2007 08:53:21 +0200
parents b82b59fe008d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1 ;;; tl-822.el --- RFC 822 parser for GNU Emacs
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
2
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
6 ;; Keywords: mail, news, RFC 822
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
7
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
8 ;; This file is part of tl (Tiny Library).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
9
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
10 ;; This program is free software; you can redistribute it and/or
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
11 ;; modify it under the terms of the GNU General Public License as
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
12 ;; published by the Free Software Foundation; either version 2, or (at
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
13 ;; your option) any later version.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
14
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
15 ;; This program is distributed in the hope that it will be useful, but
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
18 ;; General Public License for more details.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
19
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
21 ;; along with This program; see the file COPYING. If not, write to
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
24
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
25 ;;; Code:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
26
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
27 (require 'tl-seq)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
28 (require 'tl-str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
29 (require 'std11)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
30
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
31
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
32 (defconst rfc822/RCS-ID
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
33 "$Id: tl-822.el,v 1.1.1.1 1996/12/18 03:55:31 steve Exp $")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
34 (defconst rfc822/version (get-version-string rfc822/RCS-ID))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
35
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
36
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
37 ;;; @ header
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
38 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
39
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
40 (defalias 'rfc822/narrow-to-header 'std11-narrow-to-header)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
41 (defalias 'rfc822/get-header-string 'std11-header-string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
42 (defalias 'rfc822/get-header-string-except 'std11-header-string-except)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
43 (defalias 'rfc822/get-field-names 'std11-collect-field-names)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
44
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
45
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
46 ;;; @ field
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
47 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
48
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
49 (defalias `rfc822/field-end 'std11-field-end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
50 (defalias 'rfc822/get-field-body 'std11-field-body)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
51 (defalias 'rfc822/get-field-bodies 'std11-field-bodies)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
52
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
53
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
54 ;;; @ quoting
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
55 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
56
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
57 (defconst rfc822/linear-white-space-regexp "\\(\n?[ \t]\\)+")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
58 (defconst rfc822/quoted-pair-regexp "\\\\.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
59 (defconst rfc822/non-qtext-char-list '(?\" ?\\ ?\r ?\n))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
60 (defconst rfc822/qtext-regexp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
61 (concat "[^" (char-list-to-string rfc822/non-qtext-char-list) "]"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
62 (defconst rfc822/quoted-string-regexp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
63 (concat "\""
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
64 (regexp-*
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
65 (regexp-or rfc822/qtext-regexp rfc822/quoted-pair-regexp)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
66 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
67 "\""))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
68
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
69 (defun rfc822/wrap-as-quoted-string (str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
70 "Wrap string STR as RFC 822 quoted-string. [tl-822.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
71 (concat "\""
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
72 (mapconcat (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
73 (lambda (chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
74 (if (memq chr rfc822/non-qtext-char-list)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
75 (concat "\\" (char-to-string chr))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
76 (char-to-string chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
77 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
78 )) str "")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
79 "\""))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
80
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
81 (defun rfc822/strip-quoted-pair (str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
82 (let ((dest "")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
83 (i 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
84 (len (length str))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
85 chr flag)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
86 (while (< i len)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
87 (setq chr (elt str i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
88 (if (or flag (not (eq chr ?\\)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
89 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
90 (setq dest (concat dest (char-to-string chr)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
91 (setq flag nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
92 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
93 (setq flag t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
94 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
95 (setq i (+ i 1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
96 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
97 dest))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
98
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
99 (defun rfc822/strip-quoted-string (str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
100 (rfc822/strip-quoted-pair
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
101 (let ((max (- (length str) 1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
102 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
103 (if (and (eq (elt str 0) ?\")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
104 (eq (elt str max) ?\")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
105 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
106 (substring str 1 max)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
107 str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
108 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
109
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
110
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
111 ;;; @ unfolding
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
112 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
113
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
114 (defalias 'rfc822/unfolding-string 'std11-unfold-string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
115
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
116
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
117 ;;; @ lexical analyze
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
118 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
119
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
120 (defalias 'rfc822/lexical-analyze 'std11-lexical-analyze)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
121
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
122
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
123 ;;; @ parser
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
124 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
125
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
126 (defalias 'rfc822/parse-address 'std11-parse-address)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
127 (defalias 'rfc822/parse-addresses 'std11-parse-addresses)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
128 (defalias 'rfc822/address-string 'std11-address-string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
129 (defalias 'rfc822/full-name-string 'std11-full-name-string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
130
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
131 (defun rfc822/extract-address-components (string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
132 "Extract full name and canonical address from STRING.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
133 Returns a list of the form (FULL-NAME CANONICAL-ADDRESS).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
134 If no name can be extracted, FULL-NAME will be nil. [tl-822.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
135 (let* ((structure (car (std11-parse-address-string string)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
136 (phrase (rfc822/full-name-string structure))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
137 (address (rfc822/address-string structure))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
138 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
139 (list phrase address)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
140 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
141
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
142
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
143 ;;; @ end
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
144 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
145
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
146 (provide 'tl-822)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
147
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
148 ;;; tl-822.el ends here