1 ;;; mime-def.el --- definition module about MIME -*- coding: iso-2022-jp; -*-
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.
35 (require 'luna) ; luna-arglist-to-arguments
39 (defconst mime-library-product ["CLIME" (1 14 0) "
\e$B8^4VF2
\e(B"]
40 "Product name, version number and code name of MIME-library package."))
42 (defmacro mime-product-name (product)
43 (` (aref (, product) 0)))
45 (defmacro mime-product-version (product)
46 (` (aref (, product) 1)))
48 (defmacro mime-product-code-name (product)
49 (` (aref (, product) 2)))
51 (defconst mime-library-version
53 (concat (mime-product-name mime-library-product) " "
54 (mapconcat (function int-to-string)
55 (mime-product-version mime-library-product) ".")
56 " - \"" (mime-product-code-name mime-library-product) "\"")))
62 (defgroup mime '((default-mime-charset custom-variable))
63 "Emacs MIME Interfaces"
67 (defcustom mime-uuencode-encoding-name-list '("x-uue" "x-uuencode")
68 "*List of encoding names for uuencode format."
70 :type '(repeat string))
73 ;;; @@ for encoded-word
76 (defgroup mime-header nil
77 "Header representation, specially encoded-word"
83 (defcustom mime-field-decoding-max-size 1000
84 "*Max size to decode header field."
86 :type '(choice (integer :tag "Limit (bytes)")
87 (const :tag "Don't limit" nil)))
92 (defcustom mime-field-encoding-method-alist
93 '(("X-Nsubject" . iso-2022-jp-2)
98 "*Alist to specify field encoding method.
99 Its key is field-name, value is encoding method.
101 If method is `mime', this field will be encoded into MIME format.
103 If method is a MIME-charset, this field will be encoded as the charset
104 when it must be convert into network-code.
106 If method is `default-mime-charset', this field will be encoded as
107 variable `default-mime-charset' when it must be convert into
110 If method is nil, this field will not be encoded."
112 :type '(repeat (cons (choice :tag "Field"
114 (const :tag "Default" t))
115 (choice :tag "Method"
116 (const :tag "MIME conversion" mime)
117 (symbol :tag "non-MIME conversion")
118 (const :tag "no-conversion" nil)))))
121 ;;; @ required functions
124 (defsubst regexp-* (regexp)
127 (defsubst regexp-or (&rest args)
128 (concat "\\(" (mapconcat (function identity) args "\\|") "\\)"))
135 (defconst std11-quoted-pair-regexp "\\\\.")
136 (defconst std11-non-qtext-char-list '(?\" ?\\ ?\r ?\n))
137 (defconst std11-qtext-regexp
139 (concat "[^" std11-non-qtext-char-list "]"))))
140 (defconst std11-quoted-string-regexp
144 (regexp-or std11-qtext-regexp std11-quoted-pair-regexp))
152 (defconst mime-tspecial-char-list
153 '(?\] ?\[ ?\( ?\) ?< ?> ?@ ?, ?\; ?: ?\\ ?\" ?/ ?? ?=)))
154 (defconst mime-token-regexp
156 (concat "[^" mime-tspecial-char-list "\000-\040]+")))
157 (defconst mime-charset-regexp mime-token-regexp)
159 (defconst mime-media-type/subtype-regexp
160 (concat mime-token-regexp "/" mime-token-regexp))
166 (defconst base64-token-regexp "[A-Za-z0-9+/]")
167 (defconst base64-token-padding-regexp "[A-Za-z0-9+/=]")
169 (defconst B-encoded-text-regexp
178 base64-token-padding-regexp
179 base64-token-padding-regexp
182 ;; (defconst eword-B-encoding-and-encoded-text-regexp
183 ;; (concat "\\(B\\)\\?" eword-B-encoded-text-regexp))
186 ;;; @@ Quoted-Printable / Q
189 (defconst quoted-printable-hex-chars "0123456789ABCDEF")
191 (defconst quoted-printable-octet-regexp
192 (concat "=[" quoted-printable-hex-chars
193 "][" quoted-printable-hex-chars "]"))
195 (defconst Q-encoded-text-regexp
196 (concat "\\([^=?]\\|" quoted-printable-octet-regexp "\\)+"))
198 ;; (defconst eword-Q-encoding-and-encoded-text-regexp
199 ;; (concat "\\(Q\\)\\?" eword-Q-encoded-text-regexp))
205 (defsubst make-mime-content-type (type subtype &optional parameters)
206 (cons (cons 'type type)
207 (cons (cons 'subtype subtype)
208 (nreverse parameters))))
210 (defsubst mime-content-type-primary-type (content-type)
211 "Return primary-type of CONTENT-TYPE."
212 (cdr (car content-type)))
214 (defsubst mime-content-type-subtype (content-type)
215 "Return primary-type of CONTENT-TYPE."
216 (cdr (cadr content-type)))
218 (defsubst mime-content-type-parameters (content-type)
219 "Return primary-type of CONTENT-TYPE."
222 (defsubst mime-content-type-parameter (content-type parameter)
223 "Return PARAMETER value of CONTENT-TYPE."
224 (cdr (assoc parameter (mime-content-type-parameters content-type))))
227 (defsubst mime-type/subtype-string (type &optional subtype)
228 "Return type/subtype string from TYPE and SUBTYPE."
231 (format "%s/%s" type subtype)
232 (format "%s" type))))
235 ;;; @ Content-Disposition
238 (defsubst mime-content-disposition-type (content-disposition)
239 "Return disposition-type of CONTENT-DISPOSITION."
240 (cdr (car content-disposition)))
242 (defsubst mime-content-disposition-parameters (content-disposition)
243 "Return disposition-parameters of CONTENT-DISPOSITION."
244 (cdr content-disposition))
246 (defsubst mime-content-disposition-parameter (content-disposition parameter)
247 "Return PARAMETER value of CONTENT-DISPOSITION."
248 (cdr (assoc parameter (cdr content-disposition))))
250 (defsubst mime-content-disposition-filename (content-disposition)
251 "Return filename of CONTENT-DISPOSITION."
252 (mime-content-disposition-parameter content-disposition "filename"))
255 ;;; @ message structure
258 (defvar mime-message-structure nil
259 "Information about structure of message.
260 Please use reference function `mime-entity-SLOT' to get value of SLOT.
262 Following is a list of slots of the structure:
264 node-id node-id (list of integers)
265 content-type content-type (content-type)
266 content-disposition content-disposition (content-disposition)
267 encoding Content-Transfer-Encoding (string or nil)
268 children entities included in this entity (list of entity)
270 If an entity includes other entities in its body, such as multipart or
271 message/rfc822, `mime-entity' structures of them are included in
272 `children', so the `mime-entity' structure become a tree.")
274 (make-variable-buffer-local 'mime-message-structure)
276 (make-obsolete-variable 'mime-message-structure "should not use it.")
279 ;;; @ for mel-backend
282 (defvar mel-service-list nil)
284 (defmacro mel-define-service (name &optional args &rest rest)
285 "Define NAME as a service for Content-Transfer-Encodings.
286 If ARGS is specified, NAME is defined as a generic function for the
289 (add-to-list 'mel-service-list '(, name))
290 (defvar (, (intern (format "%s-obarray" name))) (make-vector 7 0))
292 (` ((defun (, name) (, args)
294 (funcall (mel-find-function '(, name)
295 (, (car (last args))))
296 (,@ (luna-arglist-to-arguments
297 (butlast args))))))))))))
299 (put 'mel-define-service 'lisp-indent-function 'defun)
302 (defvar mel-encoding-module-alist nil)
304 (defsubst mel-find-function-from-obarray (ob-array encoding)
305 (let* ((f (intern-soft encoding ob-array)))
307 (let ((rest (cdr (assoc encoding mel-encoding-module-alist))))
311 (null (setq f (intern-soft encoding ob-array)))))
312 (setq rest (cdr rest)))
315 (defsubst mel-copy-method (service src-backend dst-backend)
316 (let* ((oa (symbol-value (intern (format "%s-obarray" service))))
317 (f (mel-find-function-from-obarray oa src-backend))
320 (setq sym (intern dst-backend oa))
322 (fset sym (symbol-function f))))))
324 (defsubst mel-copy-backend (src-backend dst-backend)
325 (let ((services mel-service-list))
327 (mel-copy-method (car services) src-backend dst-backend)
328 (setq services (cdr services)))))
330 (defmacro mel-define-backend (type &optional parents)
331 "Define TYPE as a mel-backend.
332 If PARENTS is specified, TYPE inherits PARENTS.
333 Each parent must be backend name (string)."
337 (` (mel-copy-backend (, parent) (, type)))))
340 (defmacro mel-define-method (name args &rest body)
341 "Define NAME as a method function of (nth 1 (car (last ARGS))) backend.
342 ARGS is like an argument list of lambda, but (car (last ARGS)) must be
343 specialized parameter. (car (car (last ARGS))) is name of variable
344 and (nth 1 (car (last ARGS))) is name of backend (encoding)."
345 (let* ((specializer (car (last args)))
346 (class (nth 1 specializer)))
348 (mel-define-service (, name))
349 (fset (intern (, class) (, (intern (format "%s-obarray" name))))
351 (lambda (, (butlast args))
354 (put 'mel-define-method 'lisp-indent-function 'defun)
356 (defmacro mel-define-method-function (spec function)
357 "Set SPEC's function definition to FUNCTION.
358 First element of SPEC is service.
359 Rest of ARGS is like an argument list of lambda, but (car (last ARGS))
360 must be specialized parameter. (car (car (last ARGS))) is name of
361 variable and (nth 1 (car (last ARGS))) is name of backend (encoding)."
362 (let* ((name (car spec))
364 (specializer (car (last args)))
365 (class (nth 1 specializer)))
367 (mel-define-service (, name))
368 (setq sym (intern (, class) (, (intern (format "%s-obarray" name)))))
370 (fset sym (symbol-function (, function))))))))
372 (defmacro mel-define-function (function spec)
373 (let* ((name (car spec))
375 (specializer (car (last args)))
376 (class (nth 1 specializer)))
378 (define-function (, function)
379 (intern (, class) (, (intern (format "%s-obarray" name)))))))))
381 (defvar base64-dl-module
382 (if (and (fboundp 'base64-encode-string)
383 (subrp (symbol-function 'base64-encode-string)))
385 (if (fboundp 'dynamic-link)
386 (let ((path (expand-file-name "base64.so" exec-directory)))
387 (and (file-exists-p path)
396 ;;; mime-def.el ends here