1 ;;; mime-def.el --- definition module about MIME
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: definition, MIME, multimedia, mail, news
8 ;; This file is part of FLIM (Faithful Library about Internet Message).
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; 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.
27 (defconst mime-library-version-string "Chao 1.6.1 - \"Ky
\e,Dr
\e(Bto\"")
35 (eval-when-compile (require 'cl))
38 "Emacs MIME Interfaces"
42 (custom-handle-keyword 'default-mime-charset :group 'mime
45 (defcustom mime-temp-directory (or (getenv "MIME_TMP_DIR")
51 "*Directory for temporary files."
55 (defcustom mime-uuencode-encoding-name-list '("x-uue" "x-uuencode")
56 "*List of encoding names for uuencode format."
58 :type '(repeat string))
61 ;;; @ required functions
64 (unless (fboundp 'butlast)
65 (defun butlast (x &optional n)
66 "Returns a copy of LIST with the last N elements removed."
67 (if (and n (<= n 0)) x
68 (nbutlast (copy-sequence x) n)))
70 (defun nbutlast (x &optional n)
71 "Modifies LIST to remove the last N elements."
76 (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil))
80 (defsubst eliminate-top-spaces (string)
81 "Eliminate top sequence of space or tab in STRING."
82 (if (string-match "^[ \t]+" string)
83 (substring string (match-end 0))
86 (defsubst regexp-* (regexp)
89 (defsubst regexp-or (&rest args)
90 (concat "\\(" (mapconcat (function identity) args "\\|") "\\)"))
96 (defconst std11-quoted-pair-regexp "\\\\.")
97 (defconst std11-non-qtext-char-list '(?\" ?\\ ?\r ?\n))
98 (defconst std11-qtext-regexp
99 (concat "[^" (char-list-to-string std11-non-qtext-char-list) "]"))
100 (defconst std11-quoted-string-regexp
103 (regexp-or std11-qtext-regexp std11-quoted-pair-regexp))
110 (defconst mime-tspecials "][()<>@,\;:\\\"/?=")
111 (defconst mime-token-regexp (concat "[^" mime-tspecials "\000-\040]+"))
112 (defconst mime-charset-regexp mime-token-regexp)
114 (defconst mime-media-type/subtype-regexp
115 (concat mime-token-regexp "/" mime-token-regexp))
118 ;;; @@ Quoted-Printable
121 (defconst quoted-printable-hex-chars "0123456789ABCDEF")
123 (defconst quoted-printable-octet-regexp
124 (concat "=[" quoted-printable-hex-chars
125 "][" quoted-printable-hex-chars "]"))
131 (defsubst make-mime-content-type (type subtype &optional parameters)
132 (list* (cons 'type type)
133 (cons 'subtype subtype)
134 (nreverse parameters))
137 (defsubst mime-content-type-primary-type (content-type)
138 "Return primary-type of CONTENT-TYPE."
139 (cdr (car content-type)))
141 (defsubst mime-content-type-subtype (content-type)
142 "Return primary-type of CONTENT-TYPE."
143 (cdr (cadr content-type)))
145 (defsubst mime-content-type-parameters (content-type)
146 "Return primary-type of CONTENT-TYPE."
149 (defsubst mime-content-type-parameter (content-type parameter)
150 "Return PARAMETER value of CONTENT-TYPE."
151 (cdr (assoc parameter (mime-content-type-parameters content-type))))
154 (defsubst mime-type/subtype-string (type &optional subtype)
155 "Return type/subtype string from TYPE and SUBTYPE."
158 (format "%s/%s" type subtype)
159 (format "%s" type))))
162 ;;; @ Content-Disposition
165 (defsubst mime-content-disposition-type (content-disposition)
166 "Return disposition-type of CONTENT-DISPOSITION."
167 (cdr (car content-disposition)))
169 (defsubst mime-content-disposition-parameters (content-disposition)
170 "Return disposition-parameters of CONTENT-DISPOSITION."
171 (cdr content-disposition))
173 (defsubst mime-content-disposition-parameter (content-disposition parameter)
174 "Return PARAMETER value of CONTENT-DISPOSITION."
175 (cdr (assoc parameter (cdr content-disposition))))
177 (defsubst mime-content-disposition-filename (content-disposition)
178 "Return filename of CONTENT-DISPOSITION."
179 (mime-content-disposition-parameter content-disposition "filename"))
185 (defsubst make-mime-entity-internal (buffer
186 header-start header-end
189 content-type content-disposition
191 (vector buffer header-start header-end body-start body-end
192 node-id content-type content-disposition encoding nil
195 (defsubst mime-entity-buffer-internal (entity) (aref entity 0))
196 (defsubst mime-entity-header-start-internal (entity) (aref entity 1))
197 (defsubst mime-entity-header-end-internal (entity) (aref entity 2))
198 (defsubst mime-entity-body-start-internal (entity) (aref entity 3))
199 (defsubst mime-entity-body-end-internal (entity) (aref entity 4))
200 (defsubst mime-entity-node-id-internal (entity) (aref entity 5))
201 (defsubst mime-entity-content-type-internal (entity) (aref entity 6))
202 (defsubst mime-entity-content-disposition-internal (entity) (aref entity 7))
203 (defsubst mime-entity-encoding-internal (entity) (aref entity 8))
204 (defsubst mime-entity-original-header-internal (entity) (aref entity 9))
205 (defsubst mime-entity-children-internal (entity) (aref entity 10))
206 (defsubst mime-entity-parsed-header-internal (entity) (aref entity 11))
208 (defsubst mime-entity-set-original-header-internal (entity header)
209 (aset entity 9 header))
210 (defsubst mime-entity-set-children-internal (entity children)
211 (aset entity 10 children))
212 (defsubst mime-entity-set-parsed-header-internal (entity header)
213 (aset entity 11 header))
216 ;;; @ message structure
219 (defvar mime-message-structure nil
220 "Information about structure of message.
221 Please use reference function `mime-entity-SLOT' to get value of SLOT.
223 Following is a list of slots of the structure:
225 buffer buffer includes this entity (buffer).
226 node-id node-id (list of integers)
227 header-start minimum point of header in raw-buffer
228 header-end maximum point of header in raw-buffer
229 body-start minimum point of body in raw-buffer
230 body-end maximum point of body in raw-buffer
231 content-type content-type (content-type)
232 content-disposition content-disposition (content-disposition)
233 encoding Content-Transfer-Encoding (string or nil)
234 children entities included in this entity (list of entity)
236 If an entity includes other entities in its body, such as multipart or
237 message/rfc822, `mime-entity' structures of them are included in
238 `children', so the `mime-entity' structure become a tree.")
240 (make-variable-buffer-local 'mime-message-structure)
248 ;;; mime-def.el ends here