Sync up with REMI 1.4.0-pre3.
[elisp/semi.git] / mime-play.el
index 20991eb..ef682d6 100644 (file)
@@ -197,29 +197,44 @@ specified, play as it.  Default MODE is \"play\"."
 ;;; @ external decoder
 ;;;
 
+(defvar mime-mailcap-method-filename-alist nil)
+
 (defun mime-activate-mailcap-method (start end situation)
   (save-excursion
     (save-restriction
       (narrow-to-region start end)
       (goto-char start)
       (let ((method (cdr (assoc 'method situation)))
-           (name (mime-raw-get-filename situation)))
+           (name (expand-file-name (mime-raw-get-filename situation)
+                                   mime-temp-directory)))
        (mime-write-decoded-region (if (re-search-forward "^$" end t)
                                       (1+ (match-end 0))
                                     (point-min))
                                   end name
                                   (cdr (assq 'encoding situation)))
        (message "External method is starting...")
-       (let ((command
-              (mailcap-format-command
-               method
-               (cons (cons 'filename name) situation))))
-         (start-process command mime-echo-buffer-name
-                        shell-file-name shell-command-switch command)
+       (let ((process
+              (let ((command
+                     (mailcap-format-command
+                      method
+                      (cons (cons 'filename name) situation))))
+                (start-process command mime-echo-buffer-name
+                               shell-file-name shell-command-switch command)
+                )))
+         (set-alist 'mime-mailcap-method-filename-alist process name)
+         (set-process-sentinel process 'mime-mailcap-method-sentinel)
          )
-       (mime-show-echo-buffer)
+       ;;(mime-show-echo-buffer)
        ))))
 
+(defun mime-mailcap-method-sentinel (process event)
+  (let ((file (cdr (assq process mime-mailcap-method-filename-alist))))
+    (if (file-exists-p file)
+       (delete-file file)
+      ))
+  (remove-alist 'mime-mailcap-method-filename-alist process)
+  (message (format "%s %s" process event)))
+
 (defun mime-activate-external-method (beg end cal)
   (save-excursion
     (save-restriction