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.
33 (autoload 'mime-entity-content-type "mime")
34 (autoload 'mime-parse-multipart "mime-parse")
35 (autoload 'mime-parse-message "mime-parse")
36 ;; (autoload 'mime-parse-encapsulated "mime-parse")
37 ;; (autoload 'mime-parse-external "mime-parse")
38 (autoload 'mime-entity-content "mime")
41 (luna-define-class mime-entity ()
43 content-type children parent
45 content-disposition encoding
47 original-header parsed-header))
48 (luna-define-internal-accessors 'mime-entity))
50 (defalias 'mime-entity-representation-type-internal 'luna-class-name)
51 (defalias 'mime-entity-set-representation-type-internal 'luna-set-class-name)
53 (luna-define-method mime-entity-fetch-field ((entity mime-entity)
55 (or (symbolp field-name)
56 (setq field-name (intern (capitalize (capitalize field-name)))))
58 (mime-entity-original-header-internal entity))))
60 (luna-define-method mime-insert-text-content ((entity mime-entity))
62 (decode-mime-charset-string (mime-entity-content entity)
63 (or (mime-content-type-parameter
64 (mime-entity-content-type entity)
73 (defmacro mm-expand-class-name (type)
74 (` (intern (format "mime-%s-entity" (, type)))))
76 (defmacro mm-define-backend (type &optional parents)
77 (` (luna-define-class (, (mm-expand-class-name type))
78 (, (nconc (mapcar (function
80 (mm-expand-class-name parent)))
84 (defmacro mm-define-method (name args &rest body)
85 (or (eq name 'initialize-instance)
86 (setq name (intern (format "mime-%s" name))))
87 (let ((spec (car args)))
89 (cons (list (car spec)
90 (mm-expand-class-name (nth 1 spec)))
92 (` (luna-define-method (, name) (, args) (,@ body)))))
94 (put 'mm-define-method 'lisp-indent-function 'defun)
96 (def-edebug-spec mm-define-method
97 (&define name ((arg symbolp)
99 [&optional ["&optional" arg &rest arg]]
100 &optional ["&rest" arg])
107 ;; [tomo] We should think about specification of better filtering
108 ;; mechanism. Please discuss in the emacs-mime mailing lists.
110 (defun mime-visible-field-p (field-name visible-fields invisible-fields)
112 (while visible-fields
113 (let ((regexp (car visible-fields)))
114 (if (string-match regexp field-name)
116 (setq visible-fields (cdr visible-fields))))
118 (while invisible-fields
119 (let ((regexp (car invisible-fields)))
120 (if (string-match regexp field-name)
122 (setq invisible-fields (cdr invisible-fields)))
125 (defun mime-insert-header-from-buffer (buffer start end
126 &optional invisible-fields
128 (let ((the-buf (current-buffer))
129 (mode-obj (mime-find-field-presentation-method 'wide))
131 f-b p f-e field-name len field field-body)
135 (narrow-to-region start end)
137 (while (re-search-forward std11-field-head-regexp nil t)
138 (setq f-b (match-beginning 0)
140 field-name (buffer-substring f-b p)
141 len (string-width field-name)
142 f-e (std11-field-end))
143 (when (mime-visible-field-p field-name
144 visible-fields invisible-fields)
146 (capitalize (buffer-substring f-b (1- p))))
147 field-body (buffer-substring p f-e)
148 field-decoder (inline (mime-find-field-decoder-internal
150 (with-current-buffer the-buf
152 (insert (if field-decoder
153 (funcall field-decoder field-body len)
164 ;;; mmgeneric.el ends here