Add autoload setting for mime-parse.el.
[elisp/flim.git] / mime-lib.el
1 ;;; mime-lib.el --- MIME library module
2
3 ;; Copyright (C) 1998 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: MIME, multimedia, mail, news
7
8 ;; This file is part of FLIM (Faithful Library about Internet Message).
9
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.
14
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.
19
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.
24
25 ;;; Code:
26
27 (require 'alist)
28 (require 'std11)
29 (require 'mime-def)
30 (require 'eword-decode)
31
32
33 (autoload 'mime-parse-Content-Type "mime-parse"
34   "Parse STRING as field-body of Content-Type field.")
35
36 (autoload 'mime-read-Content-Type "mime-parse"
37   "Read field-body of Content-Type field from current-buffer,
38 and return parsed it.")
39
40 (autoload 'mime-parse-Content-Disposition "mime-parse"
41   "Parse STRING as field-body of Content-Disposition field.")
42
43 (autoload 'mime-read-Content-Disposition "mime-parse"
44   "Read field-body of Content-Disposition field from current-buffer,
45 and return parsed it.")
46
47 (autoload 'mime-parse-Content-Transfer-Encoding "mime-parse"
48   "Parse STRING as field-body of Content-Transfer-Encoding field.")
49
50 (autoload 'mime-read-Content-Transfer-Encoding "mime-parse"
51   "Read field-body of Content-Transfer-Encoding field from
52 current-buffer, and return it.")
53
54 (autoload 'mime-parse-message "mime-parse"
55   "Parse current-buffer as a MIME message.")
56
57 (autoload 'mime-parse-buffer "mime-parse"
58   "Parse BUFFER as a MIME message.")
59
60
61 (defun mime-entity-fetch-field (entity field-name)
62   (or (symbolp field-name)
63       (setq field-name (intern (capitalize (capitalize field-name)))))
64   (let* ((header (mime-entity-original-header entity))
65          (field-body (cdr (assq field-name header))))
66     (or field-body
67         (progn
68           (if (save-excursion
69                 (set-buffer (mime-entity-buffer entity))
70                 (save-restriction
71                   (narrow-to-region (mime-entity-header-start entity)
72                                     (mime-entity-header-end entity))
73                   (setq field-body
74                         (std11-fetch-field (symbol-name field-name)))
75                   ))
76               (mime-entity-set-original-header
77                entity (put-alist field-name field-body header))
78             )
79           field-body))))
80
81 (defun mime-entity-read-field (entity field-name)
82   (or (symbolp field-name)
83       (setq field-name (capitalize (capitalize field-name))))
84   (cond ((eq field-name 'Content-Type)
85          (mime-entity-content-type entity)
86          )
87         ((eq field-name 'Content-Disposition)
88          (mime-entity-content-disposition entity)
89          )
90         ((eq field-name 'Content-Transfer-Encoding)
91          (mime-entity-encoding entity)
92          )
93         (t
94          (let* ((header (mime-entity-parsed-header entity))
95                 (field (cdr (assq field-name header))))
96            (or field
97                (let ((field-body (mime-entity-fetch-field entity field-name)))
98                  (when field-body
99                    (cond ((memq field-name '(From Resent-From
100                                              To Resent-To
101                                              Cc Resent-Cc
102                                              Bcc Resent-Bcc
103                                              Reply-To Resent-Reply-To))
104                           (setq field (std11-parse-addresses
105                                        (eword-lexical-analyze field-body)))
106                           )
107                          ((eq field-name '(Sender Resent-Sender))
108                           (setq field (std11-parse-address
109                                        (eword-lexical-analyze field-body)))
110                           )
111                          ((memq field-name eword-decode-ignored-field-list)
112                           (setq field field-body))
113                          ((memq field-name eword-decode-structured-field-list)
114                           (setq field (eword-decode-structured-field-body
115                                        field-body)))
116                          (t
117                           (setq field (eword-decode-unstructured-field-body
118                                        field-body))
119                           ))
120                    (mime-entity-set-parsed-header
121                     entity (put-alist field-name field header))
122                    field)))))))
123
124
125 ;;; @ end
126 ;;;
127
128 (provide 'mime-lib)
129
130 ;;; mime-lib.el ends here