Merge semi-1_10_2.
[elisp/semi.git] / mime-play.el
1 ;;; mime-play.el --- Playback processing module for mime-view.el
2
3 ;; Copyright (C) 1994,1995,1996,1997,1998 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Created: 1995/9/26 (separated from tm-view.el)
7 ;;      Renamed: 1997/2/21 from tm-play.el
8 ;; Keywords: MIME, multimedia, mail, news
9
10 ;; This file is part of SEMI (Secretariat of Emacs MIME Interfaces).
11
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
16
17 ;; This program is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Code:
28
29 (require 'mime-view)
30 (require 'alist)
31 (require 'filename)
32
33 (eval-when-compile
34   (condition-case nil
35       (require 'bbdb)
36     (error (defvar bbdb-buffer-name nil)))
37   )
38
39 (defvar mime-acting-situation-example-list nil)
40
41 (defvar mime-acting-situation-example-list-max-size 16)
42
43 (defun mime-save-acting-situation-examples ()
44   (let* ((file mime-acting-situation-examples-file)
45          (buffer (get-buffer-create " *mime-example*")))
46     (unwind-protect
47         (save-excursion
48           (set-buffer buffer)
49           (setq buffer-file-name file)
50           (erase-buffer)
51           (insert ";;; " (file-name-nondirectory file) "\n")
52           (insert "\n;; This file is generated automatically by "
53                   mime-view-version "\n\n")
54           (insert ";;; Code:\n\n")
55           (pp `(setq mime-acting-situation-example-list
56                      ',mime-acting-situation-example-list)
57               (current-buffer))
58           (insert "\n;;; "
59                   (file-name-nondirectory file)
60                   " ends here.\n")
61           (save-buffer))
62       (kill-buffer buffer))))
63
64 (add-hook 'kill-emacs-hook 'mime-save-acting-situation-examples)
65
66 (defun mime-reduce-acting-situation-examples ()
67   (let* ((rest mime-acting-situation-example-list)
68          (min-example (car rest))
69          (min-score (cdr min-example)))
70     (while rest
71       (let* ((example (car rest))
72              (score (cdr example)))
73         (cond ((< score min-score)
74                (setq min-score score
75                      min-example example)
76                )
77               ((= score min-score)
78                (if (<= (length (car example))(length (car min-example)))
79                    (setq min-example example)
80                  ))
81               ))
82       (setq rest (cdr rest)))
83     (setq mime-acting-situation-example-list
84           (delq min-example mime-acting-situation-example-list))
85     (setq min-example (car min-example))
86     (let ((examples mime-acting-situation-example-list)
87           (max-score 0)
88           max-examples)
89       (while examples
90         (let* ((ret (mime-compare-situation-with-example min-example
91                                                          (caar examples)))
92                (ret-score (car ret)))
93           (cond ((> ret-score max-score)
94                  (setq max-score ret-score
95                        max-examples (list (cdr ret)))
96                  )
97                 ((= ret-score max-score)
98                  (setq max-examples (cons (cdr ret) max-examples))
99                  )))
100         (setq examples (cdr examples)))
101       (while max-examples
102         (let* ((example (car max-examples))
103                (cell (assoc example mime-acting-situation-example-list)))
104           (if cell
105               (setcdr cell (1+ (cdr cell)))
106             (setq mime-acting-situation-example-list
107                   (cons (cons example 0)
108                         mime-acting-situation-example-list))
109             ))
110         (setq max-examples (cdr max-examples))
111         ))))
112
113
114 ;;; @ content decoder
115 ;;;
116
117 (defvar mime-preview-after-decoded-position nil)
118
119 (defun mime-preview-play-current-entity (&optional ignore-examples mode)
120   "Play current entity.
121 It decodes current entity to call internal or external method.  The
122 method is selected from variable `mime-acting-condition'.
123 If IGNORE-EXAMPLES (C-u prefix) is specified, this function ignores
124 `mime-acting-situation-example-list'.
125 If MODE is specified, play as it.  Default MODE is \"play\"."
126   (interactive "P")
127   (let ((entity (get-text-property (point) 'mime-view-entity)))
128     (if entity
129         (let ((the-buf (current-buffer))
130               (raw-buffer (mime-entity-buffer entity)))
131           (setq mime-preview-after-decoded-position (point))
132           (set-buffer raw-buffer)
133           (mime-raw-play-entity entity (or mode "play") nil ignore-examples)
134           (when (eq (current-buffer) raw-buffer)
135             (set-buffer the-buf)
136             (goto-char mime-preview-after-decoded-position)
137             )))))
138
139 (defun mime-sort-situation (situation)
140   (sort situation
141         #'(lambda (a b)
142             (let ((a-t (car a))
143                   (b-t (car b))
144                   (order '((type . 1)
145                            (subtype . 2)
146                            (mode . 3)
147                            (method . 4)
148                            (major-mode . 5)
149                            (disposition-type . 6)
150                            ))
151                   a-order b-order)
152               (if (symbolp a-t)
153                   (let ((ret (assq a-t order)))
154                     (if ret
155                         (setq a-order (cdr ret))
156                       (setq a-order 7)
157                       ))
158                 (setq a-order 8)
159                 )
160               (if (symbolp b-t)
161                   (let ((ret (assq b-t order)))
162                     (if ret
163                         (setq b-order (cdr ret))
164                       (setq b-order 7)
165                       ))
166                 (setq b-order 8)
167                 )
168               (if (= a-order b-order)
169                   (string< (format "%s" a-t)(format "%s" b-t))
170                 (< a-order b-order))
171               )))
172   )
173
174 (defsubst mime-delq-null-situation (situations field
175                                                &optional ignored-value)
176   (let (dest)
177     (while situations
178       (let* ((situation (car situations))
179              (cell (assq field situation)))
180         (if cell
181             (or (eq (cdr cell) ignored-value)
182                 (setq dest (cons situation dest))
183                 )))
184       (setq situations (cdr situations)))
185     dest))
186
187 (defun mime-compare-situation-with-example (situation example)
188   (let ((example (copy-alist example))
189         (match 0))
190     (while situation
191       (let* ((cell (car situation))
192              (key (car cell))
193              (ecell (assoc key example)))
194         (when ecell
195           (if (equal cell ecell)
196               (setq match (1+ match))
197             (setq example (delq ecell example))
198             ))
199         )
200       (setq situation (cdr situation))
201       )
202     (cons match example)
203     ))
204
205 (defun mime-raw-play-entity (entity &optional mode situation ignore-examples
206                                     ignored-method)
207   "Play entity specified by ENTITY.
208 It decodes the entity to call internal or external method.  The method
209 is selected from variable `mime-acting-condition'.  If MODE is
210 specified, play as it.  Default MODE is \"play\"."
211   (let (method ret)
212     (or situation
213         (setq situation (mime-entity-situation entity)))
214     (if mode
215         (setq situation (cons (cons 'mode mode) situation))
216       )
217     (if ignore-examples
218         (or (assq 'ignore-examples situation)
219             (setq situation
220                   (cons (cons 'ignore-examples ignore-examples) situation)))
221       )
222     (setq ret
223           (mime-delq-null-situation
224            (ctree-find-calist mime-acting-condition situation
225                               mime-view-find-every-acting-situation)
226            'method ignored-method))
227     (or ignore-examples
228         (if (cdr ret)
229             (let ((rest ret)
230                   (max-score 0)
231                   (max-escore 0)
232                   max-examples
233                   max-situations)
234               (while rest
235                 (let ((situation (car rest))
236                       (examples mime-acting-situation-example-list))
237                   (while examples
238                     (let* ((ret
239                             (mime-compare-situation-with-example
240                              situation (caar examples)))
241                            (ret-score (car ret)))
242                       (cond ((> ret-score max-score)
243                              (setq max-score ret-score
244                                    max-escore (cdar examples)
245                                    max-examples (list (cdr ret))
246                                    max-situations (list situation))
247                              )
248                             ((= ret-score max-score)
249                              (cond ((> (cdar examples) max-escore)
250                                     (setq max-escore (cdar examples)
251                                           max-examples (list (cdr ret))
252                                           max-situations (list situation))
253                                     )
254                                    ((= (cdar examples) max-escore)
255                                     (setq max-examples
256                                           (cons (cdr ret) max-examples))
257                                     (or (member situation max-situations)
258                                         (setq max-situations
259                                               (cons situation max-situations)))
260                                     )))))
261                     (setq examples (cdr examples))))
262                 (setq rest (cdr rest)))
263               (when max-situations
264                 (setq ret max-situations)
265                 (while max-examples
266                   (let* ((example (car max-examples))
267                          (cell
268                           (assoc example mime-acting-situation-example-list)))
269                     (if cell
270                         (setcdr cell (1+ (cdr cell)))
271                       (setq mime-acting-situation-example-list
272                             (cons (cons example 0)
273                                   mime-acting-situation-example-list))
274                       ))
275                   (setq max-examples (cdr max-examples))
276                   )))))
277     (cond ((cdr ret)
278            (setq ret (select-menu-alist
279                       "Methods"
280                       (mapcar (function
281                                (lambda (situation)
282                                  (cons
283                                   (format "%s"
284                                           (cdr (assq 'method situation)))
285                                   situation)))
286                               ret)))
287            (setq ret (mime-sort-situation ret))
288            (add-to-list 'mime-acting-situation-example-list (cons ret 0))
289            )
290           (t
291            (setq ret (car ret))
292            ))
293     (setq method (cdr (assq 'method ret)))
294     (cond ((and (symbolp method)
295                 (fboundp method))
296            (funcall method entity ret)
297            )
298           ((stringp method)
299            (mime-activate-mailcap-method entity ret)
300            )
301           ;; ((and (listp method)(stringp (car method)))
302           ;;  (mime-activate-external-method entity ret)
303           ;;  )
304           (t
305            (mime-show-echo-buffer "No method are specified for %s\n"
306                                   (mime-entity-type/subtype entity))
307            ))
308     ))
309
310
311 ;;; @ external decoder
312 ;;;
313
314 (defvar mime-mailcap-method-filename-alist nil)
315
316 (defun mime-activate-mailcap-method (entity situation)
317   (save-excursion
318     (save-restriction
319       (let ((start (mime-entity-point-min entity))
320             (end (mime-entity-point-max entity)))
321         (narrow-to-region start end)
322         (goto-char start)
323         (let ((method (cdr (assoc 'method situation)))
324               (name (mime-entity-safe-filename entity)))
325           (setq name
326                 (if (and name (not (string= name "")))
327                     (expand-file-name name temporary-file-directory)
328                   (make-temp-name
329                    (expand-file-name "EMI" temporary-file-directory))
330                   ))
331           (mime-write-entity-content entity name)
332           (message "External method is starting...")
333           (let ((process
334                  (let ((command
335                         (mailcap-format-command
336                          method
337                          (cons (cons 'filename name) situation))))
338                    (start-process command mime-echo-buffer-name
339                                   shell-file-name shell-command-switch command)
340                    )))
341             (set-alist 'mime-mailcap-method-filename-alist process name)
342             (set-process-sentinel process 'mime-mailcap-method-sentinel)
343             )
344           )))))
345
346 (defun mime-mailcap-method-sentinel (process event)
347   (let ((file (cdr (assq process mime-mailcap-method-filename-alist))))
348     (if (file-exists-p file)
349         (delete-file file)
350       ))
351   (remove-alist 'mime-mailcap-method-filename-alist process)
352   (message (format "%s %s" process event)))
353
354 (defvar mime-echo-window-is-shared-with-bbdb
355   (module-installed-p 'bbdb)
356   "*If non-nil, mime-echo window is shared with BBDB window.")
357
358 (defvar mime-echo-window-height
359   (function
360    (lambda ()
361      (/ (window-height) 5)
362      ))
363   "*Size of mime-echo window.
364 It allows function or integer.  If it is function,
365 `mime-show-echo-buffer' calls it to get height of mime-echo window.
366 Otherwise `mime-show-echo-buffer' uses it as height of mime-echo
367 window.")
368
369 (defun mime-show-echo-buffer (&rest forms)
370   "Show mime-echo buffer to display MIME-playing information."
371   (get-buffer-create mime-echo-buffer-name)
372   (let ((the-win (selected-window))
373         (win (get-buffer-window mime-echo-buffer-name)))
374     (unless win
375       (unless (and mime-echo-window-is-shared-with-bbdb
376                    (condition-case nil
377                        (setq win (get-buffer-window bbdb-buffer-name))
378                      (error nil)))
379         (select-window (get-buffer-window mime-preview-buffer))
380         (setq win (split-window-vertically
381                    (- (window-height)
382                       (if (functionp mime-echo-window-height)
383                           (funcall mime-echo-window-height)
384                         mime-echo-window-height)
385                       )))
386         )
387       (set-window-buffer win mime-echo-buffer-name)
388       )
389     (select-window win)
390     (goto-char (point-max))
391     (if forms
392         (insert (apply (function format) forms))
393       )
394     (select-window the-win)
395     ))
396
397
398 ;;; @ file name
399 ;;;
400
401 (defvar mime-view-file-name-char-regexp "[A-Za-z0-9+_-]")
402
403 (defvar mime-view-file-name-regexp-1
404   (concat mime-view-file-name-char-regexp "+\\."
405           mime-view-file-name-char-regexp "+"))
406
407 (defvar mime-view-file-name-regexp-2
408   (concat (regexp-* mime-view-file-name-char-regexp)
409           "\\(\\." mime-view-file-name-char-regexp "+\\)*"))
410
411 (defun mime-entity-safe-filename (entity)
412   (let ((filename
413          (or (mime-entity-filename entity)
414              (let ((subj
415                     (or (mime-read-field 'Content-Description entity)
416                         (mime-read-field 'Subject entity))))
417                (if (and subj
418                         (or (string-match mime-view-file-name-regexp-1 subj)
419                             (string-match mime-view-file-name-regexp-2 subj)))
420                    (substring subj (match-beginning 0)(match-end 0))
421                  )))))
422     (if filename
423         (replace-as-filename filename)
424       )))
425
426
427 ;;; @ file extraction
428 ;;;
429
430 (defun mime-save-content (entity situation)
431   (let* ((name (mime-entity-safe-filename entity))
432          (filename (if (and name (not (string-equal name "")))
433                        (expand-file-name name
434                                          (save-window-excursion
435                                            (call-interactively
436                                             (function
437                                              (lambda (dir)
438                                                (interactive "DDirectory: ")
439                                                dir)))))
440                      (save-window-excursion
441                        (call-interactively
442                         (function
443                          (lambda (file)
444                            (interactive "FFilename: ")
445                            (expand-file-name file)))))))
446          )
447     (if (file-exists-p filename)
448         (or (yes-or-no-p (format "File %s exists. Save anyway? " filename))
449             (error "")))
450     (mime-write-entity-content entity filename)
451     ))
452
453
454 ;;; @ file detection
455 ;;;
456
457 (defvar mime-magic-type-alist
458   '(("^\377\330\377[\340\356]..JFIF"    image jpeg)
459     ("^\211PNG"                         image png)
460     ("^GIF8[79]"                        image gif)
461     ("^II\\*\000"                       image tiff)
462     ("^MM\000\\*"                       image tiff)
463     ("^MThd"                            audio midi)
464     ("^\000\000\001\263"                video mpeg)
465     )
466   "*Alist of regexp about magic-number vs. corresponding media-types.
467 Each element looks like (REGEXP TYPE SUBTYPE).
468 REGEXP is a regular expression to match against the beginning of the
469 content of entity.
470 TYPE is symbol to indicate primary type of media-type.
471 SUBTYPE is symbol to indicate subtype of media-type.")
472
473 (defun mime-detect-content (entity situation)
474   (let (type subtype)
475     (let ((mdata (save-excursion
476                    ;;(set-buffer (mime-entity-buffer entity))
477                    (let* ((start (mime-entity-body-start entity))
478                           (end (progn
479                                  (goto-char start)
480                                  (end-of-line)
481                                  (point))))
482                      (mime-decode-string (buffer-substring start end)
483                                          (mime-entity-encoding entity))
484                      )))
485           (rest mime-magic-type-alist))
486       (while (not (let ((cell (car rest)))
487                     (if cell
488                         (if (string-match (car cell) mdata)
489                             (setq type (nth 1 cell)
490                                   subtype (nth 2 cell))
491                           )
492                       t)))
493         (setq rest (cdr rest))))
494     (if type
495         (mime-raw-play-entity
496          entity nil
497          (put-alist 'type type
498                     (put-alist 'subtype subtype
499                                (del-alist 'method
500                                           (copy-alist situation))))
501          (cdr (assq 'ignore-examples situation))
502          'mime-detect-content)
503       ))
504   )
505
506
507 ;;; @ mail/news message
508 ;;;
509
510 (defun mime-preview-quitting-method-for-mime-show-message-mode ()
511   "Quitting method for mime-view.
512 It is registered to variable `mime-preview-quitting-method-alist'."
513   (let ((mother mime-mother-buffer)
514         (win-conf mime-preview-original-window-configuration)
515         )
516     (kill-buffer mime-raw-buffer)
517     (mime-preview-kill-buffer)
518     (set-window-configuration win-conf)
519     (pop-to-buffer mother)
520     ))
521
522 (defun mime-view-message/rfc822 (entity situation)
523   (let* ((new-name
524           (format "%s-%s" (buffer-name) (mime-entity-number entity)))
525          (mother mime-preview-buffer)
526          (children (car (mime-entity-children entity))))
527     (set-buffer (get-buffer-create new-name))
528     (erase-buffer)
529     (insert-buffer-substring (mime-entity-buffer children)
530                              (mime-entity-point-min children)
531                              (mime-entity-point-max children))
532     (setq mime-message-structure children)
533     (setq major-mode 'mime-show-message-mode)
534     (mime-view-buffer (current-buffer) nil mother
535                       nil (if (mime-entity-cooked-p entity) 'cooked))
536     ))
537
538
539 ;;; @ message/partial
540 ;;;
541
542 (defun mime-store-message/partial-piece (entity cal)
543   (goto-char (mime-entity-point-min entity))
544   (let* ((root-dir
545           (expand-file-name
546            (concat "m-prts-" (user-login-name)) temporary-file-directory))
547          (id (cdr (assoc "id" cal)))
548          (number (cdr (assoc "number" cal)))
549          (total (cdr (assoc "total" cal)))
550          file
551          (mother mime-preview-buffer)
552          )
553     (or (file-exists-p root-dir)
554         (make-directory root-dir)
555         )
556     (setq id (replace-as-filename id))
557     (setq root-dir (concat root-dir "/" id))
558     (or (file-exists-p root-dir)
559         (make-directory root-dir)
560         )
561     (setq file (concat root-dir "/FULL"))
562     (if (file-exists-p file)
563         (let ((full-buf (get-buffer-create "FULL"))
564               (pwin (or (get-buffer-window mother)
565                         (get-largest-window)))
566               )
567           (save-window-excursion
568             (set-buffer full-buf)
569             (erase-buffer)
570             (as-binary-input-file (insert-file-contents file))
571             (setq major-mode 'mime-show-message-mode)
572             (mime-view-buffer (current-buffer) nil mother)
573             )
574           (set-window-buffer pwin
575                              (save-excursion
576                                (set-buffer full-buf)
577                                mime-preview-buffer))
578           (select-window pwin)
579           )
580       (setq file (concat root-dir "/" number))
581       (mime-write-entity-body entity file)
582       (let ((total-file (concat root-dir "/CT")))
583         (setq total
584               (if total
585                   (progn
586                     (or (file-exists-p total-file)
587                         (save-excursion
588                           (set-buffer
589                            (get-buffer-create mime-temp-buffer-name))
590                           (erase-buffer)
591                           (insert total)
592                           (write-region (point-min)(point-max) total-file)
593                           (kill-buffer (current-buffer))
594                           ))
595                     (string-to-number total)
596                     )
597                 (and (file-exists-p total-file)
598                      (save-excursion
599                        (set-buffer (find-file-noselect total-file))
600                        (prog1
601                            (and (re-search-forward "[0-9]+" nil t)
602                                 (string-to-number
603                                  (buffer-substring (match-beginning 0)
604                                                    (match-end 0)))
605                                 )
606                          (kill-buffer (current-buffer))
607                          )))
608                 )))
609       (if (and total (> total 0))
610           (catch 'tag
611             (save-excursion
612               (set-buffer (get-buffer-create mime-temp-buffer-name))
613               (let ((full-buf (current-buffer)))
614                 (erase-buffer)
615                 (let ((i 1))
616                   (while (<= i total)
617                     (setq file (concat root-dir "/" (int-to-string i)))
618                     (or (file-exists-p file)
619                         (throw 'tag nil)
620                         )
621                     (as-binary-input-file (insert-file-contents file))
622                     (goto-char (point-max))
623                     (setq i (1+ i))
624                     ))
625                 (as-binary-output-file
626                  (write-region (point-min)(point-max)
627                                (expand-file-name "FULL" root-dir)))
628                 (let ((i 1))
629                   (while (<= i total)
630                     (let ((file (format "%s/%d" root-dir i)))
631                       (and (file-exists-p file)
632                            (delete-file file)
633                            ))
634                     (setq i (1+ i))
635                     ))
636                 (let ((file (expand-file-name "CT" root-dir)))
637                   (and (file-exists-p file)
638                        (delete-file file)
639                        ))
640                 (save-window-excursion
641                   (setq major-mode 'mime-show-message-mode)
642                   (mime-view-buffer (current-buffer) nil mother)
643                   )
644                 (let ((pwin (or (get-buffer-window mother)
645                                 (get-largest-window)))
646                       (pbuf (save-excursion
647                               (set-buffer full-buf)
648                               mime-preview-buffer)))
649                   (set-window-buffer pwin pbuf)
650                   (select-window pwin)
651                   )))))
652       )))
653
654
655 ;;; @ message/external-body
656 ;;;
657
658 (defvar mime-raw-dired-function
659   (if (and (>= emacs-major-version 19) window-system)
660       (function dired-other-frame)
661     (function mime-raw-dired-function-for-one-frame)
662     ))
663
664 (defun mime-raw-dired-function-for-one-frame (dir)
665   (let ((win (or (get-buffer-window mime-preview-buffer)
666                  (get-largest-window))))
667     (select-window win)
668     (dired dir)
669     ))
670
671 (defun mime-view-message/external-anon-ftp (entity cal)
672   (let* ((site (cdr (assoc "site" cal)))
673          (directory (cdr (assoc "directory" cal)))
674          (name (cdr (assoc "name" cal)))
675          (pathname (concat "/anonymous@" site ":" directory)))
676     (message (concat "Accessing " (expand-file-name name pathname) " ..."))
677     (funcall mime-raw-dired-function pathname)
678     (goto-char (point-min))
679     (search-forward name)
680     ))
681
682 (defvar mime-raw-browse-url-function (function mime-browse-url))
683
684 (defun mime-view-message/external-url (entity cal)
685   (let ((url (cdr (assoc "url" cal))))
686     (message (concat "Accessing " url " ..."))
687     (funcall mime-raw-browse-url-function url)))
688
689
690 ;;; @ rot13-47
691 ;;;
692
693 (defun mime-view-caesar (entity situation)
694   "Internal method for mime-view to display ROT13-47-48 message."
695   (let* ((new-name (format "%s-%s" (buffer-name)
696                            (mime-entity-number entity)))
697          (mother mime-preview-buffer))
698     (let ((pwin (or (get-buffer-window mother)
699                     (get-largest-window)))
700           (buf (get-buffer-create new-name)))
701       (set-window-buffer pwin buf)
702       (set-buffer buf)
703       (select-window pwin)
704       )
705     (setq buffer-read-only nil)
706     (erase-buffer)
707     (mime-insert-text-content entity)
708     (mule-caesar-region (point-min) (point-max))
709     (set-buffer-modified-p nil)
710     (set-buffer mother)
711     (view-buffer new-name)
712     ))
713
714
715 ;;; @ end
716 ;;;
717
718 (provide 'mime-play)
719
720 (let* ((file mime-acting-situation-examples-file)
721        (buffer (get-buffer-create " *mime-example*")))
722   (if (file-readable-p file)
723       (unwind-protect
724           (save-excursion
725             (set-buffer buffer)
726             (erase-buffer)
727             (insert-file-contents file)
728             (eval-buffer)
729             ;; format check
730             (condition-case nil
731                 (let ((i 0))
732                   (while (and (> (length mime-acting-situation-example-list)
733                                  mime-acting-situation-example-list-max-size)
734                               (< i 16))
735                     (mime-reduce-acting-situation-examples)
736                     (setq i (1+ i))
737                     ))
738               (error (setq mime-acting-situation-example-list nil)))
739             )
740         (kill-buffer buffer))))
741
742 ;;; mime-play.el ends here