2 ;;; tm-play.el --- decoder for tm-view.el
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1994 .. 1996 MORIOKA Tomohiko
7 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
9 ;;; Created: 1995/9/26 (separated from tm-view.el)
11 ;;; $Id: tm-play.el,v 7.20 1996/07/15 14:04:46 morioka Exp $
12 ;;; Keywords: mail, news, MIME, multimedia
14 ;;; This file is part of tm (Tools for MIME).
16 ;;; This program is free software; you can redistribute it and/or
17 ;;; modify it under the terms of the GNU General Public License as
18 ;;; published by the Free Software Foundation; either version 2, or
19 ;;; (at your option) any later version.
21 ;;; This program is distributed in the hope that it will be useful,
22 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 ;;; General Public License for more details.
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with This program. If not, write to the Free Software
28 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
34 (defvar mime-viewer/external-progs "/usr/local/share/tm"
35 "*Directory containing tm external methods.")
37 (add-to-list 'exec-path mime-viewer/external-progs)
43 (defvar mime-preview/after-decoded-position nil)
45 (defun mime-preview/decode-content ()
47 (let ((pc (mime-preview/point-pcinfo (point))))
49 (let ((the-buf (current-buffer)))
50 (setq mime-preview/after-decoded-position (point))
51 (set-buffer (mime::preview-content-info/buffer pc))
52 (mime-article/decode-content
53 (mime::preview-content-info/content-info pc))
54 (if (eq (current-buffer)
55 (mime::preview-content-info/buffer pc))
58 (goto-char mime-preview/after-decoded-position)
63 (defun mime-article/decode-content (cinfo)
64 (let ((beg (mime::content-info/point-min cinfo))
65 (end (mime::content-info/point-max cinfo))
66 (ctype (mime::content-info/type cinfo))
67 (params (mime::content-info/parameters cinfo))
68 (encoding (mime::content-info/encoding cinfo))
71 (if (< beg (point-min))
72 (setq beg (point-min))
74 (if (< (point-max) end)
75 (setq end (point-max))
79 (setq cal (append (list (cons 'type ctype)
80 (cons 'encoding encoding)
81 (cons 'major-mode major-mode)
84 (if mime-viewer/decoding-mode
86 (cons 'mode mime-viewer/decoding-mode)
89 (setq ret (mime/get-content-decoding-alist cal))
90 (setq method (cdr (assoc 'method ret)))
91 (cond ((and (symbolp method)
93 (funcall method beg end ret)
95 ((and (listp method)(stringp (car method)))
96 (mime-article/start-external-method-region beg end ret)
99 (mime-article/show-output-buffer
100 "No method are specified for %s\n" ctype)
105 (defun mime/get-content-decoding-alist (al)
106 (get-unified-alist mime/content-decoding-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/tmp-dir)))
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/output-buffer-name (car method)
143 (mime-article/make-method-args cal
146 (let ((process-environment
147 (let* ((rest process-environment)
148 (dest (cons nil nil))
152 (while (and (setq cell (car rest))
154 (if (string-match "^PATH=" cell)
158 mime-viewer/external-progs
159 (substring cell (match-end 0))
162 (setcdr prest (cons nil nil))
163 (setq rest (cdr rest)
169 (format "PATH=%s" mime-viewer/external-progs)))
170 (setcdr prest (cdr rest))
172 (apply (function start-process) args)
174 (mime-article/show-output-buffer)
178 (defun mime-article/make-method-args (cal format)
183 (let* ((item (eval arg))
184 (ret (cdr (assoc item cal)))
188 (if (eq item 'encoding)
195 (defun mime-article/show-output-buffer (&rest forms)
196 (get-buffer-create mime/output-buffer-name)
197 (let ((the-win (selected-window))
198 (win (get-buffer-window mime/output-buffer-name))
201 (if (and mime/output-buffer-window-is-shared-with-bbdb
202 (boundp 'bbdb-buffer-name)
203 (setq win (get-buffer-window bbdb-buffer-name))
205 (set-window-buffer win mime/output-buffer-name)
206 (select-window (get-buffer-window mime::article/preview-buffer))
207 (setq win (split-window-vertically (/ (* (window-height) 3) 4)))
208 (set-window-buffer win mime/output-buffer-name)
211 (goto-char (point-max))
213 (insert (apply (function format) forms))
215 (select-window the-win)
222 (defvar mime-viewer/file-name-char-regexp "[A-Za-z0-9+_-]")
224 (defvar mime-viewer/file-name-regexp-1
225 (concat mime-viewer/file-name-char-regexp "+\\."
226 mime-viewer/file-name-char-regexp "+"))
228 (defvar mime-viewer/file-name-regexp-2
229 (concat (regexp-* mime-viewer/file-name-char-regexp)
230 "\\(\\." mime-viewer/file-name-char-regexp "+\\)*"))
232 (defun mime-article/get-original-filename (param &optional encoding)
233 (or (mime-article/get-uu-filename param encoding)
235 (or (if (or (and (setq ret (mime/Content-Disposition))
236 (setq ret (assoc "filename" (cdr ret)))
238 (setq ret (assoc "name" param))
239 (setq ret (assoc "x-name" param))
241 (rfc822/strip-quoted-string (cdr ret))
244 (or (rfc822/get-field-body "Content-Description")
245 (rfc822/get-field-body "Subject")
247 (if (or (string-match mime-viewer/file-name-regexp-1 ret)
248 (string-match mime-viewer/file-name-regexp-2 ret))
249 (substring ret (match-beginning 0)(match-end 0))
254 (defun mime-article/get-filename (param)
255 (replace-as-filename (mime-article/get-original-filename param))
259 ;;; @ mail/news message
262 (defun mime-viewer/quitting-method-for-mime/show-message-mode ()
263 (let ((mother mime::preview/mother-buffer)
264 (win-conf mime::preview/original-window-configuration)
267 (mime::preview-content-info/buffer (car mime::preview/content-list)))
268 (mime-viewer/kill-buffer)
269 (set-window-configuration win-conf)
270 (pop-to-buffer mother)
271 ;;(goto-char (point-min))
272 ;;(mime-viewer/up-content)
275 (defun mime-article/view-message/rfc822 (beg end cal)
276 (let* ((cnum (mime-article/point-content-number beg))
277 (cur-buf (current-buffer))
278 (new-name (format "%s-%s" (buffer-name) cnum))
279 (mother mime::article/preview-buffer)
281 (or (cdr (assq major-mode mime-viewer/code-converter-alist))
282 'mime-viewer/default-code-convert-region))
284 (setq str (buffer-substring beg end))
285 (switch-to-buffer new-name)
288 (goto-char (point-min))
289 (if (re-search-forward "^\n" nil t)
290 (delete-region (point-min) (match-end 0))
292 (setq major-mode 'mime/show-message-mode)
293 (setq mime::article/code-converter code-converter)
294 (mime/viewer-mode mother)
298 ;;; @ message/partial
301 (defvar mime-article/coding-system-alist
303 '((mh-show-mode . *noconv*)
307 (defvar mime-article/kanji-code-alist
308 (and (boundp 'NEMACS)
309 '((mh-show-mode . nil)
313 (defun mime-article/decode-message/partial (beg end cal)
315 (let* ((root-dir (expand-file-name
316 (concat "m-prts-" (user-login-name)) mime/tmp-dir))
317 (id (cdr (assoc "id" cal)))
318 (number (cdr (assoc "number" cal)))
319 (total (cdr (assoc "total" cal)))
320 (the-buf (current-buffer))
322 (mother mime::article/preview-buffer)
323 (win-conf (save-excursion
325 mime::preview/original-window-configuration))
327 (if (not (file-exists-p root-dir))
328 (make-directory root-dir)
330 (setq id (replace-as-filename id))
331 (setq root-dir (concat root-dir "/" id))
332 (if (not (file-exists-p root-dir))
333 (make-directory root-dir)
335 (setq file (concat root-dir "/FULL"))
336 (if (not (file-exists-p file))
338 (re-search-forward "^$")
339 (goto-char (1+ (match-end 0)))
340 (setq file (concat root-dir "/" number))
341 (let ((file-coding-system
343 (or (assq major-mode mime-article/coding-system-alist)
344 (assq t mime-article/coding-system-alist)
348 (or (assq major-mode mime-article/kanji-code-alist)
349 (assq t mime-article/kanji-code-alist)
352 (write-region (point) (point-max) file)
354 (if (get-buffer mime/temp-buffer-name)
355 (kill-buffer mime/temp-buffer-name)
357 (switch-to-buffer mime/temp-buffer-name)
359 (max (string-to-int total))
360 (file-coding-system-for-read (if (boundp 'MULE)
365 (setq file (concat root-dir "/" (int-to-string i)))
366 (if (not (file-exists-p file))
368 (switch-to-buffer the-buf)
371 (insert-file-contents file)
372 (goto-char (point-max))
375 ;;(delete-other-windows)
376 (let ((buf (current-buffer)))
377 (write-file (concat root-dir "/FULL"))
378 (set-window-configuration win-conf)
379 (let ((win (get-buffer-window mother)))
383 (set-window-buffer (selected-window) buf)
384 ;;(set-window-buffer buf)
385 (setq major-mode 'mime/show-message-mode)
387 (mime/viewer-mode mother)
388 (pop-to-buffer (current-buffer))
392 ;;(delete-other-windows)
393 (set-window-configuration win-conf)
394 (select-window (get-buffer-window mother))
395 (let ((file-coding-system-for-read
396 (if (boundp 'MULE) *noconv*))
398 (set-buffer (get-buffer-create "FULL"))
399 (insert-file-contents file)
401 (setq major-mode 'mime/show-message-mode)
402 (mime/viewer-mode mother)
403 ;;(pop-to-buffer (current-buffer))
411 (defun mime-article/decode-caesar (beg end cal)
412 (let* ((cnum (mime-article/point-content-number beg))
413 (cur-buf (current-buffer))
414 (new-name (format "%s-%s" (buffer-name) cnum))
415 (mother mime::article/preview-buffer)
416 (charset (cdr (assoc "charset" cal)))
417 (encoding (cdr (assq 'encoding cal)))
420 (setq str (buffer-substring beg end))
421 (switch-to-buffer new-name)
422 (setq buffer-read-only nil)
425 (goto-char (point-min))
426 (if (re-search-forward "^\n" nil t)
427 (delete-region (point-min) (match-end 0))
429 (let ((m (assq mode mime-viewer/code-converter-alist)))
430 (if (and m (fboundp (setq m (cdr m))))
431 (funcall m (point-min) (point-max) charset encoding)
432 (mime-viewer/default-code-convert-region (point-min) (point-max)
436 (set-mark (point-min))
437 (goto-char (point-max))
449 ;;; tm-play.el ends here