-(defvar mime-temp-directory (or (getenv "MIME_TMP_DIR")
- (getenv "TM_TMP_DIR")
- "/tmp/")
- "*Directory for temporary files.")
-
-(defvar base64-dl-module
- (and (fboundp 'dynamic-link)
- (expand-file-name "base64.so" exec-directory)))
-
-
-;;; @ autoload
-;;;
-
-(cond (base64-dl-module
- (autoload 'base64-encode-string "mel-dl"
- "Encode STRING to base64, and return the result.")
- (autoload 'base64-decode-string "mel-dl"
- "Decode STRING which is encoded in base64, and return the result.")
- (autoload 'base64-encode-region "mel-dl"
- "Encode current region by base64." t)
- (autoload 'base64-decode-region "mel-dl"
- "Decode current region by base64." t)
- (autoload 'base64-insert-encoded-file "mel-dl"
- "Encode contents of file to base64, and insert the result." t)
- (autoload 'base64-write-decoded-region "mel-dl"
- "Decode and write current region encoded by base64 into FILENAME." t)
- ;; for encoded-word
- (autoload 'base64-encoded-length "mel-dl")
- )
- (t
- (autoload 'base64-encode-string "mel-b"
- "Encode STRING to base64, and return the result.")
- (autoload 'base64-decode-string "mel-b"
- "Decode STRING which is encoded in base64, and return the result.")
- (autoload 'base64-encode-region "mel-b"
- "Encode current region by base64." t)
- (autoload 'base64-decode-region "mel-b"
- "Decode current region by base64." t)
- (autoload 'base64-insert-encoded-file "mel-b"
- "Encode contents of file to base64, and insert the result." t)
- (autoload 'base64-write-decoded-region "mel-b"
- "Decode and write current region encoded by base64 into FILENAME." t)
- ;; for encoded-word
- (autoload 'base64-encoded-length "mel-b")
- ))
-
-(autoload 'quoted-printable-encode-string "mel-q"
- "Encode STRING to quoted-printable, and return the result.")
-(autoload 'quoted-printable-decode-string "mel-q"
- "Decode STRING which is encoded in quoted-printable, and return the result.")
-(autoload 'quoted-printable-encode-region "mel-q"
- "Encode current region by Quoted-Printable." t)
-(autoload 'quoted-printable-decode-region "mel-q"
- "Decode current region by Quoted-Printable." t)
-(autoload 'quoted-printable-insert-encoded-file "mel-q"
- "Encode contents of file to quoted-printable, and insert the result." t)
-(autoload 'quoted-printable-write-decoded-region "mel-q"
- "Decode and write current region encoded by quoted-printable into FILENAME."
- t)
-;; for encoded-word
-(autoload 'q-encoding-encode-string "mel-q"
- "Encode STRING to Q-encoding of encoded-word, and return the result.")
-(autoload 'q-encoding-decode-string "mel-q"
- "Decode STRING which is encoded in Q-encoding and return the result.")
-(autoload 'q-encoding-encoded-length "mel-q")
-
-(autoload 'uuencode-encode-region "mel-u"
- "Encode current region by unofficial uuencode format." t)
-(autoload 'uuencode-decode-region "mel-u"
- "Decode current region by unofficial uuencode format." t)
-(autoload 'uuencode-insert-encoded-file "mel-u"
- "Insert file encoded by unofficial uuencode format." t)
-(autoload 'uuencode-write-decoded-region "mel-u"
- "Decode and write current region encoded by uuencode into FILENAME." t)
-
-(autoload 'gzip64-encode-region "mel-g"
- "Encode current region by unofficial x-gzip64 format." t)
-(autoload 'gzip64-decode-region "mel-g"
- "Decode current region by unofficial x-gzip64 format." t)
-(autoload 'gzip64-insert-encoded-file "mel-g"
- "Insert file encoded by unofficial gzip64 format." t)
-(autoload 'gzip64-write-decoded-region "mel-g"
- "Decode and write current region encoded by gzip64 into FILENAME." t)
+(mel-define-backend "7bit")
+(mel-define-method-function (mime-encode-string string (nil "7bit"))
+ 'identity)
+(mel-define-method-function (mime-decode-string string (nil "7bit"))
+ 'identity)
+(mel-define-method mime-encode-region (start end (nil "7bit")))
+(mel-define-method mime-decode-region (start end (nil "7bit")))
+(mel-define-method-function (mime-insert-encoded-file filename (nil "7bit"))
+ 'insert-file-contents-as-binary)
+(mel-define-method-function (mime-write-decoded-region
+ start end filename (nil "7bit"))
+ 'write-region-as-binary)
+
+(mel-define-backend "8bit" ("7bit"))
+
+(mel-define-backend "binary" ("8bit"))
+
+(defvar mel-b-builtin
+ (and (fboundp 'base64-encode-string)
+ (subrp (symbol-function 'base64-encode-string))))
+
+(when mel-b-builtin
+ (mel-define-backend "base64")
+ (mel-define-method-function (mime-encode-string string (nil "base64"))
+ 'base64-encode-string)
+ (mel-define-method-function (mime-decode-string string (nil "base64"))
+ 'base64-decode-string)
+ (mel-define-method-function (mime-encode-region start end (nil "base64"))
+ 'base64-encode-region)
+ (mel-define-method-function (mime-decode-region start end (nil "base64"))
+ 'base64-decode-region)
+ (mel-define-method mime-insert-encoded-file (filename (nil "base64"))
+ "Encode contents of file FILENAME to base64, and insert the result.
+It calls external base64 encoder specified by
+`base64-external-encoder'. So you must install the program (maybe
+mmencode included in metamail or XEmacs package)."
+ (interactive "*fInsert encoded file: ")
+ (insert (base64-encode-string
+ (with-temp-buffer
+ (set-buffer-multibyte nil)
+ (insert-file-contents-as-binary filename)
+ (buffer-string))))
+ (or (bolp) (insert ?\n)))
+
+ (mel-define-method-function (encoded-text-encode-string string (nil "B"))
+ 'base64-encode-string)
+ (mel-define-method encoded-text-decode-string (string (nil "B"))
+ (if (string-match (eval-when-compile
+ (concat "\\`" B-encoded-text-regexp "\\'"))
+ string)
+ (base64-decode-string string)
+ (error "Invalid encoded-text %s" string)))
+ )
+
+(mel-use-module 'mel-b-el '("base64" "B"))
+(mel-use-module 'mel-q '("quoted-printable" "Q"))
+(mel-use-module 'mel-g '("x-gzip64"))
+(mel-use-module 'mel-u '("x-uue" "x-uuencode"))
+
+(defvar mel-b-ccl-module
+ (and (featurep 'mule)
+ (progn
+ (require 'path-util)
+ (module-installed-p 'mel-b-ccl))))
+
+(defvar mel-q-ccl-module
+ (and (featurep 'mule)
+ (progn
+ (require 'path-util)
+ (module-installed-p 'mel-q-ccl))))
+
+(when mel-b-ccl-module
+ (mel-use-module 'mel-b-ccl '("base64" "B")))
+
+(when mel-q-ccl-module
+ (mel-use-module 'mel-q-ccl '("quoted-printable" "Q")))
+
+(when base64-dl-module
+ (mel-use-module 'mel-b-dl '("base64" "B")))