(pgg-parse-public-key-encrypted-session-key-packet): Rename tag
[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
163                (get-text-property (point) 'mime-view-situation)))
164           (or mode
165               (setq mode "play"))
166           (setq situation 
167                 (if (assq 'mode situation)
168                     (put-alist 'mode mode (copy-alist situation))
169                   (cons (cons 'mode mode)
170                         situation)))
171           (if ignore-examples
172               (setq situation
173                     (cons (cons 'ignore-examples ignore-examples)
174                           situation)))
175           (mime-play-entity entity situation)
176           ))))
177
178 (defun mime-sort-situation (situation)
179   (sort situation
180         #'(lambda (a b)
181             (let ((a-t (car a))
182                   (b-t (car b))
183                   (order '((type . 1)
184                            (subtype . 2)
185                            (mode . 3)
186                            (method . 4)
187                            (major-mode . 5)
188                            (disposition-type . 6)
189                            ))
190                   a-order b-order)
191               (if (symbolp a-t)
192                   (let ((ret (assq a-t order)))
193                     (if ret
194                         (setq a-order (cdr ret))
195                       (setq a-order 7)
196                       ))
197                 (setq a-order 8)
198                 )
199               (if (symbolp b-t)
200                   (let ((ret (assq b-t order)))
201                     (if ret
202                         (setq b-order (cdr ret))
203                       (setq b-order 7)
204                       ))
205                 (setq b-order 8)
206                 )
207               (if (= a-order b-order)
208                   (string< (format "%s" a-t)(format "%s" b-t))
209                 (< a-order b-order))
210               )))
211   )
212
213 (defsubst mime-delq-null-situation (situations field
214                                                &optional ignored-value)
215   (let (dest)
216     (while situations
217       (let* ((situation (car situations))
218              (cell (assq field situation)))
219         (if cell
220             (or (eq (cdr cell) ignored-value)
221                 (setq dest (cons situation dest))
222                 )))
223       (setq situations (cdr situations)))
224     dest))
225
226 (defun mime-compare-situation-with-example (situation example)
227   (let ((example (copy-alist example))
228         (match 0))
229     (while situation
230       (let* ((cell (car situation))
231              (key (car cell))
232              (ecell (assoc key example)))
233         (when ecell
234           (if (equal cell ecell)
235               (setq match (1+ match))
236             (setq example (delq ecell example))
237             ))
238         )
239       (setq situation (cdr situation))
240       )
241     (cons match example)
242     ))
243
244 ;;;###autoload
245 (defun mime-play-entity (entity &optional situation ignored-method)
246   "Play entity specified by ENTITY.
247 It decodes the entity to call internal or external method.  The method
248 is selected from variable `mime-acting-condition'.  If MODE is
249 specified, play as it.  Default MODE is \"play\"."
250   (let (method ret)
251     (in-calist-package 'mime-view)
252     (setq ret
253           (mime-delq-null-situation
254            (ctree-find-calist mime-acting-condition
255                               (mime-entity-situation entity situation)
256                               mime-view-find-every-acting-situation)
257            'method ignored-method))
258     (or (assq 'ignore-examples situation)
259         (if (cdr ret)
260             (let ((rest ret)
261                   (max-score 0)
262                   (max-escore 0)
263                   max-examples
264                   max-situations)
265               (while rest
266                 (let ((situation (car rest))
267                       (examples mime-acting-situation-example-list))
268                   (while examples
269                     (let* ((ret
270                             (mime-compare-situation-with-example
271                              situation (caar examples)))
272                            (ret-score (car ret)))
273                       (cond ((> ret-score max-score)
274                              (setq max-score ret-score
275                                    max-escore (cdar examples)
276                                    max-examples (list (cdr ret))
277                                    max-situations (list situation))
278                              )
279                             ((= ret-score max-score)
280                              (cond ((> (cdar examples) max-escore)
281                                     (setq max-escore (cdar examples)
282                                           max-examples (list (cdr ret))
283                                           max-situations (list situation))
284                                     )
285                                    ((= (cdar examples) max-escore)
286                                     (setq max-examples
287                                           (cons (cdr ret) max-examples))
288                                     (or (member situation max-situations)
289                                         (setq max-situations
290                                               (cons situation max-situations)))
291                                     )))))
292                     (setq examples (cdr examples))))
293                 (setq rest (cdr rest)))
294               (when max-situations
295                 (setq ret max-situations)
296                 (while max-examples
297                   (let* ((example (car max-examples))
298                          (cell
299                           (assoc example mime-acting-situation-example-list)))
300                     (if cell
301                         (setcdr cell (1+ (cdr cell)))
302                       (setq mime-acting-situation-example-list
303                             (cons (cons example 0)
304                                   mime-acting-situation-example-list))
305                       ))
306                   (setq max-examples (cdr max-examples))
307                   )))))
308     (cond ((cdr ret)
309            (setq ret (select-menu-alist
310                       "Methods"
311                       (mapcar (function
312                                (lambda (situation)
313                                  (cons
314                                   (format "%s"
315                                           (cdr (assq 'method situation)))
316                                   situation)))
317                               ret)))
318            (setq ret (mime-sort-situation ret))
319            (add-to-list 'mime-acting-situation-example-list (cons ret 0))
320            )
321           (t
322            (setq ret (car ret))
323            ))
324     (setq method (cdr (assq 'method ret)))
325     (cond ((and (symbolp method)
326                 (fboundp method))
327            (funcall method entity ret)
328            )
329           ((stringp method)
330            (mime-activate-mailcap-method entity ret)
331            )
332           ;; ((and (listp method)(stringp (car method)))
333           ;;  (mime-activate-external-method entity ret)
334           ;;  )
335           (t
336            (mime-show-echo-buffer "No method are specified for %s\n"
337                                   (mime-type/subtype-string
338                                    (cdr (assq 'type situation))
339                                    (cdr (assq 'subtype situation))))
340            (if (y-or-n-p "Do you want to save current entity to disk?")
341                (mime-save-content entity situation))
342            ))
343     ))
344
345
346 ;;; @ external decoder
347 ;;;
348
349 (defvar mime-mailcap-method-filename-alist nil)
350
351 (defun mime-activate-mailcap-method (entity situation)
352   (let ((method (cdr (assoc 'method situation)))
353         (name (mime-entity-safe-filename entity)))
354     (setq name
355           (if (and name (not (string= name "")))
356               (expand-file-name name temporary-file-directory)
357             (make-temp-name
358              (expand-file-name "EMI" temporary-file-directory))
359             ))
360     (mime-write-entity-content entity name)
361     (message "External method is starting...")
362     (let ((process
363            (let ((command
364                   (mailcap-format-command
365                    method
366                    (cons (cons 'filename name) situation))))
367              (start-process command mime-echo-buffer-name
368                             shell-file-name shell-command-switch command)
369              )))
370       (set-alist 'mime-mailcap-method-filename-alist process name)
371       (set-process-sentinel process 'mime-mailcap-method-sentinel)
372       )
373     ))
374
375 (defun mime-mailcap-method-sentinel (process event)
376   (let ((file (cdr (assq process mime-mailcap-method-filename-alist))))
377     (if (file-exists-p file)
378         (delete-file file)
379       ))
380   (remove-alist 'mime-mailcap-method-filename-alist process)
381   (message (format "%s %s" process event)))
382
383 (defvar mime-echo-window-is-shared-with-bbdb
384   (module-installed-p 'bbdb)
385   "*If non-nil, mime-echo window is shared with BBDB window.")
386
387 (defvar mime-echo-window-height
388   (function
389    (lambda ()
390      (/ (window-height) 5)
391      ))
392   "*Size of mime-echo window.
393 It allows function or integer.  If it is function,
394 `mime-show-echo-buffer' calls it to get height of mime-echo window.
395 Otherwise `mime-show-echo-buffer' uses it as height of mime-echo
396 window.")
397
398 (defun mime-show-echo-buffer (&rest forms)
399   "Show mime-echo buffer to display MIME-playing information."
400   (get-buffer-create mime-echo-buffer-name)
401   (let ((the-win (selected-window))
402         (win (get-buffer-window mime-echo-buffer-name)))
403     (unless win
404       (unless (and mime-echo-window-is-shared-with-bbdb
405                    (condition-case nil
406                        (setq win (get-buffer-window bbdb-buffer-name))
407                      (error nil)))
408         (select-window (get-buffer-window (or mime-preview-buffer
409                                               (current-buffer))))
410         (setq win (split-window-vertically
411                    (- (window-height)
412                       (if (functionp mime-echo-window-height)
413                           (funcall mime-echo-window-height)
414                         mime-echo-window-height)
415                       )))
416         )
417       (set-window-buffer win mime-echo-buffer-name)
418       )
419     (select-window win)
420     (goto-char (point-max))
421     (if forms
422         (let ((buffer-read-only nil))
423           (insert (apply (function format) forms))
424           ))
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     (setq situation (del-alist 'method (copy-alist situation)))
517     (mime-play-entity entity
518                       (if type
519                           (put-alist 'type type
520                                      (put-alist 'subtype subtype
521                                                 situation))
522                         situation)
523                       'mime-detect-content)))
524
525
526 ;;; @ mail/news message
527 ;;;
528
529 (defun mime-preview-quitting-method-for-mime-show-message-mode ()
530   "Quitting method for mime-view.
531 It is registered to variable `mime-preview-quitting-method-alist'."
532   (let ((raw-buffer (mime-entity-buffer
533                      (get-text-property (point-min) 'mime-view-entity)))
534         (mother mime-mother-buffer)
535         (win-conf mime-preview-original-window-configuration))
536     (kill-buffer raw-buffer)
537     (mime-preview-kill-buffer)
538     (set-window-configuration win-conf)
539     (pop-to-buffer mother)
540     ))
541
542 (defun mime-view-message/rfc822 (entity situation)
543   (let* ((new-name
544           (format "%s-%s" (buffer-name) (mime-entity-number entity)))
545          (mother (current-buffer))
546          (children (car (mime-entity-children entity)))
547          (preview-buffer
548           (mime-display-message
549            children new-name mother nil
550            (cdr (assq 'major-mode
551                       (get-text-property (point) 'mime-view-situation))))))
552     (or (get-buffer-window preview-buffer)
553         (let ((m-win (get-buffer-window mother)))
554           (if m-win
555               (set-window-buffer m-win preview-buffer)
556             (switch-to-buffer preview-buffer)
557             )))))
558
559
560 ;;; @ message/partial
561 ;;;
562
563 (defun mime-store-message/partial-piece (entity cal)
564   (let* ((root-dir
565           (expand-file-name
566            (concat "m-prts-" (user-login-name)) temporary-file-directory))
567          (id (cdr (assoc "id" cal)))
568          (number (cdr (assoc "number" cal)))
569          (total (cdr (assoc "total" cal)))
570          file
571          (mother (current-buffer)))
572     (or (file-exists-p root-dir)
573         (make-directory root-dir))
574     (setq id (replace-as-filename id))
575     (setq root-dir (concat root-dir "/" id))
576     (or (file-exists-p root-dir)
577         (make-directory root-dir))
578     (setq file (concat root-dir "/FULL"))
579     (if (file-exists-p file)
580         (let ((full-buf (get-buffer-create "FULL"))
581               (pwin (or (get-buffer-window mother)
582                         (get-largest-window)))
583               pbuf)
584           (save-window-excursion
585             (set-buffer full-buf)
586             (erase-buffer)
587             (as-binary-input-file (insert-file-contents file))
588             (setq major-mode 'mime-show-message-mode)
589             (mime-view-buffer (current-buffer) nil mother)
590             (setq pbuf (current-buffer))
591             )
592           (set-window-buffer pwin pbuf)
593           (select-window pwin)
594           )
595       (setq file (concat root-dir "/" number))
596       (mime-write-entity-body entity file)
597       (let ((total-file (concat root-dir "/CT")))
598         (setq total
599               (if total
600                   (progn
601                     (or (file-exists-p total-file)
602                         (save-excursion
603                           (set-buffer
604                            (get-buffer-create mime-temp-buffer-name))
605                           (erase-buffer)
606                           (insert total)
607                           (write-region (point-min)(point-max) total-file)
608                           (kill-buffer (current-buffer))
609                           ))
610                     (string-to-number total)
611                     )
612                 (and (file-exists-p total-file)
613                      (save-excursion
614                        (set-buffer (find-file-noselect total-file))
615                        (prog1
616                            (and (re-search-forward "[0-9]+" nil t)
617                                 (string-to-number
618                                  (buffer-substring (match-beginning 0)
619                                                    (match-end 0)))
620                                 )
621                          (kill-buffer (current-buffer))
622                          )))
623                 )))
624       (if (and total (> total 0)
625                (>= (length (directory-files root-dir nil "^[0-9]+$" t))
626                    total))
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                 (let ((pwin (or (get-buffer-window mother)
658                                 (get-largest-window)))
659                       (pbuf (mime-display-message
660                              (mime-open-entity 'buffer (current-buffer))
661                              nil mother nil 'mime-show-message-mode)))
662                   (set-window-buffer pwin pbuf)
663                   (select-window pwin)
664                   )))))
665       )))
666
667
668 ;;; @ message/external-body
669 ;;;
670
671 (defvar mime-raw-dired-function
672   (if (and (>= emacs-major-version 19) window-system)
673       (function dired-other-frame)
674     (function mime-raw-dired-function-for-one-frame)
675     ))
676
677 (defun mime-raw-dired-function-for-one-frame (dir)
678   (let ((win (or (get-buffer-window mime-preview-buffer)
679                  (get-largest-window))))
680     (select-window win)
681     (dired dir)
682     ))
683
684 (defun mime-view-message/external-anon-ftp (entity cal)
685   (let* ((site (cdr (assoc "site" cal)))
686          (directory (cdr (assoc "directory" cal)))
687          (name (cdr (assoc "name" cal)))
688          (pathname (concat "/anonymous@" site ":" directory)))
689     (message (concat "Accessing " (expand-file-name name pathname) " ..."))
690     (funcall mime-raw-dired-function pathname)
691     (goto-char (point-min))
692     (search-forward name)
693     ))
694
695 (defvar mime-raw-browse-url-function mime-browse-url-function)
696
697 (defun mime-view-message/external-url (entity cal)
698   (let ((url (cdr (assoc "url" cal))))
699     (message (concat "Accessing " url " ..."))
700     (funcall mime-raw-browse-url-function url)))
701
702
703 ;;; @ rot13-47
704 ;;;
705
706 (defun mime-view-caesar (entity situation)
707   "Internal method for mime-view to display ROT13-47-48 message."
708   (let ((buf (get-buffer-create
709               (format "%s-%s" (buffer-name) (mime-entity-number entity)))))
710     (with-current-buffer buf
711       (setq buffer-read-only nil)
712       (erase-buffer)
713       (mime-insert-text-content entity)
714       (mule-caesar-region (point-min) (point-max))
715       (set-buffer-modified-p nil)
716       )
717     (let ((win (get-buffer-window (current-buffer))))
718       (or (eq (selected-window) win)
719           (select-window (or win (get-largest-window)))
720           ))
721     (view-buffer buf)
722     (goto-char (point-min))
723     ))
724
725
726 ;;; @ end
727 ;;;
728
729 (provide 'mime-play)
730
731 (let* ((file mime-acting-situation-examples-file)
732        (buffer (get-buffer-create " *mime-example*")))
733   (if (file-readable-p file)
734       (unwind-protect
735           (save-excursion
736             (set-buffer buffer)
737             (erase-buffer)
738             (insert-file-contents file)
739             (eval-buffer)
740             ;; format check
741             (condition-case nil
742                 (let ((i 0))
743                   (while (and (> (length mime-acting-situation-example-list)
744                                  mime-acting-situation-example-list-max-size)
745                               (< i 16))
746                     (mime-reduce-acting-situation-examples)
747                     (setq i (1+ i))
748                     ))
749               (error (setq mime-acting-situation-example-list nil)))
750             )
751         (kill-buffer buffer))))
752
753 ;;; mime-play.el ends here