X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=mel.el;h=44d7a707ea9fa0fef076006aa29dbce2f3d794f5;hb=4727809b0b568e24ae94c1d6bdb4354b37959739;hp=12fff865477126c1cb733d729f3c02b6fc447377;hpb=09986cc02a99ec95288aef3f2e890426ae252b54;p=elisp%2Fflim.git diff --git a/mel.el b/mel.el index 12fff86..44d7a70 100644 --- a/mel.el +++ b/mel.el @@ -1,6 +1,6 @@ ;;; mel.el --- A MIME encoding/decoding library. -;; Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc. +;; Copyright (C) 1995,1996,1997,1998,1999,2000 Free Software Foundation, Inc. ;; Author: MORIOKA Tomohiko ;; Created: 1995/6/25 @@ -20,15 +20,13 @@ ;; You should have received a copy of the GNU General Public License ;; along with this program; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, -;; Boston, MA 02111-1307, USA. +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. ;;; Code: (require 'mime-def) -(require 'poem) (require 'alist) -(require 'path-util) (defcustom mime-encoding-list '("7bit" "8bit" "binary" "base64" "quoted-printable") @@ -79,22 +77,78 @@ Content-Transfer-Encoding for it." ;;; @ setting for modules ;;; -(mel-define-backend "7bit") -(mel-define-method-function (mime-encode-string string (nil "7bit")) +(defun 8bit-insert-encoded-file (filename) + "Insert file FILENAME encoded by \"7bit\" format." + (let ((coding-system-for-read 'raw-text) + format-alist) + ;; Returns list of absolute file name and length of data inserted. + (insert-file-contents filename))) + +(defun 8bit-write-decoded-region (start end filename) + "Decode and write current region encoded by \"8bit\" into FILENAME." + (let ((coding-system-for-write 'raw-text) + format-alist) + (write-region start end filename))) + +(mel-define-backend "8bit") +(mel-define-method-function (mime-encode-string string (nil "8bit")) 'identity) -(mel-define-method-function (mime-decode-string string (nil "7bit")) +(mel-define-method-function (mime-decode-string string (nil "8bit")) '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 mime-encode-region (start end (nil "8bit"))) +(mel-define-method mime-decode-region (start end (nil "8bit"))) +(mel-define-method-function (mime-insert-encoded-file filename (nil "8bit")) + '8bit-insert-encoded-file) (mel-define-method-function (mime-write-decoded-region - start end filename (nil "7bit")) - 'write-region-as-binary) + start end filename (nil "8bit")) + '8bit-write-decoded-region) -(mel-define-backend "8bit" ("7bit")) -(mel-define-backend "binary" ("8bit")) +(defalias '7bit-insert-encoded-file '8bit-insert-encoded-file) +(defalias '7bit-write-decoded-region '8bit-write-decoded-region) + +(mel-define-backend "7bit" ("8bit")) + + +(defun binary-write-decoded-region (start end filename) + "Decode and write current region encoded by \"binary\" into FILENAME." + (let ((coding-system-for-write 'binary) + jka-compr-compression-info-list jam-zcat-filename-list) + (write-region start end filename))) + +(defalias 'binary-insert-encoded-file 'insert-file-contents-literally) + +(defun binary-find-file-noselect (filename &optional nowarn rawfile) + "Like `find-file-noselect', q.v., but don't code and format conversion." + (let ((coding-system-for-read 'binary) + format-alist) + (find-file-noselect filename nowarn rawfile))) + +(defun binary-funcall (name &rest args) + "Like `funcall', q.v., but read and write as binary." + (let ((coding-system-for-read 'binary) + (coding-system-for-write 'binary)) + (apply name args))) + +(defun binary-to-text-funcall (coding-system name &rest args) + "Like `funcall', q.v., but write as binary and read as text. +Read text is decoded as CODING-SYSTEM." + (let ((coding-system-for-read coding-system) + (coding-system-for-write 'binary)) + (apply name args))) + +(mel-define-backend "binary") +(mel-define-method-function (mime-encode-string string (nil "binary")) + 'identity) +(mel-define-method-function (mime-decode-string string (nil "binary")) + 'identity) +(mel-define-method mime-encode-region (start end (nil "binary"))) +(mel-define-method mime-decode-region (start end (nil "binary"))) +(mel-define-method-function (mime-insert-encoded-file filename (nil "binary")) + 'binary-insert-encoded-file) +(mel-define-method-function (mime-write-decoded-region + start end filename (nil "binary")) + 'binary-write-decoded-region) (defvar mel-b-builtin (and (fboundp 'base64-encode-string) @@ -119,12 +173,12 @@ mmencode included in metamail or XEmacs package)." (insert (base64-encode-string (with-temp-buffer (set-buffer-multibyte nil) - (insert-file-contents-as-binary filename) + (binary-insert-encoded-file filename) (buffer-string)))) (or (bolp) (insert ?\n))) - (mel-define-method-function (encoded-text-encode-string string (nil "B")) - 'base64-encode-string) + ;; (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 "\\'")) @@ -203,8 +257,18 @@ the STRING by its value." string))) -(mel-define-service encoded-text-encode-string (string encoding) - "Encode STRING as encoded-text using ENCODING. ENCODING must be string.") +(mel-define-service encoded-text-encode-string) +(defun encoded-text-encode-string (string encoding &optional mode) + "Encode STRING as encoded-text using ENCODING. +ENCODING must be string. +Optional argument MODE allows `text', `comment', `phrase' or nil. +Default value is `phrase'." + (if (string= encoding "B") + (base64-encode-string string 'no-line-break) + (let ((f (mel-find-function 'encoded-text-encode-string encoding))) + (if f + (funcall f string mode) + string)))) (mel-define-service encoded-text-decode-string (string encoding) "Decode STRING as encoded-text using ENCODING. ENCODING must be string.")