(mime-edit-x-emacs-value): Don't add mule-version if
[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.3 1997-10-03 11:55:48 shuhei-k 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          (tmp-buf (generate-new-buffer (file-name-nondirectory filename)))
53          )
54     (if (file-exists-p filename)
55         (or (yes-or-no-p (format "File %s exists. Save anyway? " filename))
56             (error "")))
57     (re-search-forward "\n\n")
58     (append-to-buffer tmp-buf (match-end 0) end)
59     (save-excursion
60       (set-buffer tmp-buf)
61       (mime-decode-region (point-min)(point-max) encoding)
62       (let ((coding-system-for-write 'no-conversion)
63             jka-compr-compression-info-list ; for jka-compr
64             jam-zcat-filename-list          ; for jam-zcat
65             require-final-newline)
66         (write-region (point-min)(point-max) filename)
67         )
68       (kill-buffer tmp-buf)
69       )))
70
71
72 ;;; @ setup
73 ;;;
74
75 (set-atype 'mime-acting-condition
76            '((type . "application/octet-stream")
77              (method . mime-article/extract-file)
78              )
79            'ignore '(method)
80            'replacement)
81
82 (set-atype 'mime-acting-condition
83            '((mode . "extract")
84              (method . mime-article/extract-file)
85              )
86            'remove
87            '((method "mime-file"  nil 'file 'type 'encoding 'mode 'name)
88              (mode . "extract"))
89            'replacement)
90
91
92 ;;; @ end
93 ;;;
94
95 (provide 'mime-file)
96
97 ;;; end of mime-file.el