1 ;;; mime-play.el --- decoder for mime-view.el
3 ;; Copyright (C) 1994,1995,1996,1997 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 ;; Version: $Id: mime-play.el,v 0.46 1997-07-02 16:28:50 morioka Exp $
9 ;; Keywords: MIME, multimedia, mail, news
11 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 2, or (at
16 ;; your option) any later version.
18 ;; This program is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
38 (defvar mime-preview/after-decoded-position nil)
40 (defun mime-view-play-current-entity (&optional mode)
42 It decodes current entity to call internal or external method. The
43 method is selected from variable `mime-acting-condition'.
44 If MODE is specified, play as it. Default MODE is \"play\"."
49 (let ((cinfo (get-text-property (point) 'mime-view-cinfo)))
51 (let ((the-buf (current-buffer))
52 (raw-buffer (get-text-property (point) 'mime-view-raw-buffer))
54 (setq mime-preview/after-decoded-position (point))
55 (set-buffer raw-buffer)
56 (mime-display-content cinfo mode)
57 (if (eq (current-buffer) raw-buffer)
60 (goto-char mime-preview/after-decoded-position)
64 (defun mime-display-content (cinfo &optional mode)
65 (let ((beg (mime::content-info/point-min cinfo))
66 (end (mime::content-info/point-max cinfo))
67 (ctype (or (mime::content-info/type cinfo) "text/plain"))
68 (params (mime::content-info/parameters cinfo))
69 (encoding (mime::content-info/encoding cinfo))
72 (if (< beg (point-min))
73 (setq beg (point-min))
75 (if (< (point-max) end)
76 (setq end (point-max))
79 (setq cal (list* (cons 'type ctype)
80 (cons 'encoding encoding)
81 (cons 'major-mode major-mode)
84 (setq cal (cons (cons 'mode mode) cal))
86 (setq ret (mime/get-content-decoding-alist cal))
87 (setq method (cdr (assq 'method ret)))
88 (cond ((and (symbolp method)
90 (funcall method beg end ret)
92 ((and (listp method)(stringp (car method)))
93 (mime-article/start-external-method-region beg end ret)
96 (mime-show-echo-buffer
97 "No method are specified for %s\n" ctype)
103 ;;; @ method selector
106 (defun mime/get-content-decoding-alist (al)
107 (get-unified-alist mime-acting-condition al)
111 ;;; @ external decoder
114 (defun mime-article/start-external-method-region (beg end cal)
117 (narrow-to-region beg end)
119 (let ((method (cdr (assoc 'method cal)))
120 (name (mime-article/get-filename cal))
123 (let ((file (make-temp-name
124 (expand-file-name "TM" mime-temp-directory)))
129 (if (re-search-forward "^$" nil t)
135 (write-region b end file)
136 (message "External method is starting...")
138 'name (replace-as-filename name) cal))
139 (setq cal (put-alist 'file file cal))
142 mime-echo-buffer-name (car method)
144 (mime-article/make-method-args cal
147 (apply (function start-process) args)
148 (mime-show-echo-buffer)
152 (defun mime-article/make-method-args (cal format)
157 (let* ((item (eval arg))
158 (ret (cdr (assoc item cal)))
162 (if (eq item 'encoding)
169 (defvar mime-echo-window-is-shared-with-bbdb t
170 "*If non-nil, mime-echo window is shared with BBDB window.")
172 (defvar mime-echo-window-height
175 (/ (window-height) 5)
177 "*Size of mime-echo window.
178 It allows function or integer. If it is function,
179 `mime-show-echo-buffer' calls it to get height of mime-echo window.
180 Otherwise `mime-show-echo-buffer' uses it as height of mime-echo
183 (defun mime-show-echo-buffer (&rest forms)
184 "Show mime-echo buffer to display MIME-playing information."
185 (get-buffer-create mime-echo-buffer-name)
186 (let ((the-win (selected-window))
187 (win (get-buffer-window mime-echo-buffer-name))
190 (if (and mime-echo-window-is-shared-with-bbdb
191 (boundp 'bbdb-buffer-name)
192 (setq win (get-buffer-window bbdb-buffer-name))
194 (set-window-buffer win mime-echo-buffer-name)
195 (select-window (get-buffer-window mime-view-buffer))
196 (setq win (split-window-vertically
198 (if (functionp mime-echo-window-height)
199 (funcall mime-echo-window-height)
200 mime-echo-window-height)
202 (set-window-buffer win mime-echo-buffer-name)
205 (goto-char (point-max))
207 (insert (apply (function format) forms))
209 (select-window the-win)
216 (defvar mime-view-file-name-char-regexp "[A-Za-z0-9+_-]")
218 (defvar mime-view-file-name-regexp-1
219 (concat mime-view-file-name-char-regexp "+\\."
220 mime-view-file-name-char-regexp "+"))
222 (defvar mime-view-file-name-regexp-2
223 (concat (regexp-* mime-view-file-name-char-regexp)
224 "\\(\\." mime-view-file-name-char-regexp "+\\)*"))
226 (defun mime-article/get-original-filename (param &optional encoding)
227 (or (mime-article/get-uu-filename param encoding)
229 (or (if (or (and (setq ret (mime/Content-Disposition))
230 (setq ret (assoc "filename" (cdr ret)))
232 (setq ret (assoc "name" param))
233 (setq ret (assoc "x-name" param))
235 (std11-strip-quoted-string (cdr ret))
238 (std11-find-field-body '("Content-Description"
240 (if (or (string-match mime-view-file-name-regexp-1 ret)
241 (string-match mime-view-file-name-regexp-2 ret))
242 (substring ret (match-beginning 0)(match-end 0))
247 (defun mime-article/get-filename (param)
248 (replace-as-filename (mime-article/get-original-filename param))
252 ;;; @ mail/news message
255 (defun mime-view-quitting-method-for-mime-show-message-mode ()
256 "Quitting method for mime-view.
257 It is registered to variable `mime-view-quitting-method-alist'."
258 (let ((mother mime-mother-buffer)
259 (win-conf mime::preview/original-window-configuration)
261 (kill-buffer mime-raw-buffer)
262 (mime-view-kill-buffer)
263 (set-window-configuration win-conf)
264 (pop-to-buffer mother)
267 (defun mime-article/view-message/rfc822 (beg end cal)
268 (let* ((cnum (mime-article/point-content-number beg))
269 (new-name (format "%s-%s" (buffer-name) cnum))
270 (mother mime-view-buffer)
272 (cdr (or (assq major-mode mime-text-decoder-alist)
273 (assq t mime-text-decoder-alist))))
275 (setq str (buffer-substring beg end))
276 (switch-to-buffer new-name)
279 (goto-char (point-min))
280 (if (re-search-forward "^\n" nil t)
281 (delete-region (point-min) (match-end 0))
283 (setq major-mode 'mime-show-message-mode)
284 (setq mime-text-decoder text-decoder)
285 (mime-view-mode mother)
289 ;;; @ message/partial
292 (defvar mime-article/coding-system-alist
293 (list '(mh-show-mode . no-conversion)
294 (cons t (mime-charset-to-coding-system default-mime-charset))
297 (defun mime-article::write-region (start end file)
298 (let ((coding-system-for-write
300 (or (assq major-mode mime-article/coding-system-alist)
301 (assq t mime-article/coding-system-alist)
303 (write-region start end file)
306 (defun mime-display-message/partial (beg end cal)
310 (concat "m-prts-" (user-login-name)) mime-temp-directory))
311 (id (cdr (assoc "id" cal)))
312 (number (cdr (assoc "number" cal)))
313 (total (cdr (assoc "total" cal)))
315 (mother mime-view-buffer)
317 (or (file-exists-p root-dir)
318 (make-directory root-dir)
320 (setq id (replace-as-filename id))
321 (setq root-dir (concat root-dir "/" id))
322 (or (file-exists-p root-dir)
323 (make-directory root-dir)
325 (setq file (concat root-dir "/FULL"))
326 (if (file-exists-p file)
327 (let ((full-buf (get-buffer-create "FULL"))
328 (pwin (or (get-buffer-window mother)
329 (get-largest-window)))
331 (save-window-excursion
332 (set-buffer full-buf)
334 (as-binary-input-file (insert-file-contents file))
335 (setq major-mode 'mime-show-message-mode)
336 (mime-view-mode mother)
338 (set-window-buffer pwin
340 (set-buffer full-buf)
344 (re-search-forward "^$")
345 (goto-char (1+ (match-end 0)))
346 (setq file (concat root-dir "/" number))
347 (mime-article::write-region (point) (point-max) file)
348 (let ((total-file (concat root-dir "/CT")))
352 (or (file-exists-p total-file)
355 (get-buffer-create mime-temp-buffer-name))
358 (write-file total-file)
359 (kill-buffer (current-buffer))
361 (string-to-number total)
363 (and (file-exists-p total-file)
365 (set-buffer (find-file-noselect total-file))
367 (and (re-search-forward "[0-9]+" nil t)
369 (buffer-substring (match-beginning 0)
372 (kill-buffer (current-buffer))
375 (if (and total (> total 0))
378 (set-buffer (get-buffer-create mime-temp-buffer-name))
379 (let ((full-buf (current-buffer)))
383 (setq file (concat root-dir "/" (int-to-string i)))
384 (or (file-exists-p file)
387 (as-binary-input-file (insert-file-contents file))
388 (goto-char (point-max))
391 (as-binary-output-file (write-file (concat root-dir "/FULL")))
394 (let ((file (format "%s/%d" root-dir i)))
395 (and (file-exists-p file)
400 (let ((file (expand-file-name "CT" root-dir)))
401 (and (file-exists-p file)
404 (save-window-excursion
405 (setq major-mode 'mime-show-message-mode)
406 (mime-view-mode mother)
408 (let ((pwin (or (get-buffer-window mother)
411 (pbuf (save-excursion
412 (set-buffer full-buf)
414 (set-window-buffer pwin pbuf)
420 ;;; @ message/external-body
423 (defvar mime-article/dired-function
424 (if mime/use-multi-frame
425 (function dired-other-frame)
426 (function mime-article/dired-function-for-one-frame)
429 (defun mime-article/dired-function-for-one-frame (dir)
430 (let ((win (or (get-buffer-window mime-view-buffer)
431 (get-largest-window))))
436 (defun mime-display-message/external-ftp (beg end cal)
437 (let* ((site (cdr (assoc "site" cal)))
438 (directory (cdr (assoc "directory" cal)))
439 (name (cdr (assoc "name" cal)))
440 ;;(mode (cdr (assoc "mode" cal)))
441 (pathname (concat "/anonymous@" site ":" directory))
443 (message (concat "Accessing " (expand-file-name name pathname) "..."))
444 (funcall mime-article/dired-function pathname)
445 (goto-char (point-min))
446 (search-forward name)
453 (defun mime-display-caesar (start end cal)
454 "Internal method for mime-view to display ROT13-47-48 message."
455 (let* ((cnum (mime-article/point-content-number start))
456 (new-name (format "%s-%s" (buffer-name) cnum))
457 (the-buf (current-buffer))
458 (mother mime-view-buffer)
459 (charset (cdr (assoc "charset" cal)))
460 (encoding (cdr (assq 'encoding cal)))
463 (let ((pwin (or (get-buffer-window mother)
464 (get-largest-window)))
465 (buf (get-buffer-create new-name))
467 (set-window-buffer pwin buf)
471 (setq buffer-read-only nil)
473 (insert-buffer-substring the-buf start end)
474 (goto-char (point-min))
475 (if (re-search-forward "^\n" nil t)
476 (delete-region (point-min) (match-end 0))
478 (let ((m (cdr (or (assq mode mime-text-decoder-alist)
479 (assq t mime-text-decoder-alist)))))
481 (funcall m charset encoding)
483 (mule-caesar-region (point-min) (point-max))
484 (set-buffer-modified-p nil)
486 (view-buffer new-name)
495 ;;; mime-play.el ends here