4
|
1 ;;; mel.el : a MIME encoding/decoding library
|
|
2
|
110
|
3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
|
4
|
4
|
|
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
|
|
6 ;; modified by Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
|
|
7 ;; Created: 1995/6/25
|
110
|
8 ;; Version: $Id: mel.el,v 1.3 1997/03/16 03:05:15 steve Exp $
|
4
|
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
|
110
|
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
|
4
|
39 ;;; @ region
|
|
40 ;;;
|
|
41
|
110
|
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)
|
4
|
50
|
|
51 (defvar mime-encoding-method-alist
|
|
52 '(("base64" . base64-encode-region)
|
|
53 ("quoted-printable" . quoted-printable-encode-region)
|
|
54 ("x-uue" . uuencode-encode-region)
|
|
55 ("x-gzip64" . gzip64-encode-region)
|
|
56 ("7bit")
|
|
57 ("8bit")
|
|
58 ("binary")
|
76
|
59 )
|
|
60 "Alist of encoding vs. corresponding method to encode region.
|
|
61 Each element looks like (STRING . FUNCTION) or (STRING . nil).
|
|
62 STRING is content-transfer-encoding.
|
110
|
63 FUNCTION is region encoder and nil means not to encode.")
|
76
|
64
|
4
|
65
|
110
|
66 (autoload 'base64-decode-region
|
|
67 "mel-b" "Decode current region by base64." t)
|
|
68 (autoload 'quoted-printable-decode-region
|
|
69 "mel-q" "Decode current region by Quoted-Printable." t)
|
|
70 (autoload 'uuencode-decode-region
|
|
71 "mel-u" "Decode current region by unofficial uuencode format." t)
|
|
72 (autoload 'gzip64-decode-region
|
|
73 "mel-g" "Decode current region by unofficial x-gzip64 format." t)
|
4
|
74
|
|
75 (defvar mime-decoding-method-alist
|
|
76 '(("base64" . base64-decode-region)
|
|
77 ("quoted-printable" . quoted-printable-decode-region)
|
|
78 ("x-uue" . uuencode-decode-region)
|
76
|
79 ("x-uuencode" . uuencode-decode-region)
|
4
|
80 ("x-gzip64" . gzip64-decode-region)
|
76
|
81 )
|
|
82 "Alist of encoding vs. corresponding method to decode region.
|
|
83 Each element looks like (STRING . FUNCTION).
|
|
84 STRING is content-transfer-encoding.
|
110
|
85 FUNCTION is region decoder.")
|
76
|
86
|
10
|
87
|
110
|
88 (defun mime-encode-region (start end encoding)
|
|
89 "Encode region START to END of current buffer using ENCODING."
|
4
|
90 (interactive
|
|
91 (list (region-beginning) (region-end)
|
|
92 (completing-read "encoding: "
|
|
93 mime-encoding-method-alist
|
|
94 nil t "base64"))
|
|
95 )
|
|
96 (let ((f (cdr (assoc encoding mime-encoding-method-alist))))
|
|
97 (if f
|
110
|
98 (funcall f start end)
|
4
|
99 )))
|
|
100
|
110
|
101 (defun mime-decode-region (start end encoding)
|
|
102 "Decode region START to END of current buffer using ENCODING."
|
4
|
103 (interactive
|
|
104 (list (region-beginning) (region-end)
|
|
105 (completing-read "encoding: "
|
|
106 mime-decoding-method-alist
|
|
107 nil t "base64"))
|
|
108 )
|
|
109 (let ((f (cdr (assoc encoding mime-decoding-method-alist))))
|
|
110 (if f
|
110
|
111 (funcall f start end)
|
4
|
112 )))
|
|
113
|
|
114
|
|
115 ;;; @ file
|
|
116 ;;;
|
|
117
|
110
|
118 (autoload 'base64-insert-encoded-file
|
|
119 "mel-b" "Insert file encoded by base64." t)
|
|
120 (autoload 'quoted-printable-insert-encoded-file
|
|
121 "mel-q" "Insert file encoded by quoted-printable." t)
|
|
122 (autoload 'uuencode-insert-encoded-file
|
|
123 "mel-u" "Insert file encoded by unofficial uuencode format." t)
|
|
124 (autoload 'gzip64-insert-encoded-file
|
|
125 "mel-g" "Insert file encoded by unofficial gzip64 format." t)
|
4
|
126
|
|
127 (defvar mime-file-encoding-method-alist
|
|
128 '(("base64" . base64-insert-encoded-file)
|
|
129 ("quoted-printable" . quoted-printable-insert-encoded-file)
|
|
130 ("x-uue" . uuencode-insert-encoded-file)
|
|
131 ("x-gzip64" . gzip64-insert-encoded-file)
|
|
132 ("7bit" . insert-binary-file-contents-literally)
|
|
133 ("8bit" . insert-binary-file-contents-literally)
|
|
134 ("binary" . insert-binary-file-contents-literally)
|
76
|
135 )
|
|
136 "Alist of encoding vs. corresponding method to insert encoded file.
|
|
137 Each element looks like (STRING . FUNCTION).
|
|
138 STRING is content-transfer-encoding.
|
110
|
139 FUNCTION is function to insert encoded file.")
|
4
|
140
|
|
141 (defun mime-insert-encoded-file (filename encoding)
|
110
|
142 "Insert file FILENAME encoded by ENCODING format."
|
4
|
143 (interactive
|
|
144 (list (read-file-name "Insert encoded file: ")
|
|
145 (completing-read "encoding: "
|
|
146 mime-encoding-method-alist
|
|
147 nil t "base64"))
|
|
148 )
|
|
149 (let ((f (cdr (assoc encoding mime-file-encoding-method-alist))))
|
|
150 (if f
|
|
151 (funcall f filename)
|
|
152 )))
|
|
153
|
|
154
|
|
155 ;;; @ string
|
|
156 ;;;
|
|
157
|
|
158 (autoload 'base64-encode-string "mel-b")
|
|
159 (autoload 'base64-decode-string "mel-b")
|
|
160
|
|
161 (autoload 'q-encoding-encode-string-for-text "mel-q")
|
|
162 (autoload 'q-encoding-encode-string-for-comment "mel-q")
|
|
163 (autoload 'q-encoding-encode-string-for-phrase "mel-q")
|
|
164 (autoload 'q-encoding-encode-string "mel-q")
|
|
165 (autoload 'q-encoding-decode-string "mel-q")
|
|
166
|
|
167 (autoload 'base64-encoded-length "mel-b")
|
|
168 (autoload 'q-encoding-encoded-length "mel-q")
|
|
169
|
|
170
|
|
171 ;;; @ end
|
|
172 ;;;
|
|
173
|
|
174 (provide 'mel)
|
|
175
|
|
176 ;;; mel.el ends here.
|