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.
34 (require 'luna) ; luna-arglist-to-arguments
38 (defconst mime-library-product ["FLIM" (1 14 0) "Ninokuchi"]
39 "Product name, version number and code name of MIME-library package."))
41 (defmacro mime-product-name (product)
44 (defmacro mime-product-version (product)
47 (defmacro mime-product-code-name (product)
50 (defconst mime-library-version
52 (concat (mime-product-name mime-library-product) " "
53 (mapconcat #'number-to-string
54 (mime-product-version mime-library-product) ".")
55 " - \"" (mime-product-code-name mime-library-product) "\"")))
61 (defgroup mime '((default-mime-charset custom-variable))
62 "Emacs MIME Interfaces"
66 (defcustom mime-uuencode-encoding-name-list '("x-uue" "x-uuencode")
67 "*List of encoding names for uuencode format."
69 :type '(repeat string))
72 ;;; @ required functions
75 (defsubst regexp-* (regexp)
78 (defsubst regexp-or (&rest args)
79 (concat "\\(" (mapconcat (function identity) args "\\|") "\\)"))
81 (eval-when-compile (require 'static))
83 (static-if (and (featurep 'xemacs)
84 (not (featurep 'utf-2000)))
87 (defalias 'binary-insert-file-contents 'insert-file-contents-as-binary)
88 (defalias 'binary-write-region 'write-region-as-binary))
89 (defalias 'binary-insert-file-contents 'insert-file-contents-literally)
90 (defun binary-write-region (start end filename
91 &optional append visit lockname)
92 "Like `write-region', q.v., but don't encode."
93 (let ((coding-system-for-write 'binary)
94 jka-compr-compression-info-list jam-zcat-filename-list)
95 (write-region start end filename append visit lockname)))
103 (defconst std11-quoted-pair-regexp "\\\\.")
104 (defconst std11-non-qtext-char-list '(?\" ?\\ ?\r ?\n))
105 (defconst std11-qtext-regexp
107 (concat "[^" std11-non-qtext-char-list "]"))))
108 (defconst std11-quoted-string-regexp
112 (regexp-or std11-qtext-regexp std11-quoted-pair-regexp))
120 (defconst mime-tspecial-char-list
121 '(?\] ?\[ ?\( ?\) ?< ?> ?@ ?, ?\; ?: ?\\ ?\" ?/ ?? ?=)))
122 (defconst mime-token-regexp
124 (concat "[^" mime-tspecial-char-list "\000-\040]+")))
125 (defconst mime-charset-regexp mime-token-regexp)
127 (defconst mime-media-type/subtype-regexp
128 (concat mime-token-regexp "/" mime-token-regexp))
134 (defconst base64-token-regexp "[A-Za-z0-9+/]")
135 (defconst base64-token-padding-regexp "[A-Za-z0-9+/=]")
137 (defconst B-encoded-text-regexp
146 base64-token-padding-regexp
147 base64-token-padding-regexp
150 ;; (defconst eword-B-encoding-and-encoded-text-regexp
151 ;; (concat "\\(B\\)\\?" eword-B-encoded-text-regexp))
154 ;;; @@ Quoted-Printable / Q
157 (defconst quoted-printable-hex-chars "0123456789ABCDEF")
159 (defconst quoted-printable-octet-regexp
160 (concat "=[" quoted-printable-hex-chars
161 "][" quoted-printable-hex-chars "]"))
163 (defconst Q-encoded-text-regexp
164 (concat "\\([^=?]\\|" quoted-printable-octet-regexp "\\)+"))
166 ;; (defconst eword-Q-encoding-and-encoded-text-regexp
167 ;; (concat "\\(Q\\)\\?" eword-Q-encoded-text-regexp))
173 (defsubst make-mime-content-type (type subtype &optional parameters)
174 (list* (cons 'type type)
175 (cons 'subtype subtype)
176 (nreverse parameters))
179 (defsubst mime-content-type-primary-type (content-type)
180 "Return primary-type of CONTENT-TYPE."
181 (cdr (car content-type)))
183 (defsubst mime-content-type-subtype (content-type)
184 "Return primary-type of CONTENT-TYPE."
185 (cdr (cadr content-type)))
187 (defsubst mime-content-type-parameters (content-type)
188 "Return primary-type of CONTENT-TYPE."
191 (defsubst mime-content-type-parameter (content-type parameter)
192 "Return PARAMETER value of CONTENT-TYPE."
193 (cdr (assoc parameter (mime-content-type-parameters content-type))))
196 (defsubst mime-type/subtype-string (type &optional subtype)
197 "Return type/subtype string from TYPE and SUBTYPE."
200 (format "%s/%s" type subtype)
201 (format "%s" type))))
204 ;;; @ Content-Disposition
207 (defsubst mime-content-disposition-type (content-disposition)
208 "Return disposition-type of CONTENT-DISPOSITION."
209 (cdr (car content-disposition)))
211 (defsubst mime-content-disposition-parameters (content-disposition)
212 "Return disposition-parameters of CONTENT-DISPOSITION."
213 (cdr content-disposition))
215 (defsubst mime-content-disposition-parameter (content-disposition parameter)
216 "Return PARAMETER value of CONTENT-DISPOSITION."
217 (cdr (assoc parameter (cdr content-disposition))))
219 (defsubst mime-content-disposition-filename (content-disposition)
220 "Return filename of CONTENT-DISPOSITION."
221 (mime-content-disposition-parameter content-disposition "filename"))
224 ;;; @ message structure
227 (defvar mime-message-structure nil
228 "Information about structure of message.
229 Please use reference function `mime-entity-SLOT' to get value of SLOT.
231 Following is a list of slots of the structure:
233 node-id node-id (list of integers)
234 content-type content-type (content-type)
235 content-disposition content-disposition (content-disposition)
236 encoding Content-Transfer-Encoding (string or nil)
237 children entities included in this entity (list of entity)
239 If an entity includes other entities in its body, such as multipart or
240 message/rfc822, `mime-entity' structures of them are included in
241 `children', so the `mime-entity' structure become a tree.")
243 (make-variable-buffer-local 'mime-message-structure)
245 (make-obsolete-variable 'mime-message-structure "should not use it.")
248 ;;; @ for mel-backend
251 (defvar mel-service-list nil)
253 (defmacro mel-define-service (name &optional args &rest rest)
254 "Define NAME as a service for Content-Transfer-Encodings.
255 If ARGS is specified, NAME is defined as a generic function for the
258 (add-to-list 'mel-service-list ',name)
259 (defvar ,(intern (format "%s-obarray" name)) (make-vector 7 0))
263 (funcall (mel-find-function ',name ,(car (last args)))
264 ,@(luna-arglist-to-arguments (butlast args)))
268 (put 'mel-define-service 'lisp-indent-function 'defun)
271 (defvar mel-encoding-module-alist nil)
273 (defsubst mel-find-function-from-obarray (ob-array encoding)
274 (let* ((f (intern-soft encoding ob-array)))
276 (let ((rest (cdr (assoc encoding mel-encoding-module-alist))))
280 (null (setq f (intern-soft encoding ob-array)))
282 (setq rest (cdr rest))
286 (defsubst mel-copy-method (service src-backend dst-backend)
287 (let* ((oa (symbol-value (intern (format "%s-obarray" service))))
288 (f (mel-find-function-from-obarray oa src-backend))
291 (setq sym (intern dst-backend oa))
293 (fset sym (symbol-function f))
296 (defsubst mel-copy-backend (src-backend dst-backend)
297 (let ((services mel-service-list))
299 (mel-copy-method (car services) src-backend dst-backend)
300 (setq services (cdr services)))))
302 (defmacro mel-define-backend (type &optional parents)
303 "Define TYPE as a mel-backend.
304 If PARENTS is specified, TYPE inherits PARENTS.
305 Each parent must be backend name (string)."
307 (mapcar (lambda (parent)
308 `(mel-copy-backend ,parent ,type)
312 (defmacro mel-define-method (name args &rest body)
313 "Define NAME as a method function of (nth 1 (car (last ARGS))) backend.
314 ARGS is like an argument list of lambda, but (car (last ARGS)) must be
315 specialized parameter. (car (car (last ARGS))) is name of variable
316 and (nth 1 (car (last ARGS))) is name of backend (encoding)."
317 (let* ((specializer (car (last args)))
318 (class (nth 1 specializer)))
320 (mel-define-service ,name)
321 (fset (intern ,class ,(intern (format "%s-obarray" name)))
322 (lambda ,(butlast args)
325 (put 'mel-define-method 'lisp-indent-function 'defun)
327 (defmacro mel-define-method-function (spec function)
328 "Set SPEC's function definition to FUNCTION.
329 First element of SPEC is service.
330 Rest of ARGS is like an argument list of lambda, but (car (last ARGS))
331 must be specialized parameter. (car (car (last ARGS))) is name of
332 variable and (nth 1 (car (last ARGS))) is name of backend (encoding)."
333 (let* ((name (car spec))
335 (specializer (car (last args)))
336 (class (nth 1 specializer)))
338 (mel-define-service ,name)
339 (setq sym (intern ,class ,(intern (format "%s-obarray" name))))
341 (fset sym (symbol-function ,function))))))
343 (defmacro mel-define-function (function spec)
344 (let* ((name (car spec))
346 (specializer (car (last args)))
347 (class (nth 1 specializer)))
349 (define-function ,function
350 (intern ,class ,(intern (format "%s-obarray" name))))
353 (defvar base64-dl-module
354 (if (and (fboundp 'base64-encode-string)
355 (subrp (symbol-function 'base64-encode-string)))
357 (if (fboundp 'dynamic-link)
358 (let ((path (expand-file-name "base64.so" exec-directory)))
359 (and (file-exists-p path)
369 ;;; mime-def.el ends here