annotate lisp/tm/tm-parse.el @ 116:9f59509498e1 r20-1b10

Import from CVS: tag r20-1b10
author cvs
date Mon, 13 Aug 2007 09:23:06 +0200
parents 54cc21c15cbb
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 ;;; tm-parse.el --- MIME message parser
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) 1994,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>
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
6 ;; Version: $Id: tm-parse.el,v 1.1.1.2 1996/12/21 20:50:42 steve Exp $
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
7 ;; Keywords: mail, news, MIME, multimedia
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
8
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
9 ;; This file is part of tm (Tools for MIME).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
10
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
11 ;; This program is free software; you can redistribute it and/or
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
12 ;; modify it under the terms of the GNU General Public License as
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
13 ;; published by the Free Software Foundation; either version 2, or (at
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
14 ;; your option) any later version.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
15
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
16 ;; This program is distributed in the hope that it will be useful, but
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
19 ;; General Public License for more details.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
20
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
25
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
26 ;;; Code:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
27
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
28 (require 'std11)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
29 (require 'tl-misc)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
30 (require 'tm-def)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
31
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
32
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
33 ;;; @ field parser
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
34 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
35
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
36 (defconst rfc822/quoted-pair-regexp "\\\\.")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
37 (defconst rfc822/qtext-regexp
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
38 (concat "[^" (char-list-to-string std11-non-qtext-char-list) "]"))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
39 (defconst rfc822/quoted-string-regexp
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
40 (concat "\""
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
41 (regexp-*
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
42 (regexp-or rfc822/qtext-regexp rfc822/quoted-pair-regexp)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
43 )
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
44 "\""))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
45
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
46 (defconst mime/content-parameter-value-regexp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
47 (concat "\\("
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
48 rfc822/quoted-string-regexp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
49 "\\|[^; \t\n]*\\)"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
50
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
51 (defconst mime::parameter-regexp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
52 (concat "^[ \t]*\;[ \t]*\\(" mime/token-regexp "\\)"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
53 "[ \t]*=[ \t]*\\(" mime/content-parameter-value-regexp "\\)"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
54
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
55 (defun mime/parse-parameter (str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
56 (if (string-match mime::parameter-regexp str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
57 (let ((e (match-end 2)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
58 (cons
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
59 (cons (downcase (substring str (match-beginning 1) (match-end 1)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
60 (std11-strip-quoted-string
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
61 (substring str (match-beginning 2) e))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
62 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
63 (substring str e)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
64 ))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
65
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
66 (defconst mime::ctype-regexp (concat "^" mime/content-type-subtype-regexp))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
67
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
68 (defun mime/parse-Content-Type (string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
69 "Parse STRING as field-body of Content-Type field. [tm-parse.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
70 (setq string (std11-unfold-string string))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
71 (if (string-match mime::ctype-regexp string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
72 (let* ((e (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
73 (ctype (downcase (substring string 0 e)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
74 ret dest)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
75 (setq string (substring string e))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
76 (while (setq ret (mime/parse-parameter string))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
77 (setq dest (cons (car ret) dest)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
78 string (cdr ret))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
79 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
80 (cons ctype (nreverse dest))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
81 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
82
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
83 (defconst mime::dtype-regexp (concat "^" mime/disposition-type-regexp))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
84
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
85 (defun mime/parse-Content-Disposition (string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
86 "Parse STRING as field-body of Content-Disposition field. [tm-parse.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
87 (setq string (std11-unfold-string string))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
88 (if (string-match mime::dtype-regexp string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
89 (let* ((e (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
90 (ctype (downcase (substring string 0 e)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
91 ret dest)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
92 (setq string (substring string e))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
93 (while (setq ret (mime/parse-parameter string))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
94 (setq dest (cons (car ret) dest)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
95 string (cdr ret))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
96 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
97 (cons ctype (nreverse 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
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
100
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
101 ;;; @ field reader
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
102 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
103
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
104 (defun mime/Content-Type ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
105 "Read field-body of Content-Type field from current-buffer,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
106 and return parsed it. [tm-parse.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
107 (let ((str (std11-field-body "Content-Type")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
108 (if str
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
109 (mime/parse-Content-Type str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
110 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
111
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
112 (defun mime/Content-Transfer-Encoding (&optional default-encoding)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
113 "Read field-body of Content-Transfer-Encoding field from
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
114 current-buffer, and return it.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
115 If is is not found, return DEFAULT-ENCODING. [tm-parse.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
116 (let ((str (std11-field-body "Content-Transfer-Encoding")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
117 (if str
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
118 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
119 (if (string-match "[ \t\n\r]+$" str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
120 (setq str (substring str 0 (match-beginning 0)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
121 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
122 (downcase str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
123 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
124 default-encoding)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
125 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
126
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
127 (defun mime/Content-Disposition ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
128 "Read field-body of Content-Disposition field from current-buffer,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
129 and return parsed it. [tm-parse.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
130 (let ((str (std11-field-body "Content-Disposition")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
131 (if str
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
132 (mime/parse-Content-Disposition str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
133 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
134
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
135
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
136 ;;; @ message parser
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
137 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
138
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
139 (define-structure mime::content-info
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
140 rcnum point-min point-max type parameters encoding children)
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 (defun mime/parse-multipart (boundary ctype params encoding rcnum)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
144 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
145 (let* ((dash-boundary (concat "--" boundary))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
146 (delimiter (concat "\n" (regexp-quote dash-boundary)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
147 (close-delimiter (concat delimiter "--[ \t]*$"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
148 (beg (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
149 (end (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
150 (goto-char (point-max))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
151 (if (re-search-backward close-delimiter nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
152 (match-beginning 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
153 (point-max)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
154 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
155 (rsep (concat delimiter "[ \t]*\n"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
156 (dc-ctl
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
157 (if (string-equal ctype "multipart/digest")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
158 '("message/rfc822")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
159 '("text/plain")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
160 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
161 cb ce ct ret ncb children (i 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
162 (save-restriction
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
163 (narrow-to-region beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
164 (goto-char beg)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
165 (re-search-forward rsep nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
166 (setq cb (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
167 (while (re-search-forward rsep nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
168 (setq ce (match-beginning 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
169 (setq ncb (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
170 (save-restriction
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
171 (narrow-to-region cb ce)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
172 (setq ret (mime/parse-message dc-ctl "7bit" (cons i rcnum)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
173 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
174 (setq children (cons ret children))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
175 (goto-char (mime::content-info/point-max ret))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
176 (goto-char (setq cb ncb))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
177 (setq i (1+ i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
178 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
179 (setq ce (point-max))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
180 (save-restriction
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
181 (narrow-to-region cb ce)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
182 (setq ret (mime/parse-message dc-ctl "7bit" (cons i rcnum)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
183 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
184 (setq children (cons ret children))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
185 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
186 (mime::content-info/create rcnum beg (point-max)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
187 ctype params encoding
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
188 (nreverse children))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
189 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
190
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
191 (defun mime/parse-message (&optional ctl encoding rcnum)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
192 "Parse current-buffer as a MIME message. [tm-parse.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
193 (setq ctl (or (mime/Content-Type) ctl))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
194 (setq encoding (or (mime/Content-Transfer-Encoding) encoding))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
195 (let ((ctype (car ctl))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
196 (params (cdr ctl))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
197 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
198 (let ((boundary (assoc "boundary" params)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
199 (cond (boundary
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
200 (setq boundary (std11-strip-quoted-string (cdr boundary)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
201 (mime/parse-multipart boundary ctype params encoding rcnum)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
202 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
203 ((or (string-equal ctype "message/rfc822")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
204 (string-equal ctype "message/news")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
205 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
206 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
207 (mime::content-info/create rcnum
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
208 (point-min) (point-max)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
209 ctype params encoding
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
210 (save-restriction
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
211 (narrow-to-region
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
212 (if (re-search-forward "^$" nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
213 (1+ (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
214 (point-min)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
215 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
216 (point-max))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
217 (list (mime/parse-message
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
218 nil nil (cons 0 rcnum)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
219 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
220 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
221 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
222 (t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
223 (mime::content-info/create rcnum (point-min) (point-max)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
224 ctype params encoding nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
225 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
226 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
227
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
228
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
229 ;;; @ end
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
230 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
231
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
232 (provide 'tm-parse)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
233
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
234 ;;; tm-parse.el ends here