update.
[elisp/flim.git] / mime-def.el
1 ;;; mime-def.el --- definition module about MIME
2
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: definition, 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 (defconst mime-spadework-module-version-string
28   "FLIM 1.2.1 - \"Kamitobaguchi\"")
29
30
31 ;;; @ variables
32 ;;;
33
34 (require 'custom)
35
36 (defgroup mime nil
37   "Emacs MIME Interfaces"
38   :group 'news
39   :group 'mail)
40
41 (custom-handle-keyword 'default-mime-charset :group 'mime
42                        'custom-variable)
43
44 (defcustom mime-temp-directory (or (getenv "MIME_TMP_DIR")
45                                    (getenv "TM_TMP_DIR")
46                                    (getenv "TMPDIR")
47                                    (getenv "TMP")
48                                    (getenv "TEMP")
49                                    "/tmp/")
50   "*Directory for temporary files."
51   :group 'mime
52   :type 'directory)
53
54
55 ;;; @ required functions
56 ;;;
57
58 (unless (fboundp 'butlast)
59   (defun butlast (x &optional n)
60     "Returns a copy of LIST with the last N elements removed."
61     (if (and n (<= n 0)) x
62       (nbutlast (copy-sequence x) n)))
63   
64   (defun nbutlast (x &optional n)
65     "Modifies LIST to remove the last N elements."
66     (let ((m (length x)))
67       (or n (setq n 1))
68       (and (< n m)
69            (progn
70              (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil))
71              x))))
72   )
73
74 (defsubst eliminate-top-spaces (string)
75   "Eliminate top sequence of space or tab in STRING."
76   (if (string-match "^[ \t]+" string)
77       (substring string (match-end 0))
78     string))
79
80
81 ;;; @ definitions about MIME
82 ;;;
83
84 (defconst mime-tspecials "][()<>@,\;:\\\"/?=")
85 (defconst mime-token-regexp (concat "[^" mime-tspecials "\000-\040]+"))
86 (defconst mime-charset-regexp mime-token-regexp)
87
88 (defconst mime-media-type/subtype-regexp
89   (concat mime-token-regexp "/" mime-token-regexp))
90
91
92 ;;; @@ Quoted-Printable
93 ;;;
94
95 (defconst quoted-printable-hex-chars "0123456789ABCDEF")
96
97 (defconst quoted-printable-octet-regexp
98   (concat "=[" quoted-printable-hex-chars
99           "][" quoted-printable-hex-chars "]"))
100
101
102 ;;; @ utility
103 ;;;
104
105 (defsubst mime-type/subtype-string (type &optional subtype)
106   "Return type/subtype string from TYPE and SUBTYPE."
107   (if type
108       (if subtype
109           (format "%s/%s" type subtype)
110         (format "%s" type))))
111
112
113 ;;; @ end
114 ;;;
115
116 (provide 'mime-def)
117
118 ;;; mime-def.el ends here