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 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.
33 (require 'luna) ; luna-arglist-to-arguments
37 (defconst mime-library-product ["FLIM" (1 14 0) "Ninokuchi"]
38 "Product name, version number and code name of MIME-library package."))
40 (defmacro mime-product-name (product)
43 (defmacro mime-product-version (product)
46 (defmacro mime-product-code-name (product)
49 (defconst mime-library-version
51 (concat (mime-product-name mime-library-product) " "
52 (mapconcat #'number-to-string
53 (mime-product-version mime-library-product) ".")
54 " - \"" (mime-product-code-name mime-library-product) "\"")))
60 (defgroup mime '((default-mime-charset custom-variable))
61 "Emacs MIME Interfaces"
65 (defcustom mime-uuencode-encoding-name-list '("x-uue" "x-uuencode")
66 "*List of encoding names for uuencode format."
68 :type '(repeat string))
71 ;;; @ required functions
74 (defsubst regexp-* (regexp)
77 (defsubst regexp-or (&rest args)
78 (concat "\\(" (mapconcat (function identity) args "\\|") "\\)"))
80 (or (fboundp 'char-int)
81 (defalias 'char-int 'identity))
88 (defconst std11-quoted-pair-regexp "\\\\.")
89 (defconst std11-non-qtext-char-list '(?\" ?\\ ?\r ?\n))
90 (defconst std11-qtext-regexp
92 (concat "[^" std11-non-qtext-char-list "]"))))
93 (defconst std11-quoted-string-regexp
97 (regexp-or std11-qtext-regexp std11-quoted-pair-regexp))
105 (defconst mime-tspecial-char-list
106 '(?\] ?\[ ?\( ?\) ?< ?> ?@ ?, ?\; ?: ?\\ ?\" ?/ ?? ?=)))
107 (defconst mime-token-regexp
109 (concat "[^" mime-tspecial-char-list "\000-\040]+")))
110 (defconst mime-charset-regexp mime-token-regexp)
112 (defconst mime-media-type/subtype-regexp
113 (concat mime-token-regexp "/" mime-token-regexp))
119 (defconst base64-token-regexp "[A-Za-z0-9+/]")
120 (defconst base64-token-padding-regexp "[A-Za-z0-9+/=]")
122 (defconst B-encoded-text-regexp
131 base64-token-padding-regexp
132 base64-token-padding-regexp
135 ;; (defconst eword-B-encoding-and-encoded-text-regexp
136 ;; (concat "\\(B\\)\\?" eword-B-encoded-text-regexp))
139 ;;; @@ Quoted-Printable / Q
142 (defconst quoted-printable-hex-chars "0123456789ABCDEF")
144 (defconst quoted-printable-octet-regexp
145 (concat "=[" quoted-printable-hex-chars
146 "][" quoted-printable-hex-chars "]"))
148 (defconst Q-encoded-text-regexp
149 (concat "\\([^=?]\\|" quoted-printable-octet-regexp "\\)+"))
151 ;; (defconst eword-Q-encoding-and-encoded-text-regexp
152 ;; (concat "\\(Q\\)\\?" eword-Q-encoded-text-regexp))
158 (defsubst make-mime-content-type (type subtype &optional parameters)
159 (list* (cons 'type type)
160 (cons 'subtype subtype)
161 (nreverse parameters))
164 (defsubst mime-content-type-primary-type (content-type)
165 "Return primary-type of CONTENT-TYPE."
166 (cdr (car content-type)))
168 (defsubst mime-content-type-subtype (content-type)
169 "Return primary-type of CONTENT-TYPE."
170 (cdr (cadr content-type)))
172 (defsubst mime-content-type-parameters (content-type)
173 "Return primary-type of CONTENT-TYPE."
176 (defsubst mime-content-type-parameter (content-type parameter)
177 "Return PARAMETER value of CONTENT-TYPE."
178 (cdr (assoc parameter (mime-content-type-parameters content-type))))
181 (defsubst mime-type/subtype-string (type &optional subtype)
182 "Return type/subtype string from TYPE and SUBTYPE."
185 (format "%s/%s" type subtype)
186 (format "%s" type))))
189 ;;; @ Content-Disposition
192 (defsubst mime-content-disposition-type (content-disposition)
193 "Return disposition-type of CONTENT-DISPOSITION."
194 (cdr (car content-disposition)))
196 (defsubst mime-content-disposition-parameters (content-disposition)
197 "Return disposition-parameters of CONTENT-DISPOSITION."
198 (cdr content-disposition))
200 (defsubst mime-content-disposition-parameter (content-disposition parameter)
201 "Return PARAMETER value of CONTENT-DISPOSITION."
202 (cdr (assoc parameter (cdr content-disposition))))
204 (defsubst mime-content-disposition-filename (content-disposition)
205 "Return filename of CONTENT-DISPOSITION."
206 (mime-content-disposition-parameter content-disposition "filename"))
209 ;;; @ message structure
212 (defvar mime-message-structure nil
213 "Information about structure of message.
214 Please use reference function `mime-entity-SLOT' to get value of SLOT.
216 Following is a list of slots of the structure:
218 node-id node-id (list of integers)
219 content-type content-type (content-type)
220 content-disposition content-disposition (content-disposition)
221 encoding Content-Transfer-Encoding (string or nil)
222 children entities included in this entity (list of entity)
224 If an entity includes other entities in its body, such as multipart or
225 message/rfc822, `mime-entity' structures of them are included in
226 `children', so the `mime-entity' structure become a tree.")
228 (make-variable-buffer-local 'mime-message-structure)
230 (make-obsolete-variable 'mime-message-structure "should not use it.")
233 ;;; @ for mel-backend
236 (defvar mel-service-list nil)
238 (defmacro mel-define-service (name &optional args &rest rest)
239 "Define NAME as a service for Content-Transfer-Encodings.
240 If ARGS is specified, NAME is defined as a generic function for the
243 (add-to-list 'mel-service-list ',name)
244 (defvar ,(intern (format "%s-obarray" name)) (make-vector 7 0))
248 (funcall (mel-find-function ',name ,(car (last args)))
249 ,@(luna-arglist-to-arguments (butlast args)))
253 (put 'mel-define-service 'lisp-indent-function 'defun)
256 (defvar mel-encoding-module-alist nil)
258 (defsubst mel-find-function-from-obarray (ob-array encoding)
259 (let* ((f (intern-soft encoding ob-array)))
261 (let ((rest (cdr (assoc encoding mel-encoding-module-alist))))
265 (null (setq f (intern-soft encoding ob-array)))
267 (setq rest (cdr rest))
271 (defsubst mel-copy-method (service src-backend dst-backend)
272 (let* ((oa (symbol-value (intern (format "%s-obarray" service))))
273 (f (mel-find-function-from-obarray oa src-backend))
276 (setq sym (intern dst-backend oa))
278 (fset sym (symbol-function f))
281 (defsubst mel-copy-backend (src-backend dst-backend)
282 (let ((services mel-service-list))
284 (mel-copy-method (car services) src-backend dst-backend)
285 (setq services (cdr services)))))
287 (defmacro mel-define-backend (type &optional parents)
288 "Define TYPE as a mel-backend.
289 If PARENTS is specified, TYPE inherits PARENTS.
290 Each parent must be backend name (string)."
292 (mapcar (lambda (parent)
293 `(mel-copy-backend ,parent ,type)
297 (defmacro mel-define-method (name args &rest body)
298 "Define NAME as a method function of (nth 1 (car (last ARGS))) backend.
299 ARGS is like an argument list of lambda, but (car (last ARGS)) must be
300 specialized parameter. (car (car (last ARGS))) is name of variable
301 and (nth 1 (car (last ARGS))) is name of backend (encoding)."
302 (let* ((specializer (car (last args)))
303 (class (nth 1 specializer)))
305 (mel-define-service ,name)
306 (fset (intern ,class ,(intern (format "%s-obarray" name)))
307 (lambda ,(butlast args)
310 (put 'mel-define-method 'lisp-indent-function 'defun)
312 (defmacro mel-define-method-function (spec function)
313 "Set SPEC's function definition to FUNCTION.
314 First element of SPEC is service.
315 Rest of ARGS is like an argument list of lambda, but (car (last ARGS))
316 must be specialized parameter. (car (car (last ARGS))) is name of
317 variable and (nth 1 (car (last ARGS))) is name of backend (encoding)."
318 (let* ((name (car spec))
320 (specializer (car (last args)))
321 (class (nth 1 specializer)))
323 (mel-define-service ,name)
324 (setq sym (intern ,class ,(intern (format "%s-obarray" name))))
326 (fset sym (symbol-function ,function))))))
328 (defmacro mel-define-function (function spec)
329 (let* ((name (car spec))
331 (specializer (car (last args)))
332 (class (nth 1 specializer)))
334 (define-function ,function
335 (intern ,class ,(intern (format "%s-obarray" name))))
338 (defvar base64-dl-module
339 (if (and (fboundp 'base64-encode-string)
340 (subrp (symbol-function 'base64-encode-string)))
342 (if (fboundp 'dynamic-link)
343 (let ((path (expand-file-name "base64.so" exec-directory)))
344 (and (file-exists-p path)
354 ;;; mime-def.el ends here