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