1 ;;; mmbuffer.el --- MIME entity module for binary buffer
3 ;; Copyright (C) 1998 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
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.
30 (mm-define-backend buffer)
32 (mm-define-method initialize-instance ((entity buffer))
33 (mime-entity-set-buffer-internal
34 entity (mime-entity-location-internal entity))
36 (set-buffer (mime-entity-buffer-internal entity))
37 (setq mime-message-structure entity)
38 (let ((header-start (point-min))
41 (body-end (point-max)))
42 (goto-char header-start)
43 (if (re-search-forward "^$" nil t)
44 (setq header-end (match-end 0)
45 body-start (if (= header-end body-end)
48 (setq header-end (point-min)
49 body-start (point-min)))
51 (narrow-to-region header-start header-end)
52 (mime-entity-set-content-type-internal
54 (let ((str (std11-fetch-field "Content-Type")))
56 (mime-parse-Content-Type str)
59 (mime-entity-set-header-start-internal entity header-start)
60 (mime-entity-set-header-end-internal entity header-end)
61 (mime-entity-set-body-start-internal entity body-start)
62 (mime-entity-set-body-end-internal entity body-end)
65 (mm-define-method entity-point-min ((entity buffer))
66 (mime-entity-header-start-internal entity))
68 (mm-define-method entity-point-max ((entity buffer))
69 (mime-entity-body-end-internal entity))
71 (mm-define-method fetch-field ((entity buffer) field-name)
73 (set-buffer (mime-entity-buffer-internal entity))
75 (narrow-to-region (mime-entity-header-start-internal entity)
76 (mime-entity-header-end-internal entity))
77 (std11-fetch-field field-name)
80 (mm-define-method entity-cooked-p ((entity buffer)) nil)
82 (mm-define-method entity-children ((entity buffer))
83 (let* ((content-type (mime-entity-content-type entity))
84 (primary-type (mime-content-type-primary-type content-type)))
85 (cond ((eq primary-type 'multipart)
86 (mime-parse-multipart entity)
88 ((and (eq primary-type 'message)
89 (memq (mime-content-type-subtype content-type)
90 '(rfc822 news external-body)
92 (mime-parse-encapsulated entity)
96 (mm-define-method entity-content ((entity buffer))
98 (set-buffer (mime-entity-buffer-internal entity))
100 (buffer-substring (mime-entity-body-start-internal entity)
101 (mime-entity-body-end-internal entity))
102 (mime-entity-encoding entity))))
104 (mm-define-method write-entity-content ((entity buffer) filename)
106 (set-buffer (mime-entity-buffer-internal entity))
107 (mime-write-decoded-region (mime-entity-body-start-internal entity)
108 (mime-entity-body-end-internal entity)
110 (or (mime-entity-encoding entity) "7bit"))
113 (mm-define-method write-entity ((entity buffer) filename)
115 (set-buffer (mime-entity-buffer-internal entity))
116 (write-region-as-binary (mime-entity-header-start-internal entity)
117 (mime-entity-body-end-internal entity)
121 (mm-define-method write-entity-body ((entity buffer) filename)
123 (set-buffer (mime-entity-buffer-internal entity))
124 (write-region-as-binary (mime-entity-body-start-internal entity)
125 (mime-entity-body-end-internal entity)
129 (defun mime-visible-field-p (field-name visible-fields invisible-fields)
131 (while visible-fields
132 (let ((regexp (car visible-fields)))
133 (if (string-match regexp field-name)
136 (setq visible-fields (cdr visible-fields))
139 (while invisible-fields
140 (let ((regexp (car invisible-fields)))
141 (if (string-match regexp field-name)
144 (setq invisible-fields (cdr invisible-fields))
148 (mm-define-method insert-decoded-header ((entity buffer)
149 &optional invisible-fields
152 (narrow-to-region (point)(point))
153 (let ((the-buf (current-buffer))
154 (src-buf (mime-entity-buffer-internal entity))
155 (h-end (mime-entity-header-end-internal entity))
156 beg p end field-name len field)
159 (goto-char (mime-entity-header-start-internal entity))
161 (narrow-to-region (point) h-end)
162 (while (re-search-forward std11-field-head-regexp nil t)
163 (setq beg (match-beginning 0)
165 field-name (buffer-substring beg (1- p))
166 len (string-width field-name)
167 end (std11-field-end))
168 (when (mime-visible-field-p field-name
169 visible-fields invisible-fields)
170 (setq field (intern (capitalize field-name)))
175 (cond ((memq field eword-decode-ignored-field-list)
177 (insert-buffer-substring src-buf p end)
179 ((memq field eword-decode-structured-field-list)
180 ;; Decode as structured field
181 (let ((body (save-excursion
183 (buffer-substring p end)
185 (insert (eword-decode-and-fold-structured-field
189 ;; Decode as unstructured field
190 (let ((body (save-excursion
192 (buffer-substring p end)
194 (insert (eword-decode-unstructured-field-body
206 ;;; mmbuffer.el ends here