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 (eval-when-compile (require 'static))
82 (static-if (and (featurep 'xemacs)
83 (not (featurep 'utf-2000)))
86 (defalias 'binary-insert-file-contents 'insert-file-contents-as-binary)
87 (defalias 'binary-write-region 'write-region-as-binary))
88 (defalias 'binary-insert-file-contents 'insert-file-contents-literally)
89 (defun binary-write-region (start end filename
90 &optional append visit lockname)
91 "Like `write-region', q.v., but don't encode."
92 (let ((coding-system-for-write 'binary)
93 jka-compr-compression-info-list jam-zcat-filename-list)
94 (write-region start end filename append visit lockname)))
97 (or (fboundp 'char-int)
98 (defalias 'char-int 'identity))
105 (defconst std11-quoted-pair-regexp "\\\\.")
106 (defconst std11-non-qtext-char-list '(?\" ?\\ ?\r ?\n))
107 (defconst std11-qtext-regexp
109 (concat "[^" std11-non-qtext-char-list "]"))))
110 (defconst std11-quoted-string-regexp
114 (regexp-or std11-qtext-regexp std11-quoted-pair-regexp))
122 (defconst mime-tspecial-char-list
123 '(?\] ?\[ ?\( ?\) ?< ?> ?@ ?, ?\; ?: ?\\ ?\" ?/ ?? ?=)))
124 (defconst mime-token-regexp
126 (concat "[^" mime-tspecial-char-list "\000-\040]+")))
127 (defconst mime-charset-regexp mime-token-regexp)
129 (defconst mime-media-type/subtype-regexp
130 (concat mime-token-regexp "/" mime-token-regexp))
136 (defconst base64-token-regexp "[A-Za-z0-9+/]")
137 (defconst base64-token-padding-regexp "[A-Za-z0-9+/=]")
139 (defconst B-encoded-text-regexp
148 base64-token-padding-regexp
149 base64-token-padding-regexp
152 ;; (defconst eword-B-encoding-and-encoded-text-regexp
153 ;; (concat "\\(B\\)\\?" eword-B-encoded-text-regexp))
156 ;;; @@ Quoted-Printable / Q
159 (defconst quoted-printable-hex-chars "0123456789ABCDEF")
161 (defconst quoted-printable-octet-regexp
162 (concat "=[" quoted-printable-hex-chars
163 "][" quoted-printable-hex-chars "]"))
165 (defconst Q-encoded-text-regexp
166 (concat "\\([^=?]\\|" quoted-printable-octet-regexp "\\)+"))
168 ;; (defconst eword-Q-encoding-and-encoded-text-regexp
169 ;; (concat "\\(Q\\)\\?" eword-Q-encoded-text-regexp))
175 (defsubst make-mime-content-type (type subtype &optional parameters)
176 (list* (cons 'type type)
177 (cons 'subtype subtype)
178 (nreverse parameters))
181 (defsubst mime-content-type-primary-type (content-type)
182 "Return primary-type of CONTENT-TYPE."
183 (cdr (car content-type)))
185 (defsubst mime-content-type-subtype (content-type)
186 "Return primary-type of CONTENT-TYPE."
187 (cdr (cadr content-type)))
189 (defsubst mime-content-type-parameters (content-type)
190 "Return primary-type of CONTENT-TYPE."
193 (defsubst mime-content-type-parameter (content-type parameter)
194 "Return PARAMETER value of CONTENT-TYPE."
195 (cdr (assoc parameter (mime-content-type-parameters content-type))))
198 (defsubst mime-type/subtype-string (type &optional subtype)
199 "Return type/subtype string from TYPE and SUBTYPE."
202 (format "%s/%s" type subtype)
203 (format "%s" type))))
206 ;;; @ Content-Disposition
209 (defsubst mime-content-disposition-type (content-disposition)
210 "Return disposition-type of CONTENT-DISPOSITION."
211 (cdr (car content-disposition)))
213 (defsubst mime-content-disposition-parameters (content-disposition)
214 "Return disposition-parameters of CONTENT-DISPOSITION."
215 (cdr content-disposition))
217 (defsubst mime-content-disposition-parameter (content-disposition parameter)
218 "Return PARAMETER value of CONTENT-DISPOSITION."
219 (cdr (assoc parameter (cdr content-disposition))))
221 (defsubst mime-content-disposition-filename (content-disposition)
222 "Return filename of CONTENT-DISPOSITION."
223 (mime-content-disposition-parameter content-disposition "filename"))
226 ;;; @ message structure
229 (defvar mime-message-structure nil
230 "Information about structure of message.
231 Please use reference function `mime-entity-SLOT' to get value of SLOT.
233 Following is a list of slots of the structure:
235 node-id node-id (list of integers)
236 content-type content-type (content-type)
237 content-disposition content-disposition (content-disposition)
238 encoding Content-Transfer-Encoding (string or nil)
239 children entities included in this entity (list of entity)
241 If an entity includes other entities in its body, such as multipart or
242 message/rfc822, `mime-entity' structures of them are included in
243 `children', so the `mime-entity' structure become a tree.")
245 (make-variable-buffer-local 'mime-message-structure)
247 (make-obsolete-variable 'mime-message-structure "should not use it.")
250 ;;; @ for mel-backend
253 (defvar mel-service-list nil)
255 (defmacro mel-define-service (name &optional args &rest rest)
256 "Define NAME as a service for Content-Transfer-Encodings.
257 If ARGS is specified, NAME is defined as a generic function for the
260 (add-to-list 'mel-service-list ',name)
261 (defvar ,(intern (format "%s-obarray" name)) (make-vector 7 0))
265 (funcall (mel-find-function ',name ,(car (last args)))
266 ,@(luna-arglist-to-arguments (butlast args)))
270 (put 'mel-define-service 'lisp-indent-function 'defun)
273 (defvar mel-encoding-module-alist nil)
275 (defsubst mel-find-function-from-obarray (ob-array encoding)
276 (let* ((f (intern-soft encoding ob-array)))
278 (let ((rest (cdr (assoc encoding mel-encoding-module-alist))))
282 (null (setq f (intern-soft encoding ob-array)))
284 (setq rest (cdr rest))
288 (defsubst mel-copy-method (service src-backend dst-backend)
289 (let* ((oa (symbol-value (intern (format "%s-obarray" service))))
290 (f (mel-find-function-from-obarray oa src-backend))
293 (setq sym (intern dst-backend oa))
295 (fset sym (symbol-function f))
298 (defsubst mel-copy-backend (src-backend dst-backend)
299 (let ((services mel-service-list))
301 (mel-copy-method (car services) src-backend dst-backend)
302 (setq services (cdr services)))))
304 (defmacro mel-define-backend (type &optional parents)
305 "Define TYPE as a mel-backend.
306 If PARENTS is specified, TYPE inherits PARENTS.
307 Each parent must be backend name (string)."
309 (mapcar (lambda (parent)
310 `(mel-copy-backend ,parent ,type)
314 (defmacro mel-define-method (name args &rest body)
315 "Define NAME as a method function of (nth 1 (car (last ARGS))) backend.
316 ARGS is like an argument list of lambda, but (car (last ARGS)) must be
317 specialized parameter. (car (car (last ARGS))) is name of variable
318 and (nth 1 (car (last ARGS))) is name of backend (encoding)."
319 (let* ((specializer (car (last args)))
320 (class (nth 1 specializer)))
322 (mel-define-service ,name)
323 (fset (intern ,class ,(intern (format "%s-obarray" name)))
324 (lambda ,(butlast args)
327 (put 'mel-define-method 'lisp-indent-function 'defun)
329 (defmacro mel-define-method-function (spec function)
330 "Set SPEC's function definition to FUNCTION.
331 First element of SPEC is service.
332 Rest of ARGS is like an argument list of lambda, but (car (last ARGS))
333 must be specialized parameter. (car (car (last ARGS))) is name of
334 variable and (nth 1 (car (last ARGS))) is name of backend (encoding)."
335 (let* ((name (car spec))
337 (specializer (car (last args)))
338 (class (nth 1 specializer)))
340 (mel-define-service ,name)
341 (setq sym (intern ,class ,(intern (format "%s-obarray" name))))
343 (fset sym (symbol-function ,function))))))
345 (defmacro mel-define-function (function spec)
346 (let* ((name (car spec))
348 (specializer (car (last args)))
349 (class (nth 1 specializer)))
351 (define-function ,function
352 (intern ,class ,(intern (format "%s-obarray" name))))
355 (defvar base64-dl-module
356 (if (and (fboundp 'base64-encode-string)
357 (subrp (symbol-function 'base64-encode-string)))
359 (if (fboundp 'dynamic-link)
360 (let ((path (expand-file-name "base64.so" exec-directory)))
361 (and (file-exists-p path)
371 ;;; mime-def.el ends here