1 ;;; tm-play.el --- decoder for tm-view.el
3 ;; Copyright (C) 1994,1995,1996 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Created: 1995/9/26 (separated from tm-view.el)
7 ;; Version: $Id: tm-play.el,v 7.29 1996/09/23 13:14:07 morioka Exp $
8 ;; Keywords: mail, news, MIME, multimedia
10 ;; This file is part of tm (Tools for MIME).
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.
31 (defvar mime-viewer/external-progs "/usr/local/share/tm"
32 "*Directory containing tm external methods.")
34 (add-to-list 'exec-path mime-viewer/external-progs)
36 (let ((paths (parse-colon-path (getenv "PATH"))))
37 (or (member mime-viewer/external-progs paths)
39 (mapconcat (function identity)
40 (append paths (list mime-viewer/external-progs))
48 (defvar mime-preview/after-decoded-position nil)
50 (defun mime-preview/decode-content ()
52 (let ((pc (mime-preview/point-pcinfo (point))))
54 (let ((the-buf (current-buffer)))
55 (setq mime-preview/after-decoded-position (point))
56 (set-buffer (mime::preview-content-info/buffer pc))
57 (mime-article/decode-content
58 (mime::preview-content-info/content-info pc))
59 (if (eq (current-buffer)
60 (mime::preview-content-info/buffer pc))
63 (goto-char mime-preview/after-decoded-position)
67 (defun mime-article/decode-content (cinfo)
68 (let ((beg (mime::content-info/point-min cinfo))
69 (end (mime::content-info/point-max cinfo))
70 (ctype (or (mime::content-info/type cinfo) "text/plain"))
71 (params (mime::content-info/parameters cinfo))
72 (encoding (mime::content-info/encoding cinfo))
75 (if (< beg (point-min))
76 (setq beg (point-min))
78 (if (< (point-max) end)
79 (setq end (point-max))
82 (setq cal (list* (cons 'type ctype)
83 (cons 'encoding encoding)
84 (cons 'major-mode major-mode)
86 (if mime-viewer/decoding-mode
88 (cons 'mode mime-viewer/decoding-mode)
91 (setq ret (mime/get-content-decoding-alist cal))
92 (setq method (cdr (assq 'method ret)))
93 (cond ((and (symbolp method)
95 (funcall method beg end ret)
97 ((and (listp method)(stringp (car method)))
98 (mime-article/start-external-method-region beg end ret)
101 (mime-article/show-output-buffer
102 "No method are specified for %s\n" ctype)
107 (defun field-unifier-for-mode (a b)
116 (defun mime/get-content-decoding-alist (al)
117 (get-unified-alist mime/content-decoding-condition al)
121 ;;; @ external decoder
124 (defun mime-article/start-external-method-region (beg end cal)
127 (narrow-to-region beg end)
129 (let ((method (cdr (assoc 'method cal)))
130 (name (mime-article/get-filename cal))
133 (let ((file (make-temp-name
134 (expand-file-name "TM" mime/tmp-dir)))
139 (if (re-search-forward "^$" nil t)
145 (write-region b end file)
146 (message "External method is starting...")
148 'name (replace-as-filename name) cal))
149 (setq cal (put-alist 'file file cal))
152 mime/output-buffer-name (car method)
154 (mime-article/make-method-args cal
157 (apply (function start-process) args)
158 (mime-article/show-output-buffer)
162 (defun mime-article/make-method-args (cal format)
167 (let* ((item (eval arg))
168 (ret (cdr (assoc item cal)))
172 (if (eq item 'encoding)
179 (defun mime-article/show-output-buffer (&rest forms)
180 (get-buffer-create mime/output-buffer-name)
181 (let ((the-win (selected-window))
182 (win (get-buffer-window mime/output-buffer-name))
185 (if (and mime/output-buffer-window-is-shared-with-bbdb
186 (boundp 'bbdb-buffer-name)
187 (setq win (get-buffer-window bbdb-buffer-name))
189 (set-window-buffer win mime/output-buffer-name)
190 (select-window (get-buffer-window mime::article/preview-buffer))
191 (setq win (split-window-vertically (/ (* (window-height) 3) 4)))
192 (set-window-buffer win mime/output-buffer-name)
195 (goto-char (point-max))
197 (insert (apply (function format) forms))
199 (select-window the-win)
206 (defvar mime-viewer/file-name-char-regexp "[A-Za-z0-9+_-]")
208 (defvar mime-viewer/file-name-regexp-1
209 (concat mime-viewer/file-name-char-regexp "+\\."
210 mime-viewer/file-name-char-regexp "+"))
212 (defvar mime-viewer/file-name-regexp-2
213 (concat (regexp-* mime-viewer/file-name-char-regexp)
214 "\\(\\." mime-viewer/file-name-char-regexp "+\\)*"))
216 (defun mime-article/get-original-filename (param &optional encoding)
217 (or (mime-article/get-uu-filename param encoding)
219 (or (if (or (and (setq ret (mime/Content-Disposition))
220 (setq ret (assoc "filename" (cdr ret)))
222 (setq ret (assoc "name" param))
223 (setq ret (assoc "x-name" param))
225 (std11-strip-quoted-string (cdr ret))
228 (std11-find-field-body '("Content-Description"
230 (if (or (string-match mime-viewer/file-name-regexp-1 ret)
231 (string-match mime-viewer/file-name-regexp-2 ret))
232 (substring ret (match-beginning 0)(match-end 0))
237 (defun mime-article/get-filename (param)
238 (replace-as-filename (mime-article/get-original-filename param))
242 ;;; @ mail/news message
245 (defun mime-viewer/quitting-method-for-mime/show-message-mode ()
246 (let ((mother mime::preview/mother-buffer)
247 (win-conf mime::preview/original-window-configuration)
250 (mime::preview-content-info/buffer (car mime::preview/content-list)))
251 (mime-viewer/kill-buffer)
252 (set-window-configuration win-conf)
253 (pop-to-buffer mother)
254 ;;(goto-char (point-min))
255 ;;(mime-viewer/up-content)
258 (defun mime-article/view-message/rfc822 (beg end cal)
259 (let* ((cnum (mime-article/point-content-number beg))
260 (cur-buf (current-buffer))
261 (new-name (format "%s-%s" (buffer-name) cnum))
262 (mother mime::article/preview-buffer)
264 (or (cdr (assq major-mode mime-viewer/code-converter-alist))
265 'mime-viewer/default-code-convert-region))
267 (setq str (buffer-substring beg end))
268 (switch-to-buffer new-name)
271 (goto-char (point-min))
272 (if (re-search-forward "^\n" nil t)
273 (delete-region (point-min) (match-end 0))
275 (setq major-mode 'mime/show-message-mode)
276 (setq mime::article/code-converter code-converter)
277 (mime/viewer-mode mother)
281 ;;; @ message/partial
284 (defvar mime-article/coding-system-alist
286 '((mh-show-mode . *noconv*)
290 (defvar mime-article/kanji-code-alist
291 (and (boundp 'NEMACS)
292 '((mh-show-mode . nil)
296 (defun mime-article/decode-message/partial (beg end cal)
298 (let* ((root-dir (expand-file-name
299 (concat "m-prts-" (user-login-name)) mime/tmp-dir))
300 (id (cdr (assoc "id" cal)))
301 (number (cdr (assoc "number" cal)))
302 (total (cdr (assoc "total" cal)))
303 (the-buf (current-buffer))
305 (mother mime::article/preview-buffer)
306 (win-conf (save-excursion
308 mime::preview/original-window-configuration))
310 (if (not (file-exists-p root-dir))
311 (make-directory root-dir)
313 (setq id (replace-as-filename id))
314 (setq root-dir (concat root-dir "/" id))
315 (if (not (file-exists-p root-dir))
316 (make-directory root-dir)
318 (setq file (concat root-dir "/FULL"))
319 (if (not (file-exists-p file))
321 (re-search-forward "^$")
322 (goto-char (1+ (match-end 0)))
323 (setq file (concat root-dir "/" number))
324 (let ((file-coding-system
326 (or (assq major-mode mime-article/coding-system-alist)
327 (assq t mime-article/coding-system-alist)
331 (or (assq major-mode mime-article/kanji-code-alist)
332 (assq t mime-article/kanji-code-alist)
335 (write-region (point) (point-max) file)
337 (if (get-buffer mime/temp-buffer-name)
338 (kill-buffer mime/temp-buffer-name)
340 (switch-to-buffer mime/temp-buffer-name)
342 (max (string-to-int total))
343 (file-coding-system-for-read (if (boundp 'MULE)
348 (setq file (concat root-dir "/" (int-to-string i)))
349 (if (not (file-exists-p file))
351 (switch-to-buffer the-buf)
354 (insert-file-contents file)
355 (goto-char (point-max))
358 ;;(delete-other-windows)
359 (let ((buf (current-buffer)))
360 (write-file (concat root-dir "/FULL"))
361 (set-window-configuration win-conf)
362 (let ((win (get-buffer-window mother)))
366 (set-window-buffer (selected-window) buf)
367 ;;(set-window-buffer buf)
368 (setq major-mode 'mime/show-message-mode)
370 (mime/viewer-mode mother)
371 (pop-to-buffer (current-buffer))
375 ;;(delete-other-windows)
376 (set-window-configuration win-conf)
377 (select-window (get-buffer-window mother))
378 (let ((file-coding-system-for-read
379 (if (boundp 'MULE) *noconv*))
381 (set-buffer (get-buffer-create "FULL"))
382 (insert-file-contents file)
384 (setq major-mode 'mime/show-message-mode)
385 (mime/viewer-mode mother)
386 ;;(pop-to-buffer (current-buffer))
394 (defun mime-article/decode-caesar (beg end cal)
395 (let* ((cnum (mime-article/point-content-number beg))
396 (cur-buf (current-buffer))
397 (new-name (format "%s-%s" (buffer-name) cnum))
398 (mother mime::article/preview-buffer)
399 (charset (cdr (assoc "charset" cal)))
400 (encoding (cdr (assq 'encoding cal)))
403 (setq str (buffer-substring beg end))
404 (switch-to-buffer new-name)
405 (setq buffer-read-only nil)
408 (goto-char (point-min))
409 (if (re-search-forward "^\n" nil t)
410 (delete-region (point-min) (match-end 0))
412 (let ((m (assq mode mime-viewer/code-converter-alist)))
413 (if (and m (fboundp (setq m (cdr m))))
414 (funcall m (point-min) (point-max) charset encoding)
415 (mime-viewer/default-code-convert-region (point-min) (point-max)
419 (set-mark (point-min))
420 (goto-char (point-max))
432 ;;; tm-play.el ends here