(semi-modules-to-compile): Delete `mime-ftp'.
[elisp/semi.git] / mime-file.el
1 ;;; mime-file.el --- mime-view internal method for file extraction
2
3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; modified by Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
7 ;; Version: $Id: mime-file.el,v 0.0 1997-02-27 05:44:03 tmorioka Exp $
8 ;; Keywords: file, extract, MIME, multimedia, mail, news
9
10 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
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 'mime-view)
30
31 (defun mime-article/extract-file (beg end cal)
32   (goto-char beg)
33   (let* ((name
34           (save-restriction
35             (narrow-to-region beg end)
36             (mime-article/get-filename cal)
37             ))
38          (encoding (cdr (assq 'encoding cal)))
39          (filename
40           (if (and name (not (string-equal name "")))
41               (expand-file-name name
42                                 (call-interactively
43                                  (function
44                                   (lambda (dir)
45                                     (interactive "DDirectory: ")
46                                     dir))))
47             (call-interactively
48              (function
49               (lambda (file)
50                 (interactive "FFilename: ")
51                 (expand-file-name file))))))
52          (the-buf (current-buffer))
53          (tmp-buf (generate-new-buffer (file-name-nondirectory filename)))
54          )
55     (if (file-exists-p filename)
56         (or (yes-or-no-p (format "File %s exists. Save anyway? " filename))
57             (error "")))
58     (re-search-forward "\n\n")
59     (append-to-buffer tmp-buf (match-end 0) end)
60     (save-excursion
61       (set-buffer tmp-buf)
62       (mime-decode-region (point-min)(point-max) encoding)
63       (let ((coding-system-for-write 'no-conversion)
64             jka-compr-compression-info-list ; for jka-compr
65             jam-zcat-filename-list          ; for jam-zcat
66             require-final-newline)
67         (write-file filename)
68         )
69       (kill-buffer tmp-buf)
70       )))
71
72
73 ;;; @ setup
74 ;;;
75
76 (set-atype 'mime/content-decoding-condition
77            '((type . "application/octet-stream")
78              (method . mime-article/extract-file)
79              )
80            'ignore '(method)
81            'replacement)
82
83 (set-atype 'mime/content-decoding-condition
84            '((mode . "extract")
85              (method . mime-article/extract-file)
86              )
87            'remove
88            '((method "mime-file"  nil 'file 'type 'encoding 'mode 'name)
89              (mode . "extract"))
90            'replacement)
91
92
93 ;;; @ end
94 ;;;
95
96 (provide 'mime-file)
97
98 ;;; end of mime-file.el