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