1 ;;; mel-u.el --- uuencode encoder/decoder.
3 ;; Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
9 ;; This file is part of FLIM (Faithful Library about Internet Message).
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
32 (mel-define-backend "x-uue")
38 (defvar uuencode-external-encoder '("uuencode" "-")
39 "*list of uuencode encoder program name and its arguments.")
41 (defvar uuencode-external-decoder '("sh" "-c" "uudecode")
42 "*list of uuencode decoder program name and its arguments.")
45 ;;; @ uuencode encoder/decoder for region
48 (defun uuencode-external-encode-region (start end)
49 "Encode current region by unofficial uuencode format.
50 This function uses external uuencode encoder which is specified by
51 variable `uuencode-external-encoder'."
54 (let ((coding-system-for-read 'binary)
55 (coding-system-for-write 'binary))
56 (apply (function call-process-region)
57 start end (car uuencode-external-encoder)
59 (cdr uuencode-external-encoder)))
61 ;; regularize line break code
62 (goto-char (point-min))
63 (while (re-search-forward "\r$" nil t)
66 (defun uuencode-external-decode-region (start end)
67 "Decode current region by unofficial uuencode format.
68 This function uses external uuencode decoder which is specified by
69 variable `uuencode-external-decoder'."
72 (let ((the-buf (current-buffer))
73 (filename (make-temp-file "x-uue")))
77 (narrow-to-region start end)
79 (when (and (re-search-forward "^begin [0-9]+ " nil t)
81 (replace-match filename)
82 (let ((coding-system-for-read 'binary)
83 (coding-system-for-write 'binary))
84 (apply (function call-process-region)
85 start (mark) (car uuencode-external-decoder)
87 (cdr uuencode-external-decoder)))
88 (insert-file-contents filename)
89 ;; The previous line causes the buffer to be made read-only, I
90 ;; do not pretend to understand the control flow leading to this
91 ;; but suspect it has something to do with image-mode. -slb
92 ;; Use `inhibit-read-only' to avoid to force
93 ;; buffer-read-only nil. - tomo.
94 (let ((inhibit-read-only t))
95 (delete-file filename))))))))
97 (mel-define-method-function (mime-encode-region start end (nil "x-uue"))
98 'uuencode-external-encode-region)
99 (mel-define-method-function (mime-decode-region start end (nil "x-uue"))
100 'uuencode-external-decode-region)
103 ;;; @ encoder/decoder for string
106 (mel-define-method mime-encode-string (string (nil "x-uue"))
109 (uuencode-external-encode-region (point-min)(point-max))
112 (mel-define-method mime-decode-string (string (nil "x-uue"))
115 (uuencode-external-decode-region (point-min)(point-max))
119 ;;; @ uuencode encoder/decoder for file
122 (mel-define-method mime-insert-encoded-file (filename (nil "x-uue"))
123 "Insert file encoded by unofficial uuencode format.
124 This function uses external uuencode encoder which is specified by
125 variable `uuencode-external-encoder'."
126 (interactive "*fInsert encoded file: ")
127 (call-process (car uuencode-external-encoder)
129 (file-name-nondirectory filename)))
131 (mel-define-method mime-write-decoded-region (start end filename
133 "Decode and write current region encoded by uuencode into FILENAME.
134 START and END are buffer positions."
135 (interactive "*r\nFWrite decoded region to file: ")
137 (let ((the-buf (current-buffer))
138 (clone-buf (clone-buffer " *x-uue*"))
139 (file (make-temp-file "x-uue")))
142 (set-buffer clone-buf)
143 (narrow-to-region start end)
144 (setq buffer-read-only nil)
146 (when (and (re-search-forward "^begin [0-9]+ " nil t)
149 (let ((coding-system-for-read 'binary)
150 (coding-system-for-write 'binary))
151 (apply (function call-process-region)
152 (point-min) (point-max) (car uuencode-external-decoder)
154 (cdr uuencode-external-decoder))
155 (rename-file file filename 'overwrites)
156 (message (concat "Wrote " filename))))))
157 (kill-buffer clone-buf))))
164 (mel-define-backend "x-uuencode" ("x-uue"))
166 ;;; mel-u.el ends here.