1 ;;; mime-def.el --- definition module about MIME -*- coding: iso-8859-4; -*-
3 ;; Copyright (C) 1995,96,97,98,99,2000 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6 ;; Keywords: definition, MIME, multimedia, mail, news
8 ;; This file is part of DEISUI (Deisui is an Entity Implementation for
9 ;; SEMI based User Interfaces).
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
36 (require 'luna) ; luna-arglist-to-arguments
40 (defconst mime-library-product ["FLIM" (1 14 0) "Ninokuchi"]
41 "Product name, version number and code name of MIME-library package."))
43 (defmacro mime-product-name (product)
46 (defmacro mime-product-version (product)
49 (defmacro mime-product-code-name (product)
52 (defconst mime-library-version
54 (concat (mime-product-name mime-library-product) " "
55 (mapconcat #'number-to-string
56 (mime-product-version mime-library-product) ".")
57 " - \"" (mime-product-code-name mime-library-product) "\"")))
65 (defgroup mime '((default-mime-charset custom-variable))
66 "Emacs MIME Interfaces"
70 (defcustom mime-uuencode-encoding-name-list '("x-uue" "x-uuencode")
71 "*List of encoding names for uuencode format."
73 :type '(repeat string))
76 ;;; @ required functions
79 (defsubst regexp-* (regexp)
82 (defsubst regexp-or (&rest args)
83 (concat "\\(" (mapconcat (function identity) args "\\|") "\\)"))
90 (defconst std11-quoted-pair-regexp "\\\\.")
91 (defconst std11-non-qtext-char-list '(?\" ?\\ ?\r ?\n))
92 (defconst std11-qtext-regexp
94 (concat "[^" std11-non-qtext-char-list "]"))))
95 (defconst std11-quoted-string-regexp
99 (regexp-or std11-qtext-regexp std11-quoted-pair-regexp))
107 (defconst mime-tspecial-char-list
108 '(?\] ?\[ ?\( ?\) ?< ?> ?@ ?, ?\; ?: ?\\ ?\" ?/ ?? ?=)))
109 (defconst mime-token-regexp
111 (concat "[^" mime-tspecial-char-list "\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))
121 (defconst base64-token-regexp "[A-Za-z0-9+/]")
122 (defconst base64-token-padding-regexp "[A-Za-z0-9+/=]")
124 (defconst B-encoded-text-regexp
133 base64-token-padding-regexp
134 base64-token-padding-regexp
137 ;; (defconst eword-B-encoding-and-encoded-text-regexp
138 ;; (concat "\\(B\\)\\?" eword-B-encoded-text-regexp))
141 ;;; @@ Quoted-Printable / Q
144 (defconst quoted-printable-hex-chars "0123456789ABCDEF")
146 (defconst quoted-printable-octet-regexp
147 (concat "=[" quoted-printable-hex-chars
148 "][" quoted-printable-hex-chars "]"))
150 (defconst Q-encoded-text-regexp
151 (concat "\\([^=?]\\|" quoted-printable-octet-regexp "\\)+"))
153 ;; (defconst eword-Q-encoding-and-encoded-text-regexp
154 ;; (concat "\\(Q\\)\\?" eword-Q-encoded-text-regexp))
160 (defsubst make-mime-content-type (type subtype &optional parameters)
161 (list* (cons 'type type)
162 (cons 'subtype subtype)
163 (nreverse parameters))
166 (defsubst mime-content-type-primary-type (content-type)
167 "Return primary-type of CONTENT-TYPE."
168 (cdr (car content-type)))
170 (defsubst mime-content-type-subtype (content-type)
171 "Return primary-type of CONTENT-TYPE."
172 (cdr (cadr content-type)))
174 (defsubst mime-content-type-parameters (content-type)
175 "Return primary-type of CONTENT-TYPE."
178 (defsubst mime-content-type-parameter (content-type parameter)
179 "Return PARAMETER value of CONTENT-TYPE."
180 (cdr (assoc parameter (mime-content-type-parameters content-type))))
183 (defsubst mime-type/subtype-string (type &optional subtype)
184 "Return type/subtype string from TYPE and SUBTYPE."
187 (format "%s/%s" type subtype)
188 (format "%s" type))))
191 ;;; @ Content-Disposition
194 (defsubst mime-content-disposition-type (content-disposition)
195 "Return disposition-type of CONTENT-DISPOSITION."
196 (cdr (car content-disposition)))
198 (defsubst mime-content-disposition-parameters (content-disposition)
199 "Return disposition-parameters of CONTENT-DISPOSITION."
200 (cdr content-disposition))
202 (defsubst mime-content-disposition-parameter (content-disposition parameter)
203 "Return PARAMETER value of CONTENT-DISPOSITION."
204 (cdr (assoc parameter (cdr content-disposition))))
206 (defsubst mime-content-disposition-filename (content-disposition)
207 "Return filename of CONTENT-DISPOSITION."
208 (mime-content-disposition-parameter content-disposition "filename"))
211 ;;; @ message structure
214 (defvar mime-message-structure nil
215 "Information about structure of message.
216 Please use reference function `mime-entity-SLOT' to get value of SLOT.
218 Following is a list of slots of the structure:
220 node-id node-id (list of integers)
221 content-type content-type (content-type)
222 content-disposition content-disposition (content-disposition)
223 encoding Content-Transfer-Encoding (string or nil)
224 children entities included in this entity (list of entity)
226 If an entity includes other entities in its body, such as multipart or
227 message/rfc822, `mime-entity' structures of them are included in
228 `children', so the `mime-entity' structure become a tree.")
230 (make-variable-buffer-local 'mime-message-structure)
232 (make-obsolete-variable 'mime-message-structure "should not use it.")
235 ;;; @ for mel-backend
238 (defvar mel-service-list nil)
240 (defmacro mel-define-service (name &optional args &rest rest)
241 "Define NAME as a service for Content-Transfer-Encodings.
242 If ARGS is specified, NAME is defined as a generic function for the
245 (add-to-list 'mel-service-list ',name)
246 (defvar ,(intern (format "%s-obarray" name)) (make-vector 7 0))
250 (funcall (mel-find-function ',name ,(car (last args)))
251 ,@(luna-arglist-to-arguments (butlast args)))
255 (put 'mel-define-service 'lisp-indent-function 'defun)
258 (defvar mel-encoding-module-alist nil)
260 (defsubst mel-find-function-from-obarray (ob-array encoding)
261 (let* ((f (intern-soft encoding ob-array)))
263 (let ((rest (cdr (assoc encoding mel-encoding-module-alist))))
267 (null (setq f (intern-soft encoding ob-array)))
269 (setq rest (cdr rest))
273 (defsubst mel-copy-method (service src-backend dst-backend)
274 (let* ((oa (symbol-value (intern (format "%s-obarray" service))))
275 (f (mel-find-function-from-obarray oa src-backend))
278 (setq sym (intern dst-backend oa))
280 (fset sym (symbol-function f))
283 (defsubst mel-copy-backend (src-backend dst-backend)
284 (let ((services mel-service-list))
286 (mel-copy-method (car services) src-backend dst-backend)
287 (setq services (cdr services)))))
289 (defmacro mel-define-backend (type &optional parents)
290 "Define TYPE as a mel-backend.
291 If PARENTS is specified, TYPE inherits PARENTS.
292 Each parent must be backend name (string)."
294 (mapcar (lambda (parent)
295 `(mel-copy-backend ,parent ,type)
299 (defmacro mel-define-method (name args &rest body)
300 "Define NAME as a method function of (nth 1 (car (last ARGS))) backend.
301 ARGS is like an argument list of lambda, but (car (last ARGS)) must be
302 specialized parameter. (car (car (last ARGS))) is name of variable
303 and (nth 1 (car (last ARGS))) is name of backend (encoding)."
304 (let* ((specializer (car (last args)))
305 (class (nth 1 specializer)))
307 (mel-define-service ,name)
308 (fset (intern ,class ,(intern (format "%s-obarray" name)))
309 (lambda ,(butlast args)
312 (put 'mel-define-method 'lisp-indent-function 'defun)
314 (defmacro mel-define-method-function (spec function)
315 "Set SPEC's function definition to FUNCTION.
316 First element of SPEC is service.
317 Rest of ARGS is like an argument list of lambda, but (car (last ARGS))
318 must be specialized parameter. (car (car (last ARGS))) is name of
319 variable and (nth 1 (car (last ARGS))) is name of backend (encoding)."
320 (let* ((name (car spec))
322 (specializer (car (last args)))
323 (class (nth 1 specializer)))
325 (mel-define-service ,name)
326 (setq sym (intern ,class ,(intern (format "%s-obarray" name))))
328 (fset sym (symbol-function ,function))))))
330 (defmacro mel-define-function (function spec)
331 (let* ((name (car spec))
333 (specializer (car (last args)))
334 (class (nth 1 specializer)))
336 (define-function ,function
337 (intern ,class ,(intern (format "%s-obarray" name))))
340 (defvar base64-dl-module
341 (if (and (fboundp 'base64-encode-string)
342 (subrp (symbol-function 'base64-encode-string)))
344 (if (fboundp 'dynamic-link)
345 (let ((path (expand-file-name "base64.so" exec-directory)))
346 (and (file-exists-p path)
356 ;;; mime-def.el ends here