1 ;;; mel-g.el --- Gzip64 encoder/decoder.
3 ;; Copyright (C) 1995,1996,1997,1998 MORIOKA Tomohiko
4 ;; Copyright (C) 1996,1997,1999 Shuhei KOBAYASHI
6 ;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
7 ;; MORIOKA Tomohiko <tomo@m17n.org>
8 ;; Maintainer: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
10 ;; Keywords: Gzip64, base64, gzip, MIME
12 ;; This file is part of FLIM (Faithful Library about Internet Message).
14 ;; This program is free software; you can redistribute it and/or
15 ;; modify it under the terms of the GNU General Public License as
16 ;; published by the Free Software Foundation; either version 2, or (at
17 ;; your option) any later version.
19 ;; This program is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;; General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with this program; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
31 ;;; NOTE: Gzip64 is an experimental Content-Transfer-Encoding and its
32 ;;; use is STRONGLY DISCOURAGED except for private communication.
43 (defvar gzip64-external-encoder
44 (let ((file (exec-installed-p "mmencode")))
46 (` ("sh" "-c" (, (concat "gzip -c | " file))))))
47 "*list of gzip64 encoder program name and its arguments.")
49 (defvar gzip64-external-decoder
50 (let ((file (exec-installed-p "mmencode")))
52 (` ("sh" "-c" (, (concat file " -u | gzip -dc"))))))
53 "*list of gzip64 decoder program name and its arguments.")
56 ;;; @ encoder/decoder for region
59 (defun gzip64-external-encode-region (beg end)
63 (apply (function call-process-region)
64 beg end (car gzip64-external-encoder)
66 (cdr gzip64-external-encoder)))
68 ;; regularize line break code
69 (goto-char (point-min))
70 (while (re-search-forward "\r$" nil t)
73 (defun gzip64-external-decode-region (beg end)
77 (apply (function call-process-region)
78 beg end (car gzip64-external-decoder)
80 (cdr gzip64-external-decoder)))))
82 (mel-define-method-function (mime-encode-region start end (nil "x-gzip64"))
83 'gzip64-external-encode-region)
84 (mel-define-method-function (mime-decode-region start end (nil "x-gzip64"))
85 'gzip64-external-decode-region)
88 ;;; @ encoder/decoder for string
91 (mel-define-method mime-encode-string (string (nil "x-gzip64"))
94 (gzip64-external-encode-region (point-min)(point-max))
97 (mel-define-method mime-decode-string (string (nil "x-gzip64"))
100 (gzip64-external-decode-region (point-min)(point-max))
104 ;;; @ encoder/decoder for file
107 (mel-define-method mime-insert-encoded-file (filename (nil "x-gzip64"))
108 (interactive "*fInsert encoded file: ")
109 (apply (function call-process)
110 (car gzip64-external-encoder)
112 (cdr gzip64-external-encoder)))
114 (mel-define-method mime-write-decoded-region (start end filename
116 "Decode and write current region encoded by gzip64 into FILENAME.
117 START and END are buffer positions."
118 (interactive "*r\nFWrite decoded region to file: ")
120 (apply (function call-process-region)
121 start end (car gzip64-external-decoder)
123 (let ((args (cdr gzip64-external-decoder)))
124 (append (butlast args)
125 (list (concat (car (last args)) ">" filename)))))))
133 ;;; mel-g.el ends here.