Fix setting.
[elisp/semi.git] / mime-file.el
1 ;;; mime-file.el --- mime-view internal method for file extraction
2
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; modified by Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
7 ;; Keywords: file, extract, MIME, multimedia, mail, news
8
9 ;; This file is part of SEMI (Saver for Emacs MIME Interfaces).
10
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
15
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Code:
27
28 (require 'mime-view)
29
30 (defun mime-extract-current-entity (beg end cal)
31   (goto-char beg)
32   (let* ((name
33           (save-restriction
34             (narrow-to-region beg end)
35             (mime-article/get-filename cal)
36             ))
37          (encoding (cdr (assq 'encoding cal)))
38          (filename
39           (if (and name (not (string-equal name "")))
40               (expand-file-name name
41                                 (call-interactively
42                                  (function
43                                   (lambda (dir)
44                                     (interactive "DDirectory: ")
45                                     dir))))
46             (call-interactively
47              (function
48               (lambda (file)
49                 (interactive "FFilename: ")
50                 (expand-file-name file))))))
51          )
52     (if (file-exists-p filename)
53         (or (yes-or-no-p (format "File %s exists. Save anyway? " filename))
54             (error "")))
55     (re-search-forward "\n\n")
56     (mime-write-decoded-region (match-end 0)(point-max) filename encoding)
57     ))
58
59
60 ;;; @ setup
61 ;;;
62
63 (set-atype 'mime-acting-condition
64            '((type . "application/octet-stream")
65              (method . mime-extract-current-entity)
66              )
67            'ignore '(method)
68            'replacement)
69
70 (set-atype 'mime-acting-condition
71            '((mode . "extract")
72              (method . mime-extract-current-entity)
73              )
74            'remove
75            '((method "tm-file"  nil 'file 'type 'encoding 'mode 'name)
76              (mode . "extract"))
77            'replacement)
78
79
80 ;;; @ end
81 ;;;
82
83 (provide 'mime-file)
84
85 ;;; end of mime-file.el