;;; mel-b.el --- Base64 encoder/decoder using builtin base64 handlers ;; Copyright (C) 1998,1999,2000,2001 Free Software Foundation, Inc. ;; Author: Tanaka Akira ;; Created by modifying mel-b-ccl.el: 2001/2/6 ;; Keywords: MIME, Base64 ;; This file is part of FLIM (Faithful Library about Internet Message). ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2, or (at ;; your option) any later version. ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; 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. ;;; Code: (require 'mime-def) (defun base64-insert-encoded-file (filename) "Encode contents of file FILENAME to base64, and insert the result." (interactive "*fInsert encoded file: ") (save-excursion (save-restriction (narrow-to-region (point) (point)) (let ((coding-system-for-read 'binary)) (insert-file-contents filename)) (base64-encode-region (point-min) (point-max))))) (mel-define-method-function (mime-encode-string string (nil "base64")) 'base64-encode-string) (mel-define-method-function (mime-encode-region start end (nil "base64")) 'base64-encode-region) (mel-define-method-function (mime-insert-encoded-file filename (nil "base64")) 'base64-insert-encoded-file) (mel-define-method-function (encoded-text-encode-string string (nil "B")) 'base64-encode-string) (defun base64-write-decoded-region (start end filename) "Decode the region from START to END and write out to FILENAME." (interactive "*r\nFWrite decoded region to file: ") (let ((current (current-buffer)) (multibyte enable-multibyte-characters)) (with-temp-buffer (set-buffer-multibyte multibyte) (insert-buffer-substring current start end) (base64-decode-region (point-min) (point-max)) (let ((coding-system-for-write 'binary)) (write-region (point-min) (point-max) filename))))) (mel-define-method-function (mime-decode-string string (nil "base64")) 'base64-ccl-decode-string) (mel-define-method-function (mime-decode-region start end (nil "base64")) 'base64-ccl-decode-region) (mel-define-method-function (mime-write-decoded-region start end filename (nil "base64")) 'base64-write-decoded-region) (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))) ;;; @ end ;;; (provide 'mel-b) ;;; mel-b.el ends here.