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