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