1 ;;; mmgeneric.el --- MIME generic entity module
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.
30 (require 'eword-decode) ; mime-find-field-presentation-method
37 (autoload 'mime-entity-content-type "mime")
38 (autoload 'mime-parse-multipart "mime-parse")
39 (autoload 'mime-parse-message "mime-parse")
40 ;; (autoload 'mime-parse-encapsulated "mime-parse")
41 ;; (autoload 'mime-parse-external "mime-parse")
42 (autoload 'mime-entity-content "mime")
45 (luna-define-class mime-entity ()
47 content-type children parent
49 content-disposition encoding
51 original-header parsed-header))
53 (luna-define-internal-accessors 'mime-entity)
56 (defalias 'mime-entity-representation-type-internal 'luna-class-name)
57 (defalias 'mime-entity-set-representation-type-internal 'luna-set-class-name)
59 (luna-define-method mime-entity-fetch-field ((entity mime-entity)
61 (or (symbolp field-name)
62 (setq field-name (intern (capitalize field-name))))
64 (mime-entity-original-header-internal entity))))
66 (luna-define-method mime-insert-text-content ((entity mime-entity))
68 (decode-mime-charset-string (mime-entity-content entity)
69 (or (mime-content-type-parameter
70 (mime-entity-content-type entity)
80 (defmacro mm-expand-class-name (type)
81 `(intern (format "mime-%s-entity" ,type)))
83 (defmacro mm-define-backend (type &optional parents)
84 `(luna-define-class ,(mm-expand-class-name type)
85 ,(nconc (mapcar (lambda (parent)
86 (mm-expand-class-name parent)
91 (defmacro mm-define-method (name args &rest body)
92 (or (eq name 'initialize-instance)
93 (setq name (intern (format "mime-%s" name))))
94 (let ((spec (car args)))
96 (cons (list (car spec)
97 (mm-expand-class-name (nth 1 spec)))
99 `(luna-define-method ,name ,args ,@body)
102 (put 'mm-define-method 'lisp-indent-function 'defun)
104 (def-edebug-spec mm-define-method
105 (&define name ((arg symbolp)
107 [&optional ["&optional" arg &rest arg]]
108 &optional ["&rest" arg]
116 ;; [tomo] We should think about specification of better filtering
117 ;; mechanism. Please discuss in the emacs-mime mailing lists.
119 (defun mime-visible-field-p (field-name visible-fields invisible-fields)
121 (while visible-fields
122 (let ((regexp (car visible-fields)))
123 (if (string-match regexp field-name)
126 (setq visible-fields (cdr visible-fields))
129 (while invisible-fields
130 (let ((regexp (car invisible-fields)))
131 (if (string-match regexp field-name)
134 (setq invisible-fields (cdr invisible-fields))
138 (defun mime-insert-header-from-buffer (buffer start end
139 &optional invisible-fields
141 (let ((the-buf (current-buffer))
142 (mode-obj (mime-find-field-presentation-method 'wide))
144 f-b p f-e field-name len field field-body)
148 (narrow-to-region start end)
150 (while (re-search-forward std11-field-head-regexp nil t)
151 (setq f-b (match-beginning 0)
153 field-name (buffer-substring f-b p)
154 len (string-width field-name)
155 f-e (std11-field-end))
156 (when (mime-visible-field-p field-name
157 visible-fields invisible-fields)
159 (capitalize (buffer-substring f-b (1- p))))
160 field-body (buffer-substring p f-e)
161 field-decoder (inline (mime-find-field-decoder-internal
163 (with-current-buffer the-buf
165 (insert (if field-decoder
166 (funcall field-decoder field-body len)
178 ;;; mmgeneric.el ends here