4
|
1 ;;; tm-play.el --- decoder for tm-view.el
|
|
2
|
18
|
3 ;; Copyright (C) 1994,1995,1996,1997 Free Software Foundation, Inc.
|
4
|
4
|
|
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
|
|
6 ;; Created: 1995/9/26 (separated from tm-view.el)
|
44
|
7 ;; Version: $Id: tm-play.el,v 1.8 1997/03/26 04:34:05 steve Exp $
|
4
|
8 ;; Keywords: mail, news, MIME, multimedia
|
|
9
|
|
10 ;; This file is part of tm (Tools for MIME).
|
|
11
|
|
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.
|
|
16
|
|
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.
|
|
21
|
|
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.
|
|
26
|
|
27 ;;; Code:
|
|
28
|
|
29 (require 'tm-view)
|
|
30
|
|
31
|
|
32 ;;; @ content decoder
|
|
33 ;;;
|
|
34
|
|
35 (defvar mime-preview/after-decoded-position nil)
|
|
36
|
|
37 (defun mime-preview/decode-content ()
|
|
38 (interactive)
|
|
39 (let ((pc (mime-preview/point-pcinfo (point))))
|
|
40 (if pc
|
|
41 (let ((the-buf (current-buffer)))
|
|
42 (setq mime-preview/after-decoded-position (point))
|
|
43 (set-buffer (mime::preview-content-info/buffer pc))
|
|
44 (mime-article/decode-content
|
|
45 (mime::preview-content-info/content-info pc))
|
|
46 (if (eq (current-buffer)
|
|
47 (mime::preview-content-info/buffer pc))
|
|
48 (progn
|
|
49 (set-buffer the-buf)
|
|
50 (goto-char mime-preview/after-decoded-position)
|
|
51 ))
|
|
52 ))))
|
|
53
|
|
54 (defun mime-article/decode-content (cinfo)
|
|
55 (let ((beg (mime::content-info/point-min cinfo))
|
|
56 (end (mime::content-info/point-max cinfo))
|
|
57 (ctype (or (mime::content-info/type cinfo) "text/plain"))
|
|
58 (params (mime::content-info/parameters cinfo))
|
|
59 (encoding (mime::content-info/encoding cinfo))
|
|
60 )
|
|
61 ;; Check for VM
|
|
62 (if (< beg (point-min))
|
|
63 (setq beg (point-min))
|
|
64 )
|
|
65 (if (< (point-max) end)
|
|
66 (setq end (point-max))
|
|
67 )
|
|
68 (let (method cal ret)
|
|
69 (setq cal (list* (cons 'type ctype)
|
|
70 (cons 'encoding encoding)
|
|
71 (cons 'major-mode major-mode)
|
|
72 params))
|
|
73 (if mime-viewer/decoding-mode
|
|
74 (setq cal (cons
|
|
75 (cons 'mode mime-viewer/decoding-mode)
|
|
76 cal))
|
|
77 )
|
|
78 (setq ret (mime/get-content-decoding-alist cal))
|
|
79 (setq method (cdr (assq 'method ret)))
|
|
80 (cond ((and (symbolp method)
|
|
81 (fboundp method))
|
|
82 (funcall method beg end ret)
|
|
83 )
|
|
84 ((and (listp method)(stringp (car method)))
|
|
85 (mime-article/start-external-method-region beg end ret)
|
|
86 )
|
|
87 (t
|
|
88 (mime-article/show-output-buffer
|
|
89 "No method are specified for %s\n" ctype)
|
|
90 ))
|
|
91 )
|
|
92 ))
|
|
93
|
|
94 (defun field-unifier-for-mode (a b)
|
|
95 (let ((va (cdr a)))
|
|
96 (if (if (consp va)
|
|
97 (member (cdr b) va)
|
|
98 (equal va (cdr b))
|
|
99 )
|
|
100 (list nil b nil)
|
|
101 )))
|
|
102
|
|
103 (defun mime/get-content-decoding-alist (al)
|
|
104 (get-unified-alist mime/content-decoding-condition al)
|
|
105 )
|
|
106
|
|
107
|
|
108 ;;; @ external decoder
|
|
109 ;;;
|
|
110
|
|
111 (defun mime-article/start-external-method-region (beg end cal)
|
|
112 (save-excursion
|
|
113 (save-restriction
|
|
114 (narrow-to-region beg end)
|
|
115 (goto-char beg)
|
|
116 (let ((method (cdr (assoc 'method cal)))
|
|
117 (name (mime-article/get-filename cal))
|
|
118 )
|
|
119 (if method
|
|
120 (let ((file (make-temp-name
|
|
121 (expand-file-name "TM" mime/tmp-dir)))
|
|
122 b args)
|
|
123 (if (nth 1 method)
|
|
124 (setq b beg)
|
|
125 (setq b
|
|
126 (if (re-search-forward "^$" nil t)
|
|
127 (1+ (match-end 0))
|
|
128 (point-min)
|
|
129 ))
|
|
130 )
|
|
131 (goto-char b)
|
|
132 (write-region b end file)
|
|
133 (message "External method is starting...")
|
|
134 (setq cal (put-alist
|
|
135 'name (replace-as-filename name) cal))
|
|
136 (setq cal (put-alist 'file file cal))
|
|
137 (setq args (nconc
|
|
138 (list (car method)
|
|
139 mime/output-buffer-name (car method)
|
|
140 )
|
|
141 (mime-article/make-method-args cal
|
|
142 (cdr (cdr method)))
|
|
143 ))
|
|
144 (apply (function start-process) args)
|
|
145 (mime-article/show-output-buffer)
|
|
146 ))
|
|
147 ))))
|
|
148
|
|
149 (defun mime-article/make-method-args (cal format)
|
|
150 (mapcar (function
|
|
151 (lambda (arg)
|
|
152 (if (stringp arg)
|
|
153 arg
|
|
154 (let* ((item (eval arg))
|
|
155 (ret (cdr (assoc item cal)))
|
|
156 )
|
|
157 (if ret
|
|
158 ret
|
|
159 (if (eq item 'encoding)
|
|
160 "7bit"
|
|
161 ""))
|
|
162 ))
|
|
163 ))
|
|
164 format))
|
|
165
|
|
166 (defun mime-article/show-output-buffer (&rest forms)
|
|
167 (get-buffer-create mime/output-buffer-name)
|
|
168 (let ((the-win (selected-window))
|
|
169 (win (get-buffer-window mime/output-buffer-name))
|
|
170 )
|
|
171 (or win
|
|
172 (if (and mime/output-buffer-window-is-shared-with-bbdb
|
|
173 (boundp 'bbdb-buffer-name)
|
|
174 (setq win (get-buffer-window bbdb-buffer-name))
|
|
175 )
|
|
176 (set-window-buffer win mime/output-buffer-name)
|
|
177 (select-window (get-buffer-window mime::article/preview-buffer))
|
|
178 (setq win (split-window-vertically (/ (* (window-height) 3) 4)))
|
|
179 (set-window-buffer win mime/output-buffer-name)
|
|
180 ))
|
|
181 (select-window win)
|
|
182 (goto-char (point-max))
|
|
183 (if forms
|
|
184 (insert (apply (function format) forms))
|
|
185 )
|
|
186 (select-window the-win)
|
|
187 ))
|
|
188
|
|
189
|
|
190 ;;; @ file name
|
|
191 ;;;
|
|
192
|
|
193 (defvar mime-viewer/file-name-char-regexp "[A-Za-z0-9+_-]")
|
|
194
|
|
195 (defvar mime-viewer/file-name-regexp-1
|
|
196 (concat mime-viewer/file-name-char-regexp "+\\."
|
|
197 mime-viewer/file-name-char-regexp "+"))
|
|
198
|
|
199 (defvar mime-viewer/file-name-regexp-2
|
|
200 (concat (regexp-* mime-viewer/file-name-char-regexp)
|
|
201 "\\(\\." mime-viewer/file-name-char-regexp "+\\)*"))
|
|
202
|
|
203 (defun mime-article/get-original-filename (param &optional encoding)
|
|
204 (or (mime-article/get-uu-filename param encoding)
|
|
205 (let (ret)
|
|
206 (or (if (or (and (setq ret (mime/Content-Disposition))
|
|
207 (setq ret (assoc "filename" (cdr ret)))
|
|
208 )
|
|
209 (setq ret (assoc "name" param))
|
|
210 (setq ret (assoc "x-name" param))
|
|
211 )
|
|
212 (std11-strip-quoted-string (cdr ret))
|
|
213 )
|
|
214 (if (setq ret
|
|
215 (std11-find-field-body '("Content-Description"
|
|
216 "Subject")))
|
|
217 (if (or (string-match mime-viewer/file-name-regexp-1 ret)
|
|
218 (string-match mime-viewer/file-name-regexp-2 ret))
|
|
219 (substring ret (match-beginning 0)(match-end 0))
|
|
220 ))
|
|
221 ))
|
|
222 ))
|
|
223
|
|
224 (defun mime-article/get-filename (param)
|
|
225 (replace-as-filename (mime-article/get-original-filename param))
|
|
226 )
|
|
227
|
|
228
|
|
229 ;;; @ mail/news message
|
|
230 ;;;
|
|
231
|
|
232 (defun mime-viewer/quitting-method-for-mime/show-message-mode ()
|
|
233 (let ((mother mime::preview/mother-buffer)
|
|
234 (win-conf mime::preview/original-window-configuration)
|
|
235 )
|
|
236 (kill-buffer
|
|
237 (mime::preview-content-info/buffer (car mime::preview/content-list)))
|
|
238 (mime-viewer/kill-buffer)
|
|
239 (set-window-configuration win-conf)
|
|
240 (pop-to-buffer mother)
|
|
241 ;;(goto-char (point-min))
|
|
242 ;;(mime-viewer/up-content)
|
|
243 ))
|
|
244
|
|
245 (defun mime-article/view-message/rfc822 (beg end cal)
|
|
246 (let* ((cnum (mime-article/point-content-number beg))
|
|
247 (cur-buf (current-buffer))
|
|
248 (new-name (format "%s-%s" (buffer-name) cnum))
|
|
249 (mother mime::article/preview-buffer)
|
|
250 (code-converter
|
|
251 (or (cdr (assq major-mode mime-viewer/code-converter-alist))
|
|
252 'mime-viewer/default-code-convert-region))
|
|
253 str)
|
|
254 (setq str (buffer-substring beg end))
|
|
255 (switch-to-buffer new-name)
|
|
256 (erase-buffer)
|
|
257 (insert str)
|
|
258 (goto-char (point-min))
|
|
259 (if (re-search-forward "^\n" nil t)
|
|
260 (delete-region (point-min) (match-end 0))
|
|
261 )
|
|
262 (setq major-mode 'mime/show-message-mode)
|
|
263 (setq mime::article/code-converter code-converter)
|
|
264 (mime/viewer-mode mother)
|
|
265 ))
|
|
266
|
|
267
|
|
268 ;;; @ message/partial
|
|
269 ;;;
|
|
270
|
|
271 (defvar mime-article/coding-system-alist
|
18
|
272 (list (cons 'mh-show-mode *noconv*)
|
|
273 (cons t (mime-charset-to-coding-system default-mime-charset))
|
|
274 ))
|
4
|
275
|
40
|
276 (cond ((boundp 'MULE) ; for MULE 2.3 or older
|
|
277 (defun mime-article::write-region (start end file)
|
|
278 (let ((file-coding-system
|
|
279 (cdr
|
|
280 (or (assq major-mode mime-article/coding-system-alist)
|
|
281 (assq t mime-article/coding-system-alist)
|
|
282 ))))
|
|
283 (write-region start end file)
|
|
284 ))
|
|
285 )
|
|
286 ((featurep 'mule) ; for Emacs/mule and XEmacs/mule
|
18
|
287 (defun mime-article::write-region (start end file)
|
|
288 (let ((coding-system-for-write
|
|
289 (cdr
|
|
290 (or (assq major-mode mime-article/coding-system-alist)
|
|
291 (assq t mime-article/coding-system-alist)
|
|
292 ))))
|
|
293 (write-region start end file)
|
|
294 ))
|
|
295 )
|
40
|
296 ((boundp 'NEMACS) ; for NEmacs
|
18
|
297 (defun mime-article::write-region (start end file)
|
|
298 (let ((kanji-fileio-code
|
|
299 (cdr
|
|
300 (or (assq major-mode mime-article/kanji-code-alist)
|
|
301 (assq t mime-article/kanji-code-alist)
|
|
302 ))))
|
|
303 (write-region start end file)
|
|
304 ))
|
|
305 )
|
40
|
306 (t ; for Emacs 19 or older and XEmacs without mule
|
18
|
307 (defalias 'mime-article::write-region 'write-region)
|
|
308 ))
|
4
|
309
|
|
310 (defun mime-article/decode-message/partial (beg end cal)
|
|
311 (goto-char beg)
|
|
312 (let* ((root-dir (expand-file-name
|
|
313 (concat "m-prts-" (user-login-name)) mime/tmp-dir))
|
|
314 (id (cdr (assoc "id" cal)))
|
|
315 (number (cdr (assoc "number" cal)))
|
|
316 (total (cdr (assoc "total" cal)))
|
|
317 file
|
|
318 (mother mime::article/preview-buffer)
|
18
|
319 )
|
|
320 (or (file-exists-p root-dir)
|
4
|
321 (make-directory root-dir)
|
18
|
322 )
|
4
|
323 (setq id (replace-as-filename id))
|
|
324 (setq root-dir (concat root-dir "/" id))
|
18
|
325 (or (file-exists-p root-dir)
|
4
|
326 (make-directory root-dir)
|
18
|
327 )
|
4
|
328 (setq file (concat root-dir "/FULL"))
|
18
|
329 (if (file-exists-p file)
|
|
330 (let ((full-buf (get-buffer-create "FULL"))
|
|
331 (pwin (or (get-buffer-window mother)
|
|
332 (get-largest-window)))
|
|
333 )
|
|
334 (save-window-excursion
|
|
335 (set-buffer full-buf)
|
|
336 (erase-buffer)
|
|
337 (as-binary-input-file (insert-file-contents file))
|
|
338 (setq major-mode 'mime/show-message-mode)
|
|
339 (mime/viewer-mode mother)
|
4
|
340 )
|
18
|
341 (set-window-buffer pwin
|
|
342 (save-excursion
|
|
343 (set-buffer full-buf)
|
|
344 mime::article/preview-buffer))
|
|
345 (select-window pwin)
|
|
346 )
|
|
347 (re-search-forward "^$")
|
|
348 (goto-char (1+ (match-end 0)))
|
|
349 (setq file (concat root-dir "/" number))
|
|
350 (mime-article::write-region (point) (point-max) file)
|
|
351 (let ((total-file (concat root-dir "/CT")))
|
|
352 (setq total
|
|
353 (if total
|
|
354 (progn
|
|
355 (or (file-exists-p total-file)
|
|
356 (save-excursion
|
20
|
357 (set-buffer
|
|
358 (get-buffer-create mime/temp-buffer-name))
|
18
|
359 (erase-buffer)
|
|
360 (insert total)
|
20
|
361 (write-file total-file)
|
18
|
362 (kill-buffer (current-buffer))
|
|
363 ))
|
|
364 (string-to-number total)
|
|
365 )
|
|
366 (and (file-exists-p total-file)
|
|
367 (save-excursion
|
|
368 (set-buffer (find-file-noselect total-file))
|
20
|
369 (prog1
|
|
370 (and (re-search-forward "[0-9]+" nil t)
|
|
371 (string-to-number
|
|
372 (buffer-substring (match-beginning 0)
|
|
373 (match-end 0)))
|
|
374 )
|
|
375 (kill-buffer (current-buffer))
|
|
376 )))
|
18
|
377 )))
|
|
378 (if (and total (> total 0))
|
|
379 (catch 'tag
|
|
380 (save-excursion
|
|
381 (set-buffer (get-buffer-create mime/temp-buffer-name))
|
|
382 (let ((full-buf (current-buffer)))
|
|
383 (erase-buffer)
|
|
384 (let ((i 1))
|
|
385 (while (<= i total)
|
|
386 (setq file (concat root-dir "/" (int-to-string i)))
|
20
|
387 (or (file-exists-p file)
|
18
|
388 (throw 'tag nil)
|
20
|
389 )
|
18
|
390 (as-binary-input-file (insert-file-contents file))
|
|
391 (goto-char (point-max))
|
|
392 (setq i (1+ i))
|
4
|
393 ))
|
18
|
394 (as-binary-output-file (write-file (concat root-dir "/FULL")))
|
|
395 (let ((i 1))
|
|
396 (while (<= i total)
|
|
397 (let ((file (format "%s/%d" root-dir i)))
|
|
398 (and (file-exists-p file)
|
|
399 (delete-file file)
|
4
|
400 ))
|
18
|
401 (setq i (1+ i))
|
|
402 ))
|
|
403 (let ((file (expand-file-name "CT" root-dir)))
|
|
404 (and (file-exists-p file)
|
|
405 (delete-file file)
|
|
406 ))
|
|
407 (save-window-excursion
|
|
408 (setq major-mode 'mime/show-message-mode)
|
|
409 (mime/viewer-mode mother)
|
|
410 )
|
|
411 (let ((pwin (or (get-buffer-window mother)
|
|
412 (get-largest-window)
|
|
413 ))
|
|
414 (pbuf (save-excursion
|
|
415 (set-buffer full-buf)
|
|
416 mime::article/preview-buffer)))
|
|
417 (set-window-buffer pwin pbuf)
|
|
418 (select-window pwin)
|
|
419 )))))
|
|
420 )))
|
4
|
421
|
|
422
|
|
423 ;;; @ rot13-47
|
|
424 ;;;
|
|
425
|
44
|
426 (unless (boundp 'view-mode-map)
|
|
427 (require 'view))
|
20
|
428
|
|
429 (defconst mime-view-text/plain-mode-map (copy-keymap view-mode-map))
|
|
430 (define-key mime-view-text/plain-mode-map
|
|
431 "q" (function mime-view-text/plain-exit))
|
|
432
|
|
433 (defun mime-view-text/plain-mode ()
|
|
434 "\\{mime-view-text/plain-mode-map}"
|
|
435 (setq buffer-read-only t)
|
|
436 (setq major-mode 'mime-view-text/plain-mode)
|
|
437 (setq mode-name "MIME-View text/plain")
|
|
438 (use-local-map mime-view-text/plain-mode-map)
|
|
439 )
|
|
440
|
|
441 (defun mime-view-text/plain-exit ()
|
|
442 (interactive)
|
|
443 (kill-buffer (current-buffer))
|
|
444 )
|
|
445
|
4
|
446 (defun mime-article/decode-caesar (beg end cal)
|
|
447 (let* ((cnum (mime-article/point-content-number beg))
|
|
448 (cur-buf (current-buffer))
|
|
449 (new-name (format "%s-%s" (buffer-name) cnum))
|
|
450 (mother mime::article/preview-buffer)
|
|
451 (charset (cdr (assoc "charset" cal)))
|
|
452 (encoding (cdr (assq 'encoding cal)))
|
|
453 (mode major-mode)
|
|
454 str)
|
|
455 (setq str (buffer-substring beg end))
|
20
|
456 (let ((pwin (or (get-buffer-window mother)
|
|
457 (get-largest-window)))
|
|
458 (buf (get-buffer-create new-name))
|
|
459 )
|
|
460 (set-window-buffer pwin buf)
|
|
461 (set-buffer buf)
|
|
462 (select-window pwin)
|
|
463 )
|
4
|
464 (setq buffer-read-only nil)
|
|
465 (erase-buffer)
|
|
466 (insert str)
|
|
467 (goto-char (point-min))
|
|
468 (if (re-search-forward "^\n" nil t)
|
|
469 (delete-region (point-min) (match-end 0))
|
|
470 )
|
|
471 (let ((m (cdr (or (assq mode mime-viewer/code-converter-alist)
|
|
472 (assq t mime-viewer/code-converter-alist)))))
|
|
473 (and (functionp m)
|
|
474 (funcall m charset encoding)
|
|
475 ))
|
|
476 (save-excursion
|
|
477 (set-mark (point-min))
|
|
478 (goto-char (point-max))
|
|
479 (tm:caesar-region)
|
|
480 )
|
20
|
481 (set-buffer-modified-p nil)
|
|
482 (mime-view-text/plain-mode)
|
4
|
483 ))
|
|
484
|
|
485
|
|
486 ;;; @ end
|
|
487 ;;;
|
|
488
|
|
489 (provide 'tm-play)
|
|
490
|
|
491 ;;; tm-play.el ends here
|