Rename `mime-view-play-current-entity' ->
[elisp/semi.git] / mime-play.el
index 889f6f7..837cb51 100644 (file)
@@ -1,14 +1,13 @@
-;;; mime-play.el --- decoder for mime-view.el
+;;; mime-play.el --- Playback processing module for mime-view.el
 
-;; Copyright (C) 1994,1995,1996,1997 Free Software Foundation, Inc.
+;; Copyright (C) 1994,1995,1996,1997,1998 Free Software Foundation, Inc.
 
 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
 ;; Created: 1995/9/26 (separated from tm-view.el)
 ;;     Renamed: 1997/2/21 from tm-play.el
-;; Version: $Id: mime-play.el,v 0.51 1997-09-05 11:42:36 morioka Exp $
 ;; Keywords: MIME, multimedia, mail, news
 
-;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
+;; This file is part of SEMI (Secretariat of Emacs MIME Interfaces).
 
 ;; This program is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU General Public License as
@@ -35,9 +34,9 @@
 ;;; @ content decoder
 ;;;
 
-(defvar mime-preview/after-decoded-position nil)
+(defvar mime-preview-after-decoded-position nil)
 
-(defun mime-view-play-current-entity (&optional mode)
+(defun mime-preview-play-current-entity (&optional mode)
   "Play current entity.
 It decodes current entity to call internal or external method.  The
 method is selected from variable `mime-acting-condition'.
@@ -51,23 +50,27 @@ If MODE is specified, play as it.  Default MODE is \"play\"."
        (let ((the-buf (current-buffer))
              (raw-buffer (get-text-property (point) 'mime-view-raw-buffer))
              )
-         (setq mime-preview/after-decoded-position (point))
+         (setq mime-preview-after-decoded-position (point))
          (set-buffer raw-buffer)
-         (mime-display-content cinfo mode)
+         (mime-playback-entity cinfo mode)
          (if (eq (current-buffer) raw-buffer)
              (progn
                (set-buffer the-buf)
-               (goto-char mime-preview/after-decoded-position)
+               (goto-char mime-preview-after-decoded-position)
                ))
          ))))
 
-(defun mime-display-content (cinfo &optional mode)
+(defun mime-playback-entity (cinfo &optional mode)
   (let ((beg (mime-entity-info-point-min cinfo))
        (end (mime-entity-info-point-max cinfo))
-       (ctype (or (mime-entity-info-type/subtype cinfo) "text/plain"))
+       (c-type (mime-entity-info-media-type cinfo))
+       (c-subtype (mime-entity-info-media-subtype cinfo))
        (params (mime-entity-info-parameters cinfo))
        (encoding (mime-entity-info-encoding cinfo))
        )
+    (or c-type
+       (setq c-type 'text
+             c-subtype 'plain))
     ;; Check for VM
     (if (< beg (point-min))
        (setq beg (point-min))
@@ -76,7 +79,8 @@ If MODE is specified, play as it.  Default MODE is \"play\"."
        (setq end (point-max))
       )
     (let (method cal ret)
-      (setq cal (list* (cons 'type ctype)
+      (setq cal (list* (cons 'type c-type)
+                      (cons 'subtype c-subtype)
                       (cons 'encoding encoding)
                       (cons 'major-mode major-mode)
                       params))
@@ -90,7 +94,7 @@ If MODE is specified, play as it.  Default MODE is \"play\"."
             (funcall method beg end ret)
             )
            ((and (listp method)(stringp (car method)))
-            (mime-article/start-external-method-region beg end ret)
+            (mime-activate-external-method beg end ret)
             )
            (t
             (mime-show-echo-buffer
@@ -111,7 +115,7 @@ If MODE is specified, play as it.  Default MODE is \"play\"."
 ;;; @ external decoder
 ;;;
 
-(defun mime-article/start-external-method-region (beg end cal)
+(defun mime-activate-external-method (beg end cal)
   (save-excursion
     (save-restriction
       (narrow-to-region beg end)
@@ -141,15 +145,15 @@ If MODE is specified, play as it.  Default MODE is \"play\"."
                          (list (car method)
                                mime-echo-buffer-name (car method)
                                )
-                         (mime-article/make-method-args cal
-                                                        (cdr (cdr method)))
+                         (mime-make-external-method-args
+                          cal (cdr (cdr method)))
                          ))
              (apply (function start-process) args)
              (mime-show-echo-buffer)
              ))
        ))))
 
-(defun mime-article/make-method-args (cal format)
+(defun mime-make-external-method-args (cal format)
   (mapcar (function
           (lambda (arg)
             (if (stringp arg)
@@ -249,6 +253,39 @@ window.")
   )
 
 
+;;; @ file extraction
+;;;
+
+(defun mime-method-to-save (beg end cal)
+  (goto-char beg)
+  (let* ((name
+         (save-restriction
+           (narrow-to-region beg end)
+           (mime-article/get-filename cal)
+           ))
+        (encoding (cdr (assq 'encoding cal)))
+        (filename
+          (if (and name (not (string-equal name "")))
+             (expand-file-name name
+                               (call-interactively
+                                (function
+                                 (lambda (dir)
+                                   (interactive "DDirectory: ")
+                                   dir))))
+           (call-interactively
+            (function
+             (lambda (file)
+               (interactive "FFilename: ")
+               (expand-file-name file))))))
+        )
+    (if (file-exists-p filename)
+        (or (yes-or-no-p (format "File %s exists. Save anyway? " filename))
+            (error "")))
+    (re-search-forward "\n\n")
+    (mime-write-decoded-region (match-end 0)(point-max) filename encoding)
+    ))
+
+
 ;;; @ mail/news message
 ;;;
 
@@ -264,7 +301,7 @@ It is registered to variable `mime-view-quitting-method-alist'."
     (pop-to-buffer mother)
     ))
 
-(defun mime-display-message/rfc822 (beg end cal)
+(defun mime-method-to-display-message/rfc822 (beg end cal)
   (let* ((cnum (mime-article/point-content-number beg))
         (new-name (format "%s-%s" (buffer-name) cnum))
         (mother mime-view-buffer)
@@ -303,7 +340,7 @@ It is registered to variable `mime-view-quitting-method-alist'."
     (write-region start end file)
     ))
 
-(defun mime-display-message/partial (beg end cal)
+(defun mime-method-to-store-message/partial (beg end cal)
   (goto-char beg)
   (let* ((root-dir
          (expand-file-name
@@ -344,7 +381,7 @@ It is registered to variable `mime-view-quitting-method-alist'."
       (re-search-forward "^$")
       (goto-char (1+ (match-end 0)))
       (setq file (concat root-dir "/" number))
-      (mime-article::write-region (point) (point-max) file)
+      (mime-article::write-region (point) end file)
       (let ((total-file (concat root-dir "/CT")))
        (setq total
              (if total
@@ -355,7 +392,7 @@ It is registered to variable `mime-view-quitting-method-alist'."
                           (get-buffer-create mime-temp-buffer-name))
                          (erase-buffer)
                          (insert total)
-                         (write-file total-file)
+                         (write-region (point-min)(point-max) total-file)
                          (kill-buffer (current-buffer))
                          ))
                    (string-to-number total)
@@ -388,7 +425,9 @@ It is registered to variable `mime-view-quitting-method-alist'."
                    (goto-char (point-max))
                    (setq i (1+ i))
                    ))
-               (as-binary-output-file (write-file (concat root-dir "/FULL")))
+               (as-binary-output-file
+                 (write-region (point-min)(point-max)
+                               (expand-file-name "FULL" root-dir)))
                (let ((i 1))
                  (while (<= i total)
                    (let ((file (format "%s/%d" root-dir i)))
@@ -433,7 +472,7 @@ It is registered to variable `mime-view-quitting-method-alist'."
     (dired dir)
     ))
 
-(defun mime-display-message/external-ftp (beg end cal)
+(defun mime-method-to-display-message/external-ftp (beg end cal)
   (let* ((site (cdr (assoc "site" cal)))
         (directory (cdr (assoc "directory" cal)))
         (name (cdr (assoc "name" cal)))
@@ -450,7 +489,7 @@ It is registered to variable `mime-view-quitting-method-alist'."
 ;;; @ rot13-47
 ;;;
 
-(defun mime-display-caesar (start end cal)
+(defun mime-method-to-display-caesar (start end cal)
   "Internal method for mime-view to display ROT13-47-48 message."
   (let* ((cnum (mime-article/point-content-number start))
         (new-name (format "%s-%s" (buffer-name) cnum))