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., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, 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")
44 (luna-define-class mime-entity ()
46 content-type children parent
48 content-disposition encoding
50 original-header parsed-header))
52 (defalias 'mime-entity-representation-type-internal 'luna-class-name)
53 (defalias 'mime-entity-set-representation-type-internal 'luna-set-class-name)
55 (luna-define-internal-accessors 'mime-entity)
57 (luna-define-method mime-entity-fetch-field ((entity mime-entity)
59 (or (symbolp field-name)
60 (setq field-name (intern (capitalize field-name))))
62 (mime-entity-original-header-internal entity))))
64 ;; unlimited patch by simm-emacs@fan.gr.jp
65 ;; Tue, 01 Feb 2000 13:32:14 +0900
66 (luna-define-method mime-insert-text-content ((entity mime-entity))
68 (decode-mime-charset-string-unlimited
69 (mime-entity-content entity)
70 (or (mime-content-type-parameter
71 (mime-entity-content-type entity)
73 default-mime-charset-unlimited
81 (defmacro mm-expand-class-name (type)
82 `(intern (format "mime-%s-entity" ,type)))
84 (defmacro mm-define-backend (type &optional parents)
85 `(luna-define-class ,(mm-expand-class-name type)
86 ,(nconc (mapcar (lambda (parent)
87 (mm-expand-class-name parent)
92 (defmacro mm-define-method (name args &rest body)
93 (or (eq name 'initialize-instance)
94 (setq name (intern (format "mime-%s" name))))
95 (let ((spec (car args)))
97 (cons (list (car spec)
98 (mm-expand-class-name (nth 1 spec)))
100 `(luna-define-method ,name ,args ,@body)
103 (put 'mm-define-method 'lisp-indent-function 'defun)
105 (def-edebug-spec mm-define-method
106 (&define name ((arg symbolp)
108 [&optional ["&optional" arg &rest arg]]
109 &optional ["&rest" arg]
117 ;; [tomo] We should think about specification of better filtering
118 ;; mechanism. Please discuss in the emacs-mime mailing lists.
120 (defun mime-visible-field-p (field-name visible-fields invisible-fields)
122 (while visible-fields
123 (let ((regexp (car visible-fields)))
124 (if (string-match regexp field-name)
127 (setq visible-fields (cdr visible-fields))
130 (while invisible-fields
131 (let ((regexp (car invisible-fields)))
132 (if (string-match regexp field-name)
135 (setq invisible-fields (cdr invisible-fields))
139 (defun mime-insert-header-from-buffer (buffer start end
140 &optional invisible-fields
142 (let ((the-buf (current-buffer))
143 (mode-obj (mime-find-field-presentation-method 'wide))
145 f-b p f-e field-name len field field-body)
149 (narrow-to-region start end)
151 (while (re-search-forward std11-field-head-regexp nil t)
152 (setq f-b (match-beginning 0)
154 field-name (buffer-substring f-b p)
155 len (string-width field-name)
156 f-e (std11-field-end))
157 (when (mime-visible-field-p field-name
158 visible-fields invisible-fields)
160 (capitalize (buffer-substring f-b (1- p))))
161 field-body (buffer-substring p f-e)
162 field-decoder (inline (mime-find-field-decoder-internal
164 (with-current-buffer the-buf
166 (insert (if field-decoder
167 (funcall field-decoder field-body len)
179 ;;; mmgeneric.el ends here