1 ;;; mime-play.el --- Playback processing module for mime-view.el
3 ;; Copyright (C) 1994,1995,1996,1997,1998 Free Software Foundation, Inc.
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
10 ;; This file is part of SEMI (Secretariat of Emacs MIME Interfaces).
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.
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.
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.
37 (defvar mime-preview/after-decoded-position nil)
39 (defun mime-view-play-current-entity (&optional mode)
41 It decodes current entity to call internal or external method. The
42 method is selected from variable `mime-acting-condition'.
43 If MODE is specified, play as it. Default MODE is \"play\"."
48 (let ((cinfo (get-text-property (point) 'mime-view-cinfo)))
50 (let ((the-buf (current-buffer))
51 (raw-buffer (get-text-property (point) 'mime-view-raw-buffer))
53 (setq mime-preview/after-decoded-position (point))
54 (set-buffer raw-buffer)
55 (mime-playback-entity cinfo mode)
56 (if (eq (current-buffer) raw-buffer)
59 (goto-char mime-preview/after-decoded-position)
63 (defun mime-playback-entity (cinfo &optional mode)
64 (let ((beg (mime-entity-info-point-min cinfo))
65 (end (mime-entity-info-point-max cinfo))
66 (ctype (or (mime-entity-info-type/subtype cinfo) "text/plain"))
67 (params (mime-entity-info-parameters cinfo))
68 (encoding (mime-entity-info-encoding cinfo))
71 (if (< beg (point-min))
72 (setq beg (point-min))
74 (if (< (point-max) end)
75 (setq end (point-max))
78 (setq cal (list* (cons 'type ctype)
79 (cons 'encoding encoding)
80 (cons 'major-mode major-mode)
83 (setq cal (cons (cons 'mode mode) cal))
85 (setq ret (mime/get-content-decoding-alist cal))
86 (setq method (cdr (assq 'method ret)))
87 (cond ((and (symbolp method)
89 (funcall method beg end ret)
91 ((and (listp method)(stringp (car method)))
92 (mime-article/start-external-method-region beg end ret)
95 (mime-show-echo-buffer
96 "No method are specified for %s\n" ctype)
102 ;;; @ method selector
105 (defun mime/get-content-decoding-alist (al)
106 (get-unified-alist mime-acting-condition al)
110 ;;; @ external decoder
113 (defun mime-article/start-external-method-region (beg end cal)
116 (narrow-to-region beg end)
118 (let ((method (cdr (assoc 'method cal)))
119 (name (mime-article/get-filename cal))
122 (let ((file (make-temp-name
123 (expand-file-name "TM" mime-temp-directory)))
128 (if (re-search-forward "^$" nil t)
134 (write-region b end file)
135 (message "External method is starting...")
137 'name (replace-as-filename name) cal))
138 (setq cal (put-alist 'file file cal))
141 mime-echo-buffer-name (car method)
143 (mime-article/make-method-args cal
146 (apply (function start-process) args)
147 (mime-show-echo-buffer)
151 (defun mime-article/make-method-args (cal format)
156 (let* ((item (eval arg))
157 (ret (cdr (assoc item cal)))
161 (if (eq item 'encoding)
168 (defvar mime-echo-window-is-shared-with-bbdb t
169 "*If non-nil, mime-echo window is shared with BBDB window.")
171 (defvar mime-echo-window-height
174 (/ (window-height) 5)
176 "*Size of mime-echo window.
177 It allows function or integer. If it is function,
178 `mime-show-echo-buffer' calls it to get height of mime-echo window.
179 Otherwise `mime-show-echo-buffer' uses it as height of mime-echo
182 (defun mime-show-echo-buffer (&rest forms)
183 "Show mime-echo buffer to display MIME-playing information."
184 (get-buffer-create mime-echo-buffer-name)
185 (let ((the-win (selected-window))
186 (win (get-buffer-window mime-echo-buffer-name))
189 (if (and mime-echo-window-is-shared-with-bbdb
190 (boundp 'bbdb-buffer-name)
191 (setq win (get-buffer-window bbdb-buffer-name))
193 (set-window-buffer win mime-echo-buffer-name)
194 (select-window (get-buffer-window mime-view-buffer))
195 (setq win (split-window-vertically
197 (if (functionp mime-echo-window-height)
198 (funcall mime-echo-window-height)
199 mime-echo-window-height)
201 (set-window-buffer win mime-echo-buffer-name)
204 (goto-char (point-max))
206 (insert (apply (function format) forms))
208 (select-window the-win)
215 (defvar mime-view-file-name-char-regexp "[A-Za-z0-9+_-]")
217 (defvar mime-view-file-name-regexp-1
218 (concat mime-view-file-name-char-regexp "+\\."
219 mime-view-file-name-char-regexp "+"))
221 (defvar mime-view-file-name-regexp-2
222 (concat (regexp-* mime-view-file-name-char-regexp)
223 "\\(\\." mime-view-file-name-char-regexp "+\\)*"))
225 (defun mime-article/get-original-filename (param &optional encoding)
226 (or (mime-article/get-uu-filename param encoding)
228 (or (if (or (and (setq ret (mime/Content-Disposition))
229 (setq ret (assoc "filename" (cdr ret)))
231 (setq ret (assoc "name" param))
232 (setq ret (assoc "x-name" param))
234 (std11-strip-quoted-string (cdr ret))
237 (std11-find-field-body '("Content-Description"
239 (if (or (string-match mime-view-file-name-regexp-1 ret)
240 (string-match mime-view-file-name-regexp-2 ret))
241 (substring ret (match-beginning 0)(match-end 0))
246 (defun mime-article/get-filename (param)
247 (replace-as-filename (mime-article/get-original-filename param))
251 ;;; @ mail/news message
254 (defun mime-view-quitting-method-for-mime-show-message-mode ()
255 "Quitting method for mime-view.
256 It is registered to variable `mime-view-quitting-method-alist'."
257 (let ((mother mime-mother-buffer)
258 (win-conf mime::preview/original-window-configuration)
260 (kill-buffer mime-raw-buffer)
261 (mime-view-kill-buffer)
262 (set-window-configuration win-conf)
263 (pop-to-buffer mother)
266 (defun mime-display-message/rfc822 (beg end cal)
267 (let* ((cnum (mime-article/point-content-number beg))
268 (new-name (format "%s-%s" (buffer-name) cnum))
269 (mother mime-view-buffer)
271 (cdr (or (assq major-mode mime-text-decoder-alist)
272 (assq t mime-text-decoder-alist))))
274 (setq str (buffer-substring beg end))
275 (switch-to-buffer new-name)
278 (goto-char (point-min))
279 (if (re-search-forward "^\n" nil t)
280 (delete-region (point-min) (match-end 0))
282 (setq major-mode 'mime-show-message-mode)
283 (setq mime-text-decoder text-decoder)
284 (mime-view-mode mother)
288 ;;; @ message/partial
291 (defvar mime-article/coding-system-alist
292 (list '(mh-show-mode . no-conversion)
293 (cons t (mime-charset-to-coding-system default-mime-charset))
296 (defun mime-article::write-region (start end file)
297 (let ((coding-system-for-write
299 (or (assq major-mode mime-article/coding-system-alist)
300 (assq t mime-article/coding-system-alist)
302 (write-region start end file)
305 (defun mime-display-message/partial (beg end cal)
309 (concat "m-prts-" (user-login-name)) mime-temp-directory))
310 (id (cdr (assoc "id" cal)))
311 (number (cdr (assoc "number" cal)))
312 (total (cdr (assoc "total" cal)))
314 (mother mime-view-buffer)
316 (or (file-exists-p root-dir)
317 (make-directory root-dir)
319 (setq id (replace-as-filename id))
320 (setq root-dir (concat root-dir "/" id))
321 (or (file-exists-p root-dir)
322 (make-directory root-dir)
324 (setq file (concat root-dir "/FULL"))
325 (if (file-exists-p file)
326 (let ((full-buf (get-buffer-create "FULL"))
327 (pwin (or (get-buffer-window mother)
328 (get-largest-window)))
330 (save-window-excursion
331 (set-buffer full-buf)
333 (as-binary-input-file (insert-file-contents file))
334 (setq major-mode 'mime-show-message-mode)
335 (mime-view-mode mother)
337 (set-window-buffer pwin
339 (set-buffer full-buf)
343 (re-search-forward "^$")
344 (goto-char (1+ (match-end 0)))
345 (setq file (concat root-dir "/" number))
346 (mime-article::write-region (point) end file)
347 (let ((total-file (concat root-dir "/CT")))
351 (or (file-exists-p total-file)
354 (get-buffer-create mime-temp-buffer-name))
357 (write-region (point-min)(point-max) total-file)
358 (kill-buffer (current-buffer))
360 (string-to-number total)
362 (and (file-exists-p total-file)
364 (set-buffer (find-file-noselect total-file))
366 (and (re-search-forward "[0-9]+" nil t)
368 (buffer-substring (match-beginning 0)
371 (kill-buffer (current-buffer))
374 (if (and total (> total 0))
377 (set-buffer (get-buffer-create mime-temp-buffer-name))
378 (let ((full-buf (current-buffer)))
382 (setq file (concat root-dir "/" (int-to-string i)))
383 (or (file-exists-p file)
386 (as-binary-input-file (insert-file-contents file))
387 (goto-char (point-max))
390 (as-binary-output-file
391 (write-region (point-min)(point-max)
392 (expand-file-name "FULL" root-dir)))
395 (let ((file (format "%s/%d" root-dir i)))
396 (and (file-exists-p file)
401 (let ((file (expand-file-name "CT" root-dir)))
402 (and (file-exists-p file)
405 (save-window-excursion
406 (setq major-mode 'mime-show-message-mode)
407 (mime-view-mode mother)
409 (let ((pwin (or (get-buffer-window mother)
412 (pbuf (save-excursion
413 (set-buffer full-buf)
415 (set-window-buffer pwin pbuf)
421 ;;; @ message/external-body
424 (defvar mime-article/dired-function
425 (if mime/use-multi-frame
426 (function dired-other-frame)
427 (function mime-article/dired-function-for-one-frame)
430 (defun mime-article/dired-function-for-one-frame (dir)
431 (let ((win (or (get-buffer-window mime-view-buffer)
432 (get-largest-window))))
437 (defun mime-display-message/external-ftp (beg end cal)
438 (let* ((site (cdr (assoc "site" cal)))
439 (directory (cdr (assoc "directory" cal)))
440 (name (cdr (assoc "name" cal)))
441 ;;(mode (cdr (assoc "mode" cal)))
442 (pathname (concat "/anonymous@" site ":" directory))
444 (message (concat "Accessing " (expand-file-name name pathname) "..."))
445 (funcall mime-article/dired-function pathname)
446 (goto-char (point-min))
447 (search-forward name)
454 (defun mime-display-caesar (start end cal)
455 "Internal method for mime-view to display ROT13-47-48 message."
456 (let* ((cnum (mime-article/point-content-number start))
457 (new-name (format "%s-%s" (buffer-name) cnum))
458 (the-buf (current-buffer))
459 (mother mime-view-buffer)
460 (charset (cdr (assoc "charset" cal)))
461 (encoding (cdr (assq 'encoding cal)))
464 (let ((pwin (or (get-buffer-window mother)
465 (get-largest-window)))
466 (buf (get-buffer-create new-name))
468 (set-window-buffer pwin buf)
472 (setq buffer-read-only nil)
474 (insert-buffer-substring the-buf start end)
475 (goto-char (point-min))
476 (if (re-search-forward "^\n" nil t)
477 (delete-region (point-min) (match-end 0))
479 (let ((m (cdr (or (assq mode mime-text-decoder-alist)
480 (assq t mime-text-decoder-alist)))))
482 (funcall m charset encoding)
484 (mule-caesar-region (point-min) (point-max))
485 (set-buffer-modified-p nil)
487 (view-buffer new-name)
496 ;;; mime-play.el ends here