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