-(defun mime-activate-external-method (beg end cal)
- (save-excursion
- (save-restriction
- (narrow-to-region beg end)
- (goto-char beg)
- (let ((method (cdr (assoc 'method cal)))
- (name (mime-raw-get-filename cal))
- )
- (if method
- (let ((file (make-temp-name
- (expand-file-name "TM" mime-temp-directory)))
- b args)
- (if (nth 1 method)
- (setq b beg)
- (setq b
- (if (re-search-forward "^$" nil t)
- (1+ (match-end 0))
- (point-min)
- ))
- )
- (goto-char b)
- (write-region b end file)
- (message "External method is starting...")
- (setq cal (put-alist
- 'name (replace-as-filename name) cal))
- (setq cal (put-alist 'file file cal))
- (setq args (nconc
- (list (car method)
- mime-echo-buffer-name (car method)
- )
- (mime-make-external-method-args
- cal (cdr (cdr method)))
- ))
- (apply (function start-process) args)
- (mime-show-echo-buffer)
- ))
- ))))
-
-(defun mime-make-external-method-args (cal format)
- (mapcar (function
- (lambda (arg)
- (if (stringp arg)
- arg
- (let* ((item (eval arg))
- (ret (cdr (assoc item cal)))
- )
- (if ret
- ret
- (if (eq item 'encoding)
- "7bit"
- ""))
- ))
- ))
- format))
-
-(defvar mime-echo-window-is-shared-with-bbdb t
+(defvar mime-mailcap-method-filename-alist nil)
+
+(defun mime-activate-mailcap-method (entity situation)
+ (let ((method (cdr (assoc 'method situation)))
+ (name (mime-entity-safe-filename entity)))
+ (setq name (expand-file-name (if (and name (not (string= name "")))
+ name
+ (make-temp-name "EMI"))
+ (make-temp-file "EMI" 'directory)))
+ (mime-write-entity-content entity name)
+ (message "External method is starting...")
+ (let ((process
+ (let ((command
+ (mime-format-mailcap-command
+ method
+ (cons (cons 'filename name) situation)))
+ (coding-system-for-read mime-play-messages-coding-system))
+ (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))))
+
+(defun mime-mailcap-method-sentinel (process event)
+ (when mime-play-delete-file-immediately
+ (let ((file (cdr (assq process mime-mailcap-method-filename-alist))))
+ (when (file-exists-p file)
+ (ignore-errors
+ (delete-file file)
+ (delete-directory (file-name-directory file)))))
+ (remove-alist 'mime-mailcap-method-filename-alist process))
+ (message "%s %s" process event))
+
+(defun mime-mailcap-delete-played-files ()
+ (dolist (elem mime-mailcap-method-filename-alist)
+ (when (file-exists-p (cdr elem))
+ (ignore-errors
+ (delete-file (cdr elem))
+ (delete-directory (file-name-directory (cdr elem)))))))
+
+(add-hook 'kill-emacs-hook 'mime-mailcap-delete-played-files)
+
+(defvar mime-echo-window-is-shared-with-bbdb
+ (module-installed-p 'bbdb)