MEL 7.1 (not released).
[elisp/flim.git] / mel.el
1 ;;; mel.el : a MIME encoding/decoding library
2
3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; modified by Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
7 ;; Created: 1995/6/25
8 ;; Version: $Id: mel.el,v 7.1 1997/11/06 16:17:11 morioka Exp $
9 ;; Keywords: MIME, Base64, Quoted-Printable, uuencode, gzip64
10
11 ;; This file is part of MEL (MIME Encoding Library).
12
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 2, or (at
16 ;; your option) any later version.
17
18 ;; This program is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 ;; General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
27
28 ;;; Code:
29
30 ;;; @ variable
31 ;;;
32
33 (defvar mime-temp-directory (or (getenv "MIME_TMP_DIR")
34                                 (getenv "TM_TMP_DIR")
35                                 "/tmp/")
36   "*Directory for temporary files.")
37
38
39 ;;; @ region
40 ;;;
41
42 (autoload 'base64-encode-region
43   "mel-b" "Encode current region by base64." t)
44 (autoload 'quoted-printable-encode-region
45   "mel-q" "Encode current region by Quoted-Printable." t)
46 (autoload 'uuencode-encode-region
47   "mel-u" "Encode current region by unofficial uuencode format." t)
48 (autoload 'gzip64-encode-region
49   "mel-g" "Encode current region by unofficial x-gzip64 format." t)
50
51 (defvar mime-encoding-method-alist
52   '(("base64"           . base64-encode-region)
53     ("quoted-printable" . quoted-printable-encode-region)
54     ;; Not standard, their use is DISCOURAGED.
55     ;; ("x-uue"            . uuencode-encode-region)
56     ;; ("x-gzip64"         . gzip64-encode-region)
57     ("7bit")
58     ("8bit")
59     ("binary")
60     )
61   "Alist of encoding vs. corresponding method to encode region.
62 Each element looks like (STRING . FUNCTION) or (STRING . nil).
63 STRING is content-transfer-encoding.
64 FUNCTION is region encoder and nil means not to encode.")
65
66
67 (autoload 'base64-decode-region
68   "mel-b" "Decode current region by base64." t)
69 (autoload 'quoted-printable-decode-region
70   "mel-q" "Decode current region by Quoted-Printable." t)
71 (autoload 'uuencode-decode-region
72   "mel-u" "Decode current region by unofficial uuencode format." t)
73 (autoload 'gzip64-decode-region
74   "mel-g" "Decode current region by unofficial x-gzip64 format." t)
75
76 (defvar mime-decoding-method-alist
77   '(("base64"           . base64-decode-region)
78     ("quoted-printable" . quoted-printable-decode-region)
79     ("x-uue"            . uuencode-decode-region)
80     ("x-uuencode"       . uuencode-decode-region)
81     ("x-gzip64"         . gzip64-decode-region)
82     )
83   "Alist of encoding vs. corresponding method to decode region.
84 Each element looks like (STRING . FUNCTION).
85 STRING is content-transfer-encoding.
86 FUNCTION is region decoder.")
87
88
89 ;;;###autoload
90 (defun mime-encode-region (start end encoding)
91   "Encode region START to END of current buffer using ENCODING.
92 ENCODING must be string.  If ENCODING is found in
93 `mime-encoding-method-alist' as its key, this function encodes the
94 region by its value."
95   (interactive
96    (list (region-beginning) (region-end)
97          (completing-read "encoding: "
98                           mime-encoding-method-alist
99                           nil t "base64"))
100    )
101   (let ((f (cdr (assoc encoding mime-encoding-method-alist))))
102     (if f
103         (funcall f start end)
104       )))
105
106 ;;;###autoload
107 (defun mime-decode-region (start end encoding)
108   "Decode region START to END of current buffer using ENCODING.
109 ENCODING must be string.  If ENCODING is found in
110 `mime-decoding-method-alist' as its key, this function decodes the
111 region by its value."
112   (interactive
113    (list (region-beginning) (region-end)
114          (completing-read "encoding: "
115                           mime-decoding-method-alist
116                           nil t "base64"))
117    )
118   (let ((f (cdr (assoc encoding mime-decoding-method-alist))))
119     (if f
120         (funcall f start end)
121       )))
122
123
124 ;;; @ file
125 ;;;
126
127 (autoload 'base64-insert-encoded-file "mel-b"
128   "Encode contents of file to base64, and insert the result." t)
129 (autoload 'quoted-printable-insert-encoded-file "mel-q"
130   "Encode contents of file to quoted-printable, and insert the result." t)
131 (autoload 'uuencode-insert-encoded-file
132   "mel-u" "Insert file encoded by unofficial uuencode format." t)
133 (autoload 'gzip64-insert-encoded-file
134   "mel-g" "Insert file encoded by unofficial gzip64 format." t)
135
136 (defvar mime-file-encoding-method-alist
137   '(("base64"           . base64-insert-encoded-file)
138     ("quoted-printable" . quoted-printable-insert-encoded-file)
139     ;; Not standard, their use is DISCOURAGED.
140     ;; ("x-uue"            . uuencode-insert-encoded-file)
141     ;; ("x-gzip64"         . gzip64-insert-encoded-file)
142     ("7bit"             . insert-binary-file-contents-literally)
143     ("8bit"             . insert-binary-file-contents-literally)
144     ("binary"           . insert-binary-file-contents-literally)
145     )
146   "Alist of encoding vs. corresponding method to insert encoded file.
147 Each element looks like (STRING . FUNCTION).
148 STRING is content-transfer-encoding.
149 FUNCTION is function to insert encoded file.")
150
151 ;;;###autoload
152 (defun mime-insert-encoded-file (filename encoding)
153   "Insert file FILENAME encoded by ENCODING format."
154   (interactive
155    (list (read-file-name "Insert encoded file: ")
156          (completing-read "encoding: "
157                           mime-encoding-method-alist
158                           nil t "base64"))
159    )
160   (let ((f (cdr (assoc encoding mime-file-encoding-method-alist))))
161     (if f
162         (funcall f filename)
163       )))
164
165
166 ;;; @ string
167 ;;;
168
169 (autoload 'base64-encode-string "mel-b"
170   "Encode STRING to base64, and return the result.")
171 (autoload 'base64-decode-string "mel-b"
172   "Decode STRING which is encoded in base64, and return the result.")
173 (autoload 'quoted-printable-encode-string "mel-q"
174   "Encode STRING to quoted-printable, and return the result.")
175 (autoload 'quoted-printable-decode-string "mel-q"
176   "Decode STRING which is encoded in quoted-printable, and return the result.")
177
178 (autoload 'q-encoding-encode-string "mel-q"
179   "Encode STRING to Q-encoding of encoded-word, and return the result.")
180 (autoload 'q-encoding-decode-string "mel-q"
181   "Decode STRING which is encoded in Q-encoding and return the result.")
182
183 (autoload 'base64-encoded-length "mel-b")
184 (autoload 'q-encoding-encoded-length "mel-q")
185
186
187 ;;; @ end
188 ;;;
189
190 (provide 'mel)
191
192 ;;; mel.el ends here.