1 ;;; mmexternal.el --- MIME entity module for external buffer
3 ;; Copyright (C) 1998,1999,2000 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6 ;; Keywords: 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.
31 (luna-define-class mime-external-entity (mime-entity)
34 (luna-define-internal-accessors 'mime-external-entity)
36 ;; In an external entity, information of media-type or other
37 ;; information which are represented in a header in a non-external
38 ;; entity are in the body of the parent entity.
41 (luna-define-method mime-entity-name ((entity mime-external-entity))
44 (mime-entity-parent-internal entity))))
47 (defun mmexternal-require-file-name (entity)
49 (or (mime-external-entity-body-file-internal entity)
50 (let* ((ct (mime-entity-content-type
51 (mime-entity-parent-internal entity)))
53 (mime-content-type-parameter ct "access-type")))
55 (string= access-type "anon-ftp"))
56 (let ((site (mime-content-type-parameter ct "site"))
58 (mime-content-type-parameter ct "directory"))
59 (name (mime-content-type-parameter ct "name")))
60 (mime-external-entity-set-body-file-internal
64 (concat "/anonymous@" site ":"
65 (file-name-as-directory directory))))))))
66 (error (message "Can't make file-name of external-body."))))
68 (defun mmexternal-require-buffer (entity)
69 (unless (and (mime-external-entity-body-buffer-internal entity)
71 (mime-external-entity-body-buffer-internal entity)))
74 (mmexternal-require-file-name entity)
75 (mime-external-entity-set-body-buffer-internal
77 (with-current-buffer (get-buffer-create
79 (mime-entity-name entity)
81 (binary-insert-encoded-file
82 (mime-external-entity-body-file-internal entity))
84 (error (message "Can't get external-body.")))))
90 (luna-define-method mime-insert-entity ((entity mime-external-entity))
91 (mime-insert-entity-body (mime-entity-parent-internal entity))
93 (mime-insert-entity-body entity))
95 (luna-define-method mime-write-entity ((entity mime-external-entity) filename)
97 (mime-insert-entity entity)
98 (let ((coding-system-for-write 'raw-text-dos))
99 (write-region (point-min) (point-max) filename))))
109 (luna-define-method mime-entity-body ((entity mime-external-entity))
110 (mmexternal-require-buffer entity)
111 (with-current-buffer (mime-external-entity-body-buffer-internal entity)
114 (luna-define-method mime-insert-entity-body ((entity mime-external-entity))
115 (mmexternal-require-buffer entity)
116 (insert-buffer-substring
117 (mime-external-entity-body-buffer-internal entity)))
119 (luna-define-method mime-write-entity-body ((entity mime-external-entity)
121 (mmexternal-require-buffer entity)
122 (with-current-buffer (mime-external-entity-body-buffer-internal entity)
123 (binary-write-decoded-region (point-min) (point-max) filename)))
129 (luna-define-method mime-entity-content ((entity mime-external-entity))
130 (let ((ret (mime-entity-body entity)))
132 (mime-decode-string ret (mime-entity-encoding entity))
133 (message "Cannot get content")
136 (luna-define-method mime-insert-entity-content ((entity mime-external-entity))
137 (insert (mime-entity-content entity)))
139 (luna-define-method mime-write-entity-content ((entity mime-external-entity)
141 (mmexternal-require-buffer entity)
142 (with-current-buffer (mime-external-entity-body-buffer-internal entity)
143 (mime-write-decoded-region (point-min) (point-max)
145 (or (mime-entity-encoding entity) "7bit"))))
151 (luna-define-method mime-entity-fetch-field :around
152 ((entity mime-external-entity) field-name)
153 (or (luna-call-next-method)
155 (mime-insert-entity-body (mime-entity-parent-internal entity))
156 (let ((ret (std11-fetch-field field-name)))
158 (or (symbolp field-name)
159 (setq field-name (intern (capitalize field-name))))
160 (mime-entity-set-original-header-internal
162 (put-alist field-name ret
163 (mime-entity-original-header-internal entity)))
166 (luna-define-method mime-insert-header ((entity mime-external-entity)
167 &optional invisible-fields
169 (let ((the-buf (current-buffer))
172 (mime-insert-entity-body (mime-entity-parent-internal entity))
173 (setq buf (current-buffer)
177 (mime-insert-header-from-buffer buf p-min p-max
178 invisible-fields visible-fields))))
184 (provide 'mmexternal)
186 ;;; mmexternal.el ends here