Sync up with the latest semi-1_13 branch.
[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     (in-calist-package 'mime-view)
244     (setq ret
245           (mime-delq-null-situation
246            (ctree-find-calist mime-acting-condition
247                               (mime-entity-situation entity situation)
248                               mime-view-find-every-acting-situation)
249            'method ignored-method))
250     (or (assq 'ignore-examples situation)
251         (if (cdr ret)
252             (let ((rest ret)
253                   (max-score 0)
254                   (max-escore 0)
255                   max-examples
256                   max-situations)
257               (while rest
258                 (let ((situation (car rest))
259                       (examples mime-acting-situation-example-list))
260                   (while examples
261                     (let* ((ret
262                             (mime-compare-situation-with-example
263                              situation (caar examples)))
264                            (ret-score (car ret)))
265                       (cond ((> ret-score max-score)
266                              (setq max-score ret-score
267                                    max-escore (cdar examples)
268                                    max-examples (list (cdr ret))
269                                    max-situations (list situation))
270                              )
271                             ((= ret-score max-score)
272                              (cond ((> (cdar examples) max-escore)
273                                     (setq max-escore (cdar examples)
274                                           max-examples (list (cdr ret))
275                                           max-situations (list situation))
276                                     )
277                                    ((= (cdar examples) max-escore)
278                                     (setq max-examples
279                                           (cons (cdr ret) max-examples))
280                                     (or (member situation max-situations)
281                                         (setq max-situations
282                                               (cons situation max-situations)))
283                                     )))))
284                     (setq examples (cdr examples))))
285                 (setq rest (cdr rest)))
286               (when max-situations
287                 (setq ret max-situations)
288                 (while max-examples
289                   (let* ((example (car max-examples))
290                          (cell
291                           (assoc example mime-acting-situation-example-list)))
292                     (if cell
293                         (setcdr cell (1+ (cdr cell)))
294                       (setq mime-acting-situation-example-list
295                             (cons (cons example 0)
296                                   mime-acting-situation-example-list))
297                       ))
298                   (setq max-examples (cdr max-examples))
299                   )))))
300     (cond ((cdr ret)
301            (setq ret (select-menu-alist
302                       "Methods"
303                       (mapcar (function
304                                (lambda (situation)
305                                  (cons
306                                   (format "%s"
307                                           (cdr (assq 'method situation)))
308                                   situation)))
309                               ret)))
310            (setq ret (mime-sort-situation ret))
311            (add-to-list 'mime-acting-situation-example-list (cons ret 0))
312            )
313           (t
314            (setq ret (car ret))
315            ))
316     (setq method (cdr (assq 'method ret)))
317     (cond ((and (symbolp method)
318                 (fboundp method))
319            (funcall method entity ret)
320            )
321           ((stringp method)
322            (mime-activate-mailcap-method entity ret)
323            )
324           ;; ((and (listp method)(stringp (car method)))
325           ;;  (mime-activate-external-method entity ret)
326           ;;  )
327           (t
328            (mime-show-echo-buffer "No method are specified for %s\n"
329                                   (mime-entity-type/subtype entity))
330            ))
331     ))
332
333
334 ;;; @ external decoder
335 ;;;
336
337 (defvar mime-mailcap-method-filename-alist nil)
338
339 (defun mime-activate-mailcap-method (entity situation)
340   (let ((method (cdr (assoc 'method situation)))
341         (name (mime-entity-safe-filename entity)))
342     (setq name
343           (if (and name (not (string= name "")))
344               (expand-file-name name temporary-file-directory)
345             (make-temp-name
346              (expand-file-name "EMI" temporary-file-directory))
347             ))
348     (mime-write-entity-content entity name)
349     (message "External method is starting...")
350     (let ((process
351            (let ((command
352                   (mailcap-format-command
353                    method
354                    (cons (cons 'filename name) situation))))
355              (start-process command mime-echo-buffer-name
356                             shell-file-name shell-command-switch command)
357              )))
358       (set-alist 'mime-mailcap-method-filename-alist process name)
359       (set-process-sentinel process 'mime-mailcap-method-sentinel)
360       )
361     ))
362
363 (defun mime-mailcap-method-sentinel (process event)
364   (let ((file (cdr (assq process mime-mailcap-method-filename-alist))))
365     (if (file-exists-p file)
366         (delete-file file)
367       ))
368   (remove-alist 'mime-mailcap-method-filename-alist process)
369   (message (format "%s %s" process event)))
370
371 (defvar mime-echo-window-is-shared-with-bbdb
372   (module-installed-p 'bbdb)
373   "*If non-nil, mime-echo window is shared with BBDB window.")
374
375 (defvar mime-echo-window-height
376   (function
377    (lambda ()
378      (/ (window-height) 5)
379      ))
380   "*Size of mime-echo window.
381 It allows function or integer.  If it is function,
382 `mime-show-echo-buffer' calls it to get height of mime-echo window.
383 Otherwise `mime-show-echo-buffer' uses it as height of mime-echo
384 window.")
385
386 (defun mime-show-echo-buffer (&rest forms)
387   "Show mime-echo buffer to display MIME-playing information.
388 It returns the list of window, start and end positions of inserted text.
389 A window height of the buffer `mime-echo-buffer-name' will be determined
390 by `mime-echo-window-height' (its value or its return value) whenever
391 this function is called."
392   (get-buffer-create mime-echo-buffer-name)
393   (let ((the-win (selected-window))
394         (win (get-buffer-window mime-echo-buffer-name))
395         (height (if (functionp mime-echo-window-height)
396                     (funcall mime-echo-window-height)
397                   mime-echo-window-height))
398         start)
399     (if win
400         (progn
401           (select-window win)
402           (enlarge-window (- height (window-height)))
403           )
404       (unless (and mime-echo-window-is-shared-with-bbdb
405                    (condition-case nil
406                        (select-window
407                         (setq win (get-buffer-window bbdb-buffer-name))
408                         )
409                      (error nil)))
410         (select-window (get-buffer-window (or mime-preview-buffer
411                                               (current-buffer))))
412         (let ((window-min-height 1))
413           (setq win (split-window-vertically (- (window-height) height)))
414           )
415         (set-window-buffer win mime-echo-buffer-name)
416         (select-window win)
417         ))
418     (goto-char (setq start (point-max)))
419     (if forms
420         (let ((buffer-read-only nil))
421           (insert (apply (function format) forms))
422           ))
423     (prog1
424         (list win start (point))
425       (select-window the-win)
426       )))
427
428
429 ;;; @ file name
430 ;;;
431
432 (defvar mime-view-file-name-char-regexp "[A-Za-z0-9+_-]")
433
434 (defvar mime-view-file-name-regexp-1
435   (concat mime-view-file-name-char-regexp "+\\."
436           mime-view-file-name-char-regexp "+"))
437
438 (defvar mime-view-file-name-regexp-2
439   (concat (regexp-* mime-view-file-name-char-regexp)
440           "\\(\\." mime-view-file-name-char-regexp "+\\)*"))
441
442 (defun mime-entity-safe-filename (entity)
443   (let ((filename
444          (or (mime-entity-filename entity)
445              (let ((subj
446                     (or (mime-entity-read-field entity 'Content-Description)
447                         (mime-entity-read-field entity 'Subject))))
448                (if (and subj
449                         (or (string-match mime-view-file-name-regexp-1 subj)
450                             (string-match mime-view-file-name-regexp-2 subj)))
451                    (substring subj (match-beginning 0)(match-end 0))
452                  )))))
453     (if filename
454         (replace-as-filename filename)
455       )))
456
457
458 ;;; @ file extraction
459 ;;;
460
461 (defun mime-save-content (entity situation)
462   (let* ((name (mime-entity-safe-filename entity))
463          (filename (if (and name (not (string-equal name "")))
464                        (expand-file-name name
465                                          (save-window-excursion
466                                            (call-interactively
467                                             (function
468                                              (lambda (dir)
469                                                (interactive "DDirectory: ")
470                                                dir)))))
471                      (save-window-excursion
472                        (call-interactively
473                         (function
474                          (lambda (file)
475                            (interactive "FFilename: ")
476                            (expand-file-name file)))))))
477          )
478     (if (file-exists-p filename)
479         (or (yes-or-no-p (format "File %s exists. Save anyway? " filename))
480             (error "")))
481     (mime-write-entity-content entity filename)
482     ))
483
484
485 ;;; @ file detection
486 ;;;
487
488 (defvar mime-magic-type-alist
489   '(("^\377\330\377[\340\356]..JFIF"    image jpeg)
490     ("^\211PNG"                         image png)
491     ("^GIF8[79]"                        image gif)
492     ("^II\\*\000"                       image tiff)
493     ("^MM\000\\*"                       image tiff)
494     ("^MThd"                            audio midi)
495     ("^\000\000\001\263"                video mpeg)
496     )
497   "*Alist of regexp about magic-number vs. corresponding media-types.
498 Each element looks like (REGEXP TYPE SUBTYPE).
499 REGEXP is a regular expression to match against the beginning of the
500 content of entity.
501 TYPE is symbol to indicate primary type of media-type.
502 SUBTYPE is symbol to indicate subtype of media-type.")
503
504 (defun mime-detect-content (entity situation)
505   (let (type subtype)
506     (let ((mdata (mime-entity-content entity))
507           (rest mime-magic-type-alist))
508       (while (not (let ((cell (car rest)))
509                     (if cell
510                         (if (string-match (car cell) mdata)
511                             (setq type (nth 1 cell)
512                                   subtype (nth 2 cell))
513                           )
514                       t)))
515         (setq rest (cdr rest))))
516     (if type
517         (mime-play-entity
518          entity
519          (put-alist 'type type
520                     (put-alist 'subtype subtype
521                                (del-alist 'method
522                                           (copy-alist situation))))
523          'mime-detect-content)
524       ))
525   )
526
527
528 ;;; @ mail/news message
529 ;;;
530
531 (defun mime-preview-quitting-method-for-mime-show-message-mode ()
532   "Quitting method for mime-view.
533 It is registered to variable `mime-preview-quitting-method-alist'."
534   (let ((raw-buffer (mime-entity-buffer
535                      (get-text-property (point-min) 'mime-view-entity)))
536         (mother mime-mother-buffer)
537         (win-conf mime-preview-original-window-configuration))
538     (kill-buffer raw-buffer)
539     (mime-preview-kill-buffer)
540     (set-window-configuration win-conf)
541     (pop-to-buffer mother)
542     ))
543
544 (defun mime-view-message/rfc822 (entity situation)
545   (let* ((new-name
546           (format "%s-%s" (buffer-name) (mime-entity-number entity)))
547          (mother (current-buffer))
548          (children (car (mime-entity-children entity)))
549          (preview-buffer
550           (mime-display-message
551            children new-name mother nil
552            (cdr (assq 'major-mode
553                       (get-text-property (point) 'mime-view-situation))))))
554     (or (get-buffer-window preview-buffer)
555         (let ((m-win (get-buffer-window mother)))
556           (if m-win
557               (set-window-buffer m-win preview-buffer)
558             (switch-to-buffer preview-buffer)
559             )))))
560
561
562 ;;; @ message/partial
563 ;;;
564
565 (defun mime-store-message/partial-piece (entity cal)
566   (let* ((root-dir
567           (expand-file-name
568            (concat "m-prts-" (user-login-name)) temporary-file-directory))
569          (id (cdr (assoc "id" cal)))
570          (number (cdr (assoc "number" cal)))
571          (total (cdr (assoc "total" cal)))
572          file
573          (mother (current-buffer)))
574     (or (file-exists-p root-dir)
575         (make-directory root-dir))
576     (setq id (replace-as-filename id))
577     (setq root-dir (concat root-dir "/" id))
578     (or (file-exists-p root-dir)
579         (make-directory root-dir))
580     (setq file (concat root-dir "/FULL"))
581     (if (file-exists-p file)
582         (let ((full-buf (get-buffer-create "FULL"))
583               (pwin (or (get-buffer-window mother)
584                         (get-largest-window)))
585               pbuf)
586           (save-window-excursion
587             (set-buffer full-buf)
588             (erase-buffer)
589             (as-binary-input-file (insert-file-contents file))
590             (setq major-mode 'mime-show-message-mode)
591             (mime-view-buffer (current-buffer) nil mother)
592             (setq pbuf (current-buffer))
593             )
594           (set-window-buffer pwin pbuf)
595           (select-window pwin)
596           )
597       (setq file (concat root-dir "/" number))
598       (mime-write-entity-body entity file)
599       (let ((total-file (concat root-dir "/CT")))
600         (setq total
601               (if total
602                   (progn
603                     (or (file-exists-p total-file)
604                         (save-excursion
605                           (set-buffer
606                            (get-buffer-create mime-temp-buffer-name))
607                           (erase-buffer)
608                           (insert total)
609                           (write-region (point-min)(point-max) total-file)
610                           (kill-buffer (current-buffer))
611                           ))
612                     (string-to-number total)
613                     )
614                 (and (file-exists-p total-file)
615                      (save-excursion
616                        (set-buffer (find-file-noselect total-file))
617                        (prog1
618                            (and (re-search-forward "[0-9]+" nil t)
619                                 (string-to-number
620                                  (buffer-substring (match-beginning 0)
621                                                    (match-end 0)))
622                                 )
623                          (kill-buffer (current-buffer))
624                          )))
625                 )))
626       (if (and total (> total 0))
627           (catch 'tag
628             (save-excursion
629               (set-buffer (get-buffer-create mime-temp-buffer-name))
630               (let ((full-buf (current-buffer)))
631                 (erase-buffer)
632                 (let ((i 1))
633                   (while (<= i total)
634                     (setq file (concat root-dir "/" (int-to-string i)))
635                     (or (file-exists-p file)
636                         (throw 'tag nil)
637                         )
638                     (as-binary-input-file (insert-file-contents file))
639                     (goto-char (point-max))
640                     (setq i (1+ i))
641                     ))
642                 (as-binary-output-file
643                  (write-region (point-min)(point-max)
644                                (expand-file-name "FULL" root-dir)))
645                 (let ((i 1))
646                   (while (<= i total)
647                     (let ((file (format "%s/%d" root-dir i)))
648                       (and (file-exists-p file)
649                            (delete-file file)
650                            ))
651                     (setq i (1+ i))
652                     ))
653                 (let ((file (expand-file-name "CT" root-dir)))
654                   (and (file-exists-p file)
655                        (delete-file file)
656                        ))
657                 (save-window-excursion
658                   (setq major-mode 'mime-show-message-mode)
659                   (mime-view-buffer (current-buffer) nil mother)
660                   )
661                 (let ((pwin (or (get-buffer-window mother)
662                                 (get-largest-window)))
663                       (pbuf (save-excursion
664                               (set-buffer full-buf)
665                               mime-preview-buffer)))
666                   (set-window-buffer pwin pbuf)
667                   (select-window pwin)
668                   )))))
669       )))
670
671
672 ;;; @ message/external-body
673 ;;;
674
675 (defvar mime-raw-dired-function
676   (if (and (>= emacs-major-version 19) window-system)
677       (function dired-other-frame)
678     (function mime-raw-dired-function-for-one-frame)
679     ))
680
681 (defun mime-raw-dired-function-for-one-frame (dir)
682   (let ((win (or (get-buffer-window mime-preview-buffer)
683                  (get-largest-window))))
684     (select-window win)
685     (dired dir)
686     ))
687
688 (defun mime-view-message/external-anon-ftp (entity cal)
689   (let* ((site (cdr (assoc "site" cal)))
690          (directory (cdr (assoc "directory" cal)))
691          (name (cdr (assoc "name" cal)))
692          (pathname (concat "/anonymous@" site ":" directory)))
693     (message (concat "Accessing " (expand-file-name name pathname) " ..."))
694     (funcall mime-raw-dired-function pathname)
695     (goto-char (point-min))
696     (search-forward name)
697     ))
698
699 (defvar mime-raw-browse-url-function mime-browse-url-function)
700
701 (defun mime-view-message/external-url (entity cal)
702   (let ((url (cdr (assoc "url" cal))))
703     (message (concat "Accessing " url " ..."))
704     (funcall mime-raw-browse-url-function url)))
705
706
707 ;;; @ rot13-47
708 ;;;
709
710 (defun mime-view-caesar (entity situation)
711   "Internal method for mime-view to display ROT13-47-48 message."
712   (let ((buf (get-buffer-create
713               (format "%s-%s" (buffer-name) (mime-entity-number entity)))))
714     (with-current-buffer buf
715       (setq buffer-read-only nil)
716       (erase-buffer)
717       (mime-insert-text-content entity)
718       (mule-caesar-region (point-min) (point-max))
719       (set-buffer-modified-p nil)
720       )
721     (let ((win (get-buffer-window (current-buffer))))
722       (or (eq (selected-window) win)
723           (select-window (or win (get-largest-window)))
724           ))
725     (view-buffer buf)
726     (goto-char (point-min))
727     ))
728
729
730 ;;; @ end
731 ;;;
732
733 (provide 'mime-play)
734
735 (let* ((file mime-acting-situation-examples-file)
736        (buffer (get-buffer-create " *mime-example*")))
737   (if (file-readable-p file)
738       (unwind-protect
739           (save-excursion
740             (set-buffer buffer)
741             (erase-buffer)
742             (insert-file-contents file)
743             (eval-buffer)
744             ;; format check
745             (condition-case nil
746                 (let ((i 0))
747                   (while (and (> (length mime-acting-situation-example-list)
748                                  mime-acting-situation-example-list-max-size)
749                               (< i 16))
750                     (mime-reduce-acting-situation-examples)
751                     (setq i (1+ i))
752                     ))
753               (error (setq mime-acting-situation-example-list nil)))
754             )
755         (kill-buffer buffer))))
756
757 ;;; mime-play.el ends here