tm 7.38.
[elisp/tm.git] / tm-file.el
1 ;;;
2 ;;; tm-file.el --- tm-view internal method for file extraction
3 ;;;
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1995 MORIOKA Tomohiko
6 ;;;
7 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;; Version:
9 ;;;     $Id: tm-file.el,v 7.2 1995/12/21 18:08:22 morioka Exp $
10 ;;; Keywords: mail, news, MIME, multimedia
11 ;;;
12 ;;; This file is part of tm (Tools for MIME).
13 ;;;
14 ;;; This program is free software; you can redistribute it and/or
15 ;;; modify it under the terms of the GNU General Public License as
16 ;;; published by the Free Software Foundation; either version 2, or
17 ;;; (at your option) any later version.
18 ;;;
19 ;;; This program is distributed in the hope that it will be useful,
20 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22 ;;; General Public License for more details.
23 ;;;
24 ;;; You should have received a copy of the GNU General Public License
25 ;;; along with This program.  If not, write to the Free Software
26 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 ;;;
28 ;;; Code:
29
30 (require 'tm-view)
31
32 (defun mime-article/extract-file (beg end cal)
33   (goto-char beg)
34   (let* ((name
35           (save-restriction
36             (narrow-to-region beg end)
37             (mime-article/get-filename cal)
38             ))
39          (encoding (cdr (assq 'encoding cal)))
40          (filename
41           (if name
42               (expand-file-name name
43                                 (call-interactively
44                                  (function
45                                   (lambda (dir)
46                                     (interactive "DDirectory: ")
47                                     dir))))
48             (call-interactively
49              (function
50               (lambda (file)
51                 (interactive "FFilename: ")
52                 (expand-file-name file))))))
53          (the-buf (current-buffer))
54          (tmp-buf (generate-new-buffer (file-name-nondirectory filename)))
55          )
56     (re-search-forward "\n\n")
57     (append-to-buffer tmp-buf (match-end 0) end)
58     (save-excursion
59       (set-buffer tmp-buf)
60       (mime/decode-region encoding (point-min)(point-max))
61       (let ((mc-flag nil)                   ; for Mule
62             (file-coding-system
63              (if (featurep 'mule) *noconv*))
64             kanji-flag                      ; for NEmacs
65             (emx-binary-mode t)             ; for OS/2
66             jka-compr-compression-info-list ; for jka-compr
67             jam-zcat-filename-list          ; for jam-zcat
68             require-final-newline)
69         (write-file filename)
70         )
71       (kill-buffer tmp-buf)
72       )))
73
74
75 ;;; @ setup
76 ;;;
77
78 (set-atype 'mime/content-decoding-condition
79            '((mode . "extract")
80              (method . mime-article/extract-file)
81              ))
82
83 (set-atype 'mime/content-decoding-condition
84            '((type . "application/octet-stream")
85              (method . mime-article/extract-file)
86              ))
87
88
89 ;;; @ end
90 ;;;
91
92 (provide 'tm-file)