1 ;;; mel.el : a MIME encoding/decoding library
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; modified by Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
8 ;; Version: $Id: mel.el,v 7.2 1998/01/11 16:16:44 morioka Exp $
9 ;; Keywords: MIME, Base64, Quoted-Printable, uuencode, gzip64
11 ;; This file is part of MEL (MIME Encoding Library).
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.
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.
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.
33 (defvar mime-temp-directory (or (getenv "MIME_TMP_DIR")
36 "*Directory for temporary files.")
38 (defvar base64-dl-module
39 (and (fboundp 'dynamic-link)
40 (expand-file-name "base64.so" exec-directory)))
46 (cond (base64-dl-module
47 (autoload 'base64-encode-string "mel-dl"
48 "Encode STRING to base64, and return the result.")
49 (autoload 'base64-decode-string "mel-dl"
50 "Decode STRING which is encoded in base64, and return the result.")
51 (autoload 'base64-encode-region "mel-dl"
52 "Encode current region by base64." t)
53 (autoload 'base64-decode-region "mel-dl"
54 "Decode current region by base64." t)
55 (autoload 'base64-insert-encoded-file "mel-dl"
56 "Encode contents of file to base64, and insert the result." t)
58 (autoload 'base64-encoded-length "mel-dl")
61 (autoload 'base64-encode-string "mel-b"
62 "Encode STRING to base64, and return the result.")
63 (autoload 'base64-decode-string "mel-b"
64 "Decode STRING which is encoded in base64, and return the result.")
65 (autoload 'base64-encode-region "mel-b"
66 "Encode current region by base64." t)
67 (autoload 'base64-decode-region "mel-b"
68 "Decode current region by base64." t)
69 (autoload 'base64-insert-encoded-file "mel-b"
70 "Encode contents of file to base64, and insert the result." t)
72 (autoload 'base64-encoded-length "mel-b")
75 (autoload 'quoted-printable-encode-string "mel-q"
76 "Encode STRING to quoted-printable, and return the result.")
77 (autoload 'quoted-printable-decode-string "mel-q"
78 "Decode STRING which is encoded in quoted-printable, and return the result.")
79 (autoload 'quoted-printable-encode-region "mel-q"
80 "Encode current region by Quoted-Printable." t)
81 (autoload 'quoted-printable-decode-region "mel-q"
82 "Decode current region by Quoted-Printable." t)
83 (autoload 'quoted-printable-insert-encoded-file "mel-q"
84 "Encode contents of file to quoted-printable, and insert the result." t)
86 (autoload 'q-encoding-encode-string "mel-q"
87 "Encode STRING to Q-encoding of encoded-word, and return the result.")
88 (autoload 'q-encoding-decode-string "mel-q"
89 "Decode STRING which is encoded in Q-encoding and return the result.")
90 (autoload 'q-encoding-encoded-length "mel-q")
92 (autoload 'uuencode-encode-region "mel-u"
93 "Encode current region by unofficial uuencode format." t)
94 (autoload 'uuencode-decode-region "mel-u"
95 "Decode current region by unofficial uuencode format." t)
96 (autoload 'uuencode-insert-encoded-file "mel-u"
97 "Insert file encoded by unofficial uuencode format." t)
99 (autoload 'gzip64-encode-region "mel-g"
100 "Encode current region by unofficial x-gzip64 format." t)
101 (autoload 'gzip64-decode-region "mel-g"
102 "Decode current region by unofficial x-gzip64 format." t)
103 (autoload 'gzip64-insert-encoded-file "mel-g"
104 "Insert file encoded by unofficial gzip64 format." t)
111 (defvar mime-encoding-method-alist
112 '(("base64" . base64-encode-region)
113 ("quoted-printable" . quoted-printable-encode-region)
114 ;; Not standard, their use is DISCOURAGED.
115 ;; ("x-uue" . uuencode-encode-region)
116 ;; ("x-gzip64" . gzip64-encode-region)
121 "Alist of encoding vs. corresponding method to encode region.
122 Each element looks like (STRING . FUNCTION) or (STRING . nil).
123 STRING is content-transfer-encoding.
124 FUNCTION is region encoder and nil means not to encode.")
127 (defvar mime-decoding-method-alist
128 '(("base64" . base64-decode-region)
129 ("quoted-printable" . quoted-printable-decode-region)
130 ("x-uue" . uuencode-decode-region)
131 ("x-uuencode" . uuencode-decode-region)
132 ("x-gzip64" . gzip64-decode-region)
134 "Alist of encoding vs. corresponding method to decode region.
135 Each element looks like (STRING . FUNCTION).
136 STRING is content-transfer-encoding.
137 FUNCTION is region decoder.")
140 (defun mime-encode-region (start end encoding)
141 "Encode region START to END of current buffer using ENCODING.
142 ENCODING must be string. If ENCODING is found in
143 `mime-encoding-method-alist' as its key, this function encodes the
144 region by its value."
146 (list (region-beginning) (region-end)
147 (completing-read "encoding: "
148 mime-encoding-method-alist
151 (let ((f (cdr (assoc encoding mime-encoding-method-alist))))
153 (funcall f start end)
157 (defun mime-decode-region (start end encoding)
158 "Decode region START to END of current buffer using ENCODING.
159 ENCODING must be string. If ENCODING is found in
160 `mime-decoding-method-alist' as its key, this function decodes the
161 region by its value."
163 (list (region-beginning) (region-end)
164 (completing-read "encoding: "
165 mime-decoding-method-alist
168 (let ((f (cdr (assoc encoding mime-decoding-method-alist))))
170 (funcall f start end)
178 (defvar mime-file-encoding-method-alist
179 '(("base64" . base64-insert-encoded-file)
180 ("quoted-printable" . quoted-printable-insert-encoded-file)
181 ;; Not standard, their use is DISCOURAGED.
182 ;; ("x-uue" . uuencode-insert-encoded-file)
183 ;; ("x-gzip64" . gzip64-insert-encoded-file)
184 ("7bit" . insert-binary-file-contents-literally)
185 ("8bit" . insert-binary-file-contents-literally)
186 ("binary" . insert-binary-file-contents-literally)
188 "Alist of encoding vs. corresponding method to insert encoded file.
189 Each element looks like (STRING . FUNCTION).
190 STRING is content-transfer-encoding.
191 FUNCTION is function to insert encoded file.")
194 (defun mime-insert-encoded-file (filename encoding)
195 "Insert file FILENAME encoded by ENCODING format."
197 (list (read-file-name "Insert encoded file: ")
198 (completing-read "encoding: "
199 mime-encoding-method-alist
202 (let ((f (cdr (assoc encoding mime-file-encoding-method-alist))))
213 ;;; mel.el ends here.