+
+;;; @ string
+;;;
+
+;;;###autoload
+(defvar mime-string-decoding-method-alist
+ '(("base64" . base64-decode-string)
+ ("quoted-printable" . quoted-printable-decode-string)
+ ("7bit" . identity)
+ ("8bit" . identity)
+ ("binary" . identity)
+ )
+ "Alist of encoding vs. corresponding method to decode string.
+Each element looks like (STRING . FUNCTION).
+STRING is content-transfer-encoding.
+FUNCTION is string decoder.")
+
+;;;###autoload
+(defun mime-decode-string (string encoding)
+ "Decode STRING using ENCODING.
+ENCODING must be string. If ENCODING is found in
+`mime-string-decoding-method-alist' as its key, this function decodes
+the STRING by its value."
+ (let ((f (cdr (assoc encoding mime-string-decoding-method-alist))))
+ (if f
+ (funcall f string)
+ (with-temp-buffer
+ (insert string)
+ (mime-decode-region (point-min)(point-max) encoding)
+ (buffer-string)
+ ))))
+
+
+;;; @ file
+;;;
+
+;;;###autoload
+(defvar mime-file-encoding-method-alist
+ '(("base64" . base64-insert-encoded-file)
+ ("quoted-printable" . quoted-printable-insert-encoded-file)
+ ;; Not standard, their use is DISCOURAGED.
+ ;; ("x-uue" . uuencode-insert-encoded-file)
+ ;; ("x-gzip64" . gzip64-insert-encoded-file)
+ ("7bit" . insert-file-contents-as-binary)
+ ("8bit" . insert-file-contents-as-binary)
+ ("binary" . insert-file-contents-as-binary)
+ )
+ "Alist of encoding vs. corresponding method to insert encoded file.
+Each element looks like (STRING . FUNCTION).
+STRING is content-transfer-encoding.
+FUNCTION is function to insert encoded file.")
+
+;;;###autoload
+(defvar mime-file-decoding-method-alist
+ '(("base64" . base64-write-decoded-region)
+ ("quoted-printable" . quoted-printable-write-decoded-region)
+ ("x-uue" . uuencode-write-decoded-region)
+ ("x-gzip64" . gzip64-write-decoded-region)
+ ("7bit" . write-region-as-binary)
+ ("8bit" . write-region-as-binary)
+ ("binary" . write-region-as-binary)
+ )
+ "Alist of encoding vs. corresponding method to write decoded region to file.
+Each element looks like (STRING . FUNCTION).
+STRING is content-transfer-encoding.
+FUNCTION is function to write decoded region to file.")
+
+;;;###autoload
+(defun mime-insert-encoded-file (filename encoding)
+ "Insert file FILENAME encoded by ENCODING format."
+ (interactive
+ (list (read-file-name "Insert encoded file: ")
+ (completing-read "encoding: "
+ mime-encoding-method-alist
+ nil t "base64"))
+ )
+ (let ((f (cdr (assoc encoding mime-file-encoding-method-alist))))
+ (if f
+ (funcall f filename)
+ )))
+
+;;;###autoload
+(defun mime-write-decoded-region (start end filename encoding)
+ "Decode and write current region encoded by ENCODING into FILENAME.
+START and END are buffer positions."
+ (interactive
+ (list (region-beginning) (region-end)
+ (read-file-name "Write decoded region to file: ")
+ (completing-read "encoding: "
+ mime-file-decoding-method-alist
+ nil t "base64")))
+ (let ((f (cdr (assoc encoding mime-file-decoding-method-alist))))
+ (if f
+ (funcall f start end filename)
+ )))