1 ;;; mime-def.el --- definition module about MIME
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
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.
27 (defconst mime-library-version-string "FLIM 1.5.0 - \"Mukaijima\"")
35 (eval-when-compile (require 'cl))
38 "Emacs MIME Interfaces"
42 (custom-handle-keyword 'default-mime-charset :group 'mime
45 (defcustom mime-temp-directory (or (getenv "MIME_TMP_DIR")
51 "*Directory for temporary files."
56 ;;; @ required functions
59 (unless (fboundp 'butlast)
60 (defun butlast (x &optional n)
61 "Returns a copy of LIST with the last N elements removed."
62 (if (and n (<= n 0)) x
63 (nbutlast (copy-sequence x) n)))
65 (defun nbutlast (x &optional n)
66 "Modifies LIST to remove the last N elements."
71 (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil))
75 (defsubst eliminate-top-spaces (string)
76 "Eliminate top sequence of space or tab in STRING."
77 (if (string-match "^[ \t]+" string)
78 (substring string (match-end 0))
81 (defsubst regexp-* (regexp)
84 (defsubst regexp-or (&rest args)
85 (concat "\\(" (mapconcat (function identity) args "\\|") "\\)"))
91 (defconst std11-quoted-pair-regexp "\\\\.")
92 (defconst std11-non-qtext-char-list '(?\" ?\\ ?\r ?\n))
93 (defconst std11-qtext-regexp
94 (concat "[^" (char-list-to-string std11-non-qtext-char-list) "]"))
95 (defconst std11-quoted-string-regexp
98 (regexp-or std11-qtext-regexp std11-quoted-pair-regexp))
105 (defconst mime-tspecials "][()<>@,\;:\\\"/?=")
106 (defconst mime-token-regexp (concat "[^" mime-tspecials "\000-\040]+"))
107 (defconst mime-charset-regexp mime-token-regexp)
109 (defconst mime-media-type/subtype-regexp
110 (concat mime-token-regexp "/" mime-token-regexp))
113 ;;; @@ Quoted-Printable
116 (defconst quoted-printable-hex-chars "0123456789ABCDEF")
118 (defconst quoted-printable-octet-regexp
119 (concat "=[" quoted-printable-hex-chars
120 "][" quoted-printable-hex-chars "]"))
126 (defsubst make-mime-content-type (type subtype &optional parameters)
127 (list* (cons 'type type)
128 (cons 'subtype subtype)
129 (nreverse parameters))
132 (defsubst mime-content-type-primary-type (content-type)
133 "Return primary-type of CONTENT-TYPE."
134 (cdr (car content-type)))
136 (defsubst mime-content-type-subtype (content-type)
137 "Return primary-type of CONTENT-TYPE."
138 (cdr (cadr content-type)))
140 (defsubst mime-content-type-parameters (content-type)
141 "Return primary-type of CONTENT-TYPE."
144 (defsubst mime-content-type-parameter (content-type parameter)
145 "Return PARAMETER value of CONTENT-TYPE."
146 (cdr (assoc parameter (mime-content-type-parameters content-type))))
149 ;;; @ Content-Disposition
152 (defsubst mime-content-disposition-type (content-disposition)
153 "Return disposition-type of CONTENT-DISPOSITION."
154 (cdr (car content-disposition)))
156 (defsubst mime-content-disposition-parameters (content-disposition)
157 "Return disposition-parameters of CONTENT-DISPOSITION."
158 (cdr content-disposition))
160 (defsubst mime-content-disposition-parameter (content-disposition parameter)
161 "Return PARAMETER value of CONTENT-DISPOSITION."
162 (cdr (assoc parameter (cdr content-disposition))))
164 (defsubst mime-content-disposition-filename (content-disposition)
165 "Return filename of CONTENT-DISPOSITION."
166 (mime-content-disposition-parameter content-disposition "filename"))
172 (defsubst make-mime-entity (buffer
173 header-start header-end body-start body-end
175 content-type content-disposition
177 (vector buffer header-start header-end body-start body-end
178 node-id content-type content-disposition encoding nil
181 (defsubst mime-entity-buffer (entity) (aref entity 0))
182 (defsubst mime-entity-header-start (entity) (aref entity 1))
183 (defsubst mime-entity-header-end (entity) (aref entity 2))
184 (defsubst mime-entity-body-start (entity) (aref entity 3))
185 (defsubst mime-entity-body-end (entity) (aref entity 4))
186 (defsubst mime-entity-node-id (entity) (aref entity 5))
187 (defsubst mime-entity-content-type (entity) (aref entity 6))
188 (defsubst mime-entity-content-disposition (entity) (aref entity 7))
189 (defsubst mime-entity-encoding (entity) (aref entity 8))
190 (defsubst mime-entity-original-header (entity) (aref entity 9))
191 (defsubst mime-entity-children (entity) (aref entity 10))
192 (defsubst mime-entity-parsed-header (entity) (aref entity 11))
194 (defsubst mime-entity-set-original-header (entity header)
195 (aset entity 9 header))
196 (defsubst mime-entity-set-parsed-header (entity header)
197 (aset entity 11 header))
199 (defsubst mime-entity-number (entity)
200 (reverse (mime-entity-node-id entity)))
202 (defalias 'mime-entity-point-min 'mime-entity-header-start)
203 (defalias 'mime-entity-point-max 'mime-entity-body-end)
205 (defsubst mime-entity-media-type (entity)
206 (mime-content-type-primary-type (mime-entity-content-type entity)))
207 (defsubst mime-entity-media-subtype (entity)
208 (mime-content-type-subtype (mime-entity-content-type entity)))
209 (defsubst mime-entity-parameters (entity)
210 (mime-content-type-parameters (mime-entity-content-type entity)))
212 (defsubst mime-entity-type/subtype (entity-info)
213 (mime-type/subtype-string (mime-entity-media-type entity-info)
214 (mime-entity-media-subtype entity-info)))
220 (defsubst mime-type/subtype-string (type &optional subtype)
221 "Return type/subtype string from TYPE and SUBTYPE."
224 (format "%s/%s" type subtype)
225 (format "%s" type))))
233 ;;; mime-def.el ends here