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.13 1997-03-10 13:39:57 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-preview/decode-content ()
42 (let ((pc (mime-preview/point-pcinfo (point))))
44 (let ((the-buf (current-buffer)))
45 (setq mime-preview/after-decoded-position (point))
46 (set-buffer (mime::preview-content-info/buffer pc))
47 (mime-article/decode-content
48 (mime::preview-content-info/content-info pc))
49 (if (eq (current-buffer)
50 (mime::preview-content-info/buffer pc))
53 (goto-char mime-preview/after-decoded-position)
57 (defun mime-article/decode-content (cinfo)
58 (let ((beg (mime::content-info/point-min cinfo))
59 (end (mime::content-info/point-max cinfo))
60 (ctype (or (mime::content-info/type cinfo) "text/plain"))
61 (params (mime::content-info/parameters cinfo))
62 (encoding (mime::content-info/encoding cinfo))
65 (if (< beg (point-min))
66 (setq beg (point-min))
68 (if (< (point-max) end)
69 (setq end (point-max))
72 (setq cal (list* (cons 'type ctype)
73 (cons 'encoding encoding)
74 (cons 'major-mode major-mode)
76 (if mime-view-decoding-mode
78 (cons 'mode mime-view-decoding-mode)
81 (setq ret (mime/get-content-decoding-alist cal))
82 (setq method (cdr (assq 'method ret)))
83 (cond ((and (symbolp method)
85 (funcall method beg end ret)
87 ((and (listp method)(stringp (car method)))
88 (mime-article/start-external-method-region beg end ret)
91 (mime-article/show-output-buffer
92 "No method are specified for %s\n" ctype)
101 (defun mime/get-content-decoding-alist (al)
102 (get-unified-alist mime/content-decoding-condition al)
106 ;;; @ external decoder
109 (defun mime-article/start-external-method-region (beg end cal)
112 (narrow-to-region beg end)
114 (let ((method (cdr (assoc 'method cal)))
115 (name (mime-article/get-filename cal))
118 (let ((file (make-temp-name
119 (expand-file-name "TM" mime-temp-directory)))
124 (if (re-search-forward "^$" nil t)
130 (write-region b end file)
131 (message "External method is starting...")
133 'name (replace-as-filename name) cal))
134 (setq cal (put-alist 'file file cal))
137 mime/output-buffer-name (car method)
139 (mime-article/make-method-args cal
142 (apply (function start-process) args)
143 (mime-article/show-output-buffer)
147 (defun mime-article/make-method-args (cal format)
152 (let* ((item (eval arg))
153 (ret (cdr (assoc item cal)))
157 (if (eq item 'encoding)
164 (defun mime-article/show-output-buffer (&rest forms)
165 (get-buffer-create mime/output-buffer-name)
166 (let ((the-win (selected-window))
167 (win (get-buffer-window mime/output-buffer-name))
170 (if (and mime/output-buffer-window-is-shared-with-bbdb
171 (boundp 'bbdb-buffer-name)
172 (setq win (get-buffer-window bbdb-buffer-name))
174 (set-window-buffer win mime/output-buffer-name)
175 (select-window (get-buffer-window mime::article/preview-buffer))
176 (setq win (split-window-vertically (/ (* (window-height) 3) 4)))
177 (set-window-buffer win mime/output-buffer-name)
180 (goto-char (point-max))
182 (insert (apply (function format) forms))
184 (select-window the-win)
191 (defvar mime-view-file-name-char-regexp "[A-Za-z0-9+_-]")
193 (defvar mime-view-file-name-regexp-1
194 (concat mime-view-file-name-char-regexp "+\\."
195 mime-view-file-name-char-regexp "+"))
197 (defvar mime-view-file-name-regexp-2
198 (concat (regexp-* mime-view-file-name-char-regexp)
199 "\\(\\." mime-view-file-name-char-regexp "+\\)*"))
201 (defun mime-article/get-original-filename (param &optional encoding)
202 (or (mime-article/get-uu-filename param encoding)
204 (or (if (or (and (setq ret (mime/Content-Disposition))
205 (setq ret (assoc "filename" (cdr ret)))
207 (setq ret (assoc "name" param))
208 (setq ret (assoc "x-name" param))
210 (std11-strip-quoted-string (cdr ret))
213 (std11-find-field-body '("Content-Description"
215 (if (or (string-match mime-view-file-name-regexp-1 ret)
216 (string-match mime-view-file-name-regexp-2 ret))
217 (substring ret (match-beginning 0)(match-end 0))
222 (defun mime-article/get-filename (param)
223 (replace-as-filename (mime-article/get-original-filename param))
227 ;;; @ mail/news message
230 (defun mime-view-quitting-method-for-mime/show-message-mode ()
231 (let ((mother mime::preview/mother-buffer)
232 (win-conf mime::preview/original-window-configuration)
235 (mime::preview-content-info/buffer (car mime::preview/content-list)))
236 (mime-view-kill-buffer)
237 (set-window-configuration win-conf)
238 (pop-to-buffer mother)
239 ;;(goto-char (point-min))
240 ;;(mime-view-up-content)
243 (defun mime-article/view-message/rfc822 (beg end cal)
244 (let* ((cnum (mime-article/point-content-number beg))
245 (cur-buf (current-buffer))
246 (new-name (format "%s-%s" (buffer-name) cnum))
247 (mother mime::article/preview-buffer)
249 (or (cdr (assq major-mode mime-text-decoder-alist))
250 'mime-view-default-code-convert-region))
252 (setq str (buffer-substring beg end))
253 (switch-to-buffer new-name)
256 (goto-char (point-min))
257 (if (re-search-forward "^\n" nil t)
258 (delete-region (point-min) (match-end 0))
260 (setq major-mode 'mime/show-message-mode)
261 (setq mime::article/code-converter code-converter)
262 (mime-view-mode mother)
266 ;;; @ message/partial
269 (defvar mime-article/coding-system-alist
270 (list '(mh-show-mode . no-conversion)
271 (cons t (mime-charset-to-coding-system default-mime-charset))
274 (defun mime-article::write-region (start end file)
275 (let ((coding-system-for-write
277 (or (assq major-mode mime-article/coding-system-alist)
278 (assq t mime-article/coding-system-alist)
280 (write-region start end file)
283 (defun mime-article/decode-message/partial (beg end cal)
287 (concat "m-prts-" (user-login-name)) mime-temp-directory))
288 (id (cdr (assoc "id" cal)))
289 (number (cdr (assoc "number" cal)))
290 (total (cdr (assoc "total" cal)))
292 (mother mime::article/preview-buffer)
294 (or (file-exists-p root-dir)
295 (make-directory root-dir)
297 (setq id (replace-as-filename id))
298 (setq root-dir (concat root-dir "/" id))
299 (or (file-exists-p root-dir)
300 (make-directory root-dir)
302 (setq file (concat root-dir "/FULL"))
303 (if (file-exists-p file)
304 (let ((full-buf (get-buffer-create "FULL"))
305 (pwin (or (get-buffer-window mother)
306 (get-largest-window)))
308 (save-window-excursion
309 (set-buffer full-buf)
311 (as-binary-input-file (insert-file-contents file))
312 (setq major-mode 'mime/show-message-mode)
313 (mime-view-mode mother)
315 (set-window-buffer pwin
317 (set-buffer full-buf)
318 mime::article/preview-buffer))
321 (re-search-forward "^$")
322 (goto-char (1+ (match-end 0)))
323 (setq file (concat root-dir "/" number))
324 (mime-article::write-region (point) (point-max) file)
325 (let ((total-file (concat root-dir "/CT")))
329 (or (file-exists-p total-file)
332 (get-buffer-create mime/temp-buffer-name))
335 (write-file total-file)
336 (kill-buffer (current-buffer))
338 (string-to-number total)
340 (and (file-exists-p total-file)
342 (set-buffer (find-file-noselect total-file))
344 (and (re-search-forward "[0-9]+" nil t)
346 (buffer-substring (match-beginning 0)
349 (kill-buffer (current-buffer))
352 (if (and total (> total 0))
355 (set-buffer (get-buffer-create mime/temp-buffer-name))
356 (let ((full-buf (current-buffer)))
360 (setq file (concat root-dir "/" (int-to-string i)))
361 (or (file-exists-p file)
364 (as-binary-input-file (insert-file-contents file))
365 (goto-char (point-max))
368 (as-binary-output-file (write-file (concat root-dir "/FULL")))
371 (let ((file (format "%s/%d" root-dir i)))
372 (and (file-exists-p file)
377 (let ((file (expand-file-name "CT" root-dir)))
378 (and (file-exists-p file)
381 (save-window-excursion
382 (setq major-mode 'mime/show-message-mode)
383 (mime-view-mode mother)
385 (let ((pwin (or (get-buffer-window mother)
388 (pbuf (save-excursion
389 (set-buffer full-buf)
390 mime::article/preview-buffer)))
391 (set-window-buffer pwin pbuf)
397 ;;; @ message/external-body
400 (defvar mime-article/dired-function
401 (if mime/use-multi-frame
402 (function dired-other-frame)
403 (function mime-article/dired-function-for-one-frame)
406 (defun mime-article/dired-function-for-one-frame (dir)
407 (let ((win (or (get-buffer-window mime::article/preview-buffer)
408 (get-largest-window))))
413 (defun mime-article/decode-message/external-ftp (beg end cal)
414 (let* ((access-type (cdr (assoc "access-type" cal)))
415 (site (cdr (assoc "site" cal)))
416 (directory (cdr (assoc "directory" cal)))
417 (name (cdr (assoc "name" cal)))
418 (mode (cdr (assoc "mode" cal)))
419 (pathname (concat "/anonymous@" site ":" directory))
421 (message (concat "Accessing " (expand-file-name name pathname) "..."))
422 (funcall mime-article/dired-function pathname)
423 (goto-char (point-min))
424 (search-forward name)
433 (defconst mime-view-text/plain-mode-map (copy-keymap view-mode-map))
434 (define-key mime-view-text/plain-mode-map
435 "q" (function mime-view-text/plain-exit))
437 (defun mime-view-text/plain-mode ()
438 "\\{mime-view-text/plain-mode-map}"
439 (setq buffer-read-only t)
440 (setq major-mode 'mime-view-text/plain-mode)
441 (setq mode-name "MIME-View text/plain")
442 (use-local-map mime-view-text/plain-mode-map)
445 (defun mime-view-text/plain-exit ()
447 (kill-buffer (current-buffer))
450 (defun mime-article/decode-caesar (beg end cal)
451 (let* ((cnum (mime-article/point-content-number beg))
452 (cur-buf (current-buffer))
453 (new-name (format "%s-%s" (buffer-name) cnum))
454 (mother mime::article/preview-buffer)
455 (charset (cdr (assoc "charset" cal)))
456 (encoding (cdr (assq 'encoding cal)))
459 (setq str (buffer-substring beg end))
460 (let ((pwin (or (get-buffer-window mother)
461 (get-largest-window)))
462 (buf (get-buffer-create new-name))
464 (set-window-buffer pwin buf)
468 (setq buffer-read-only nil)
471 (goto-char (point-min))
472 (if (re-search-forward "^\n" nil t)
473 (delete-region (point-min) (match-end 0))
475 (let ((m (cdr (or (assq mode mime-text-decoder-alist)
476 (assq t mime-text-decoder-alist)))))
478 (funcall m charset encoding)
481 (set-mark (point-min))
482 (goto-char (point-max))
485 (set-buffer-modified-p nil)
486 (mime-view-text/plain-mode)
495 ;;; mime-play.el ends here