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 FLAM (Faithful Library About MIME).
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
28 "FLAM-DOODLE 1.9.1 - \"
\e$B2+C0
\e(B\" 10R5.5/14.0")
36 (eval-when-compile (require 'cl))
39 "Emacs MIME Interfaces"
43 (custom-handle-keyword 'default-mime-charset :group 'mime
46 (defcustom mime-temp-directory (or (getenv "MIME_TMP_DIR")
52 "*Directory for temporary files."
56 (defcustom mime-uuencode-encoding-name-list '("x-uue" "x-uuencode")
57 "*List of encoding names for uuencode format."
59 :type '(repeat string))
62 ;;; @ required functions
65 (unless (fboundp 'butlast)
66 (defun butlast (x &optional n)
67 "Returns a copy of LIST with the last N elements removed."
68 (if (and n (<= n 0)) x
69 (nbutlast (copy-sequence x) n)))
71 (defun nbutlast (x &optional n)
72 "Modifies LIST to remove the last N elements."
77 (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil))
81 (defsubst eliminate-top-spaces (string)
82 "Eliminate top sequence of space or tab in STRING."
83 (if (string-match "^[ \t]+" string)
84 (substring string (match-end 0))
87 (defsubst regexp-* (regexp)
90 (defsubst regexp-or (&rest args)
91 (concat "\\(" (mapconcat (function identity) args "\\|") "\\)"))
97 (defconst std11-quoted-pair-regexp "\\\\.")
98 (defconst std11-non-qtext-char-list '(?\" ?\\ ?\r ?\n))
99 (defconst std11-qtext-regexp
100 (concat "[^" (char-list-to-string std11-non-qtext-char-list) "]"))
101 (defconst std11-quoted-string-regexp
104 (regexp-or std11-qtext-regexp std11-quoted-pair-regexp))
111 (defconst mime-tspecials "][()<>@,\;:\\\"/?=")
112 (defconst mime-token-regexp (concat "[^" mime-tspecials "\000-\040]+"))
113 (defconst mime-charset-regexp mime-token-regexp)
115 (defconst mime-media-type/subtype-regexp
116 (concat mime-token-regexp "/" mime-token-regexp))
119 ;;; @@ Quoted-Printable
122 (defconst quoted-printable-hex-chars "0123456789ABCDEF")
124 (defconst quoted-printable-octet-regexp
125 (concat "=[" quoted-printable-hex-chars
126 "][" quoted-printable-hex-chars "]"))
132 (defsubst make-mime-content-type (type subtype &optional parameters)
133 (list* (cons 'type type)
134 (cons 'subtype subtype)
135 (nreverse parameters))
138 (defsubst mime-content-type-primary-type (content-type)
139 "Return primary-type of CONTENT-TYPE."
140 (cdr (car content-type)))
142 (defsubst mime-content-type-subtype (content-type)
143 "Return primary-type of CONTENT-TYPE."
144 (cdr (cadr content-type)))
146 (defsubst mime-content-type-parameters (content-type)
147 "Return primary-type of CONTENT-TYPE."
150 (defsubst mime-content-type-parameter (content-type parameter)
151 "Return PARAMETER value of CONTENT-TYPE."
152 (cdr (assoc parameter (mime-content-type-parameters content-type))))
155 (defsubst mime-type/subtype-string (type &optional subtype)
156 "Return type/subtype string from TYPE and SUBTYPE."
159 (format "%s/%s" type subtype)
160 (format "%s" type))))
163 ;;; @ Content-Disposition
166 (defsubst mime-content-disposition-type (content-disposition)
167 "Return disposition-type of CONTENT-DISPOSITION."
168 (cdr (car content-disposition)))
170 (defsubst mime-content-disposition-parameters (content-disposition)
171 "Return disposition-parameters of CONTENT-DISPOSITION."
172 (cdr content-disposition))
174 (defsubst mime-content-disposition-parameter (content-disposition parameter)
175 "Return PARAMETER value of CONTENT-DISPOSITION."
176 (cdr (assoc parameter (cdr content-disposition))))
178 (defsubst mime-content-disposition-filename (content-disposition)
179 "Return filename of CONTENT-DISPOSITION."
180 (mime-content-disposition-parameter content-disposition "filename"))
186 (defsubst make-mime-entity-internal (representation-type location
187 &optional content-type
188 children parent node-id
190 header-start header-end
192 (vector representation-type location
193 content-type nil nil children parent node-id
194 buffer header-start header-end body-start body-end
197 (defsubst mime-entity-representation-type-internal (entity)
199 (defsubst mime-entity-set-representation-type-internal (entity type)
200 (aset entity 0 type))
201 (defsubst mime-entity-location-internal (entity)
204 (defsubst mime-entity-content-type-internal (entity)
206 (defsubst mime-entity-set-content-type-internal (entity type)
207 (aset entity 2 type))
208 (defsubst mime-entity-content-disposition-internal (entity)
210 (defsubst mime-entity-set-content-disposition-internal (entity disposition)
211 (aset entity 3 disposition))
212 (defsubst mime-entity-encoding-internal (entity)
214 (defsubst mime-entity-set-encoding-internal (entity encoding)
215 (aset entity 4 encoding))
217 (defsubst mime-entity-children-internal (entity)
219 (defsubst mime-entity-set-children-internal (entity children)
220 (aset entity 5 children))
221 (defsubst mime-entity-parent-internal (entity)
223 (defsubst mime-entity-node-id-internal (entity)
226 (defsubst mime-entity-buffer-internal (entity)
228 (defsubst mime-entity-set-buffer-internal (entity buffer)
229 (aset entity 8 buffer))
230 (defsubst mime-entity-header-start-internal (entity)
232 (defsubst mime-entity-set-header-start-internal (entity point)
233 (aset entity 9 point))
234 (defsubst mime-entity-header-end-internal (entity)
236 (defsubst mime-entity-set-header-end-internal (entity point)
237 (aset entity 10 point))
238 (defsubst mime-entity-body-start-internal (entity)
240 (defsubst mime-entity-set-body-start-internal (entity point)
241 (aset entity 11 point))
242 (defsubst mime-entity-body-end-internal (entity)
244 (defsubst mime-entity-set-body-end-internal (entity point)
245 (aset entity 12 point))
247 (defsubst mime-entity-original-header-internal (entity)
249 (defsubst mime-entity-set-original-header-internal (entity header)
250 (aset entity 13 header))
251 (defsubst mime-entity-parsed-header-internal (entity)
253 (defsubst mime-entity-set-parsed-header-internal (entity header)
254 (aset entity 14 header))
257 ;;; @ message structure
260 (defvar mime-message-structure nil
261 "Information about structure of message.
262 Please use reference function `mime-entity-SLOT' to get value of SLOT.
264 Following is a list of slots of the structure:
266 buffer buffer includes this entity (buffer).
267 node-id node-id (list of integers)
268 header-start minimum point of header in raw-buffer
269 header-end maximum point of header in raw-buffer
270 body-start minimum point of body in raw-buffer
271 body-end maximum point of body in raw-buffer
272 content-type content-type (content-type)
273 content-disposition content-disposition (content-disposition)
274 encoding Content-Transfer-Encoding (string or nil)
275 children entities included in this entity (list of entity)
277 If an entity includes other entities in its body, such as multipart or
278 message/rfc822, `mime-entity' structures of them are included in
279 `children', so the `mime-entity' structure become a tree.")
281 (make-variable-buffer-local 'mime-message-structure)
287 (defvar mime-entity-implementation-alist nil)
289 (defmacro mm-define-backend (type &optional parents)
291 `(let ((rest ',(reverse parents)))
293 (set-alist 'mime-entity-implementation-alist
296 (cdr (assq (car rest)
297 mime-entity-implementation-alist))))
298 (setq rest (cdr rest))
301 (defmacro mm-define-method (name args &rest body)
302 (let* ((specializer (car args))
303 (class (nth 1 specializer))
304 (self (car specializer)))
305 `(let ((imps (cdr (assq ',class mime-entity-implementation-alist)))
306 (func (lambda ,(if self
307 (cons self (cdr args))
311 (set-alist 'mime-entity-implementation-alist
312 ',class (put-alist ',name func imps))
313 (set-alist 'mime-entity-implementation-alist
315 (list (cons ',name func)))
318 (put 'mm-define-method 'lisp-indent-function 'defun)
326 ;;; mime-def.el ends here