- beg end (car uuencode-external-decoder)
- t t nil (cdr uuencode-external-decoder))
- (setq filename (expand-file-name filename mime/tmp-dir))
- (let ((file-coding-system-for-read
- (if (boundp 'MULE) *noconv*)) ; Mule
- kanji-fileio-code) ; NEmacs
- (insert-file-contents filename)
- )
- (delete-file filename)
- ))
- )))
-
-(defalias 'uuencode-encode-region 'uuencode-external-encode-region)
-(defalias 'uuencode-decode-region 'uuencode-external-decode-region)
+ start end (car uuencode-external-decoder)
+ t nil nil
+ (cdr uuencode-external-decoder))
+ (insert-file-contents filename)
+ ;; The previous line causes the buffer to be made read-only, I
+ ;; do not pretend to understand the control flow leading to this
+ ;; but suspect it has something to do with image-mode. -slb
+ ;; Use `inhibit-read-only' to avoid to force
+ ;; buffer-read-only nil. - tomo.
+ (let ((inhibit-read-only t))
+ (delete-file filename)))))))
+
+(mel-define-method-function (mime-encode-region start end (nil "x-uue"))
+ 'uuencode-external-encode-region)
+(mel-define-method-function (mime-decode-region start end (nil "x-uue"))
+ 'uuencode-external-decode-region)
+
+
+;;; @ encoder/decoder for string
+;;;
+
+(mel-define-method mime-encode-string (string (nil "x-uue"))
+ (with-temp-buffer
+ (insert string)
+ (uuencode-external-encode-region (point-min)(point-max))
+ (buffer-string)))
+
+(mel-define-method mime-decode-string (string (nil "x-uue"))
+ (with-temp-buffer
+ (insert string)
+ (uuencode-external-decode-region (point-min)(point-max))
+ (buffer-string)))
+
+
+;;; @ uuencode encoder/decoder for file
+;;;
+
+(mel-define-method mime-insert-encoded-file (filename (nil "x-uue"))
+ "Insert file encoded by unofficial uuencode format.
+This function uses external uuencode encoder which is specified by
+variable `uuencode-external-encoder'."
+ (interactive "*fInsert encoded file: ")
+ (call-process (car uuencode-external-encoder)
+ filename t nil
+ (file-name-nondirectory filename)))
+
+(mel-define-method mime-write-decoded-region (start end filename
+ (nil "x-uue"))
+ "Decode and write current region encoded by uuencode into FILENAME.
+START and END are buffer positions."
+ (interactive "*r\nFWrite decoded region to file: ")
+ (save-excursion
+ (let ((file (save-excursion
+ (save-restriction
+ (narrow-to-region start end)
+ (goto-char start)
+ (if (re-search-forward "^begin [0-9]+ " nil t)
+ (if (looking-at ".+$")
+ (buffer-substring (match-beginning 0)
+ (match-end 0)))))))
+ (default-directory temporary-file-directory))
+ (if file
+ (let ((coding-system-for-read 'binary)
+ (coding-system-for-write 'binary))
+ (apply (function call-process-region)
+ start end (car uuencode-external-decoder)
+ nil nil nil
+ (cdr uuencode-external-decoder))
+ (rename-file file filename 'overwrites))))))