1 ;;; mime-lib.el --- MIME library module
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 (require 'eword-decode)
32 (autoload 'eword-encode-field "eword-encode"
33 "Encode header field STRING, and return the result.")
34 (autoload 'eword-encode-header "eword-encode"
35 "Encode header fields to network representation, such as MIME encoded-word.")
38 (autoload 'mime-parse-Content-Type "mime-parse"
39 "Parse STRING as field-body of Content-Type field.")
40 (autoload 'mime-read-Content-Type "mime-parse"
41 "Read field-body of Content-Type field from current-buffer,
42 and return parsed it.")
44 (autoload 'mime-parse-Content-Disposition "mime-parse"
45 "Parse STRING as field-body of Content-Disposition field.")
46 (autoload 'mime-read-Content-Disposition "mime-parse"
47 "Read field-body of Content-Disposition field from current-buffer,
48 and return parsed it.")
50 (autoload 'mime-parse-Content-Transfer-Encoding "mime-parse"
51 "Parse STRING as field-body of Content-Transfer-Encoding field.")
52 (autoload 'mime-read-Content-Transfer-Encoding "mime-parse"
53 "Read field-body of Content-Transfer-Encoding field from
54 current-buffer, and return it.")
56 (autoload 'mime-parse-message "mime-parse"
57 "Parse current-buffer as a MIME message.")
59 (autoload 'mime-parse-buffer "mime-parse"
60 "Parse BUFFER as a MIME message.")
66 (defun mime-entity-fetch-field (entity field-name)
67 (or (symbolp field-name)
68 (setq field-name (intern (capitalize (capitalize field-name)))))
69 (let* ((header (mime-entity-original-header entity))
70 (field-body (cdr (assq field-name header))))
74 (set-buffer (mime-entity-buffer entity))
76 (narrow-to-region (mime-entity-header-start entity)
77 (mime-entity-header-end entity))
79 (std11-fetch-field (symbol-name field-name)))
81 (mime-entity-set-original-header
82 entity (put-alist field-name field-body header))
86 (defun mime-entity-read-field (entity field-name)
87 (or (symbolp field-name)
88 (setq field-name (capitalize (capitalize field-name))))
89 (cond ((eq field-name 'Content-Type)
90 (mime-entity-content-type entity)
92 ((eq field-name 'Content-Disposition)
93 (mime-entity-content-disposition entity)
95 ((eq field-name 'Content-Transfer-Encoding)
96 (mime-entity-encoding entity)
99 (let* ((header (mime-entity-parsed-header entity))
100 (field (cdr (assq field-name header))))
102 (let ((field-body (mime-entity-fetch-field entity field-name)))
104 (cond ((memq field-name '(From Resent-From
108 Reply-To Resent-Reply-To))
109 (setq field (std11-parse-addresses
110 (eword-lexical-analyze field-body)))
112 ((eq field-name '(Sender Resent-Sender))
113 (setq field (std11-parse-address
114 (eword-lexical-analyze field-body)))
116 ((memq field-name eword-decode-ignored-field-list)
117 (setq field field-body))
118 ((memq field-name eword-decode-structured-field-list)
119 (setq field (eword-decode-structured-field-body
122 (setq field (eword-decode-unstructured-field-body
125 (mime-entity-set-parsed-header
126 entity (put-alist field-name field header))
129 (defun mime-entity-content (entity)
131 (set-buffer (mime-entity-buffer entity))
132 (mime-decode-string (buffer-substring (mime-entity-body-start entity)
133 (mime-entity-body-end entity))
134 (mime-entity-encoding entity))))
136 (defsubst mime-root-entity-p (entity)
137 "Return t if ENTITY is root-entity (message)."
138 (null (mime-entity-node-id entity)))
146 ;;; mime-lib.el ends here