1 ;;; mm-extern.el --- showing message/external-body
2 ;; Copyright (C) 2000 Free Software Foundation, Inc.
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
5 ;; Keywords: message external-body
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published
11 ;; by the Free Software Foundation; either version 2, or (at your
12 ;; option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
34 (defvar mm-extern-function-alist
35 '((local-file . mm-extern-local-file)
37 (anon-ftp . mm-extern-anon-ftp)
39 ;;; (tftp . mm-extern-tftp)
40 (mail-server . mm-extern-mail-server)
41 ;;; (afs . mm-extern-afs))
44 (defvar mm-extern-anonymous "anonymous")
46 (defun mm-extern-local-file (handle)
48 (let ((name (cdr (assq 'name (cdr (mm-handle-type handle)))))
49 (coding-system-for-read mm-binary-coding-system))
51 (error "The filename is not specified."))
52 (mm-disable-multibyte-mule4)
53 (if (file-exists-p name)
54 (mm-insert-file-contents name nil nil nil nil t)
55 (error (format "File %s is gone." name)))))
57 (defun mm-extern-url (handle)
60 (let ((url (cdr (assq 'url (cdr (mm-handle-type handle)))))
61 (name buffer-file-name)
62 (coding-system-for-read mm-binary-coding-system))
64 (error "URL is not specified."))
65 (mm-with-unibyte-current-buffer-mule4
66 (url-insert-file-contents url))
67 (mm-disable-multibyte-mule4)
68 (setq buffer-file-name name)))
70 (defun mm-extern-anon-ftp (handle)
72 (let* ((params (cdr (mm-handle-type handle)))
73 (name (cdr (assq 'name params)))
74 (site (cdr (assq 'site params)))
75 (directory (cdr (assq 'directory params)))
76 (mode (cdr (assq 'mode params)))
77 (path (concat "/" (or mm-extern-anonymous
78 (read-string (format "ID for %s: " site)))
79 "@" site ":" directory "/" name))
80 (coding-system-for-read mm-binary-coding-system))
82 (error "The filename is not specified."))
83 (mm-disable-multibyte-mule4)
84 (mm-insert-file-contents path nil nil nil nil t)))
86 (defun mm-extern-ftp (handle)
87 (let (mm-extern-anonymous)
88 (mm-extern-anon-ftp handle)))
90 (defun mm-extern-mail-server (handle)
92 (let* ((params (cdr (mm-handle-type handle)))
93 (server (cdr (assq 'server params)))
94 (subject (or (cdr (assq 'subject params)) "none"))
95 (buf (current-buffer))
97 (if (y-or-n-p (format "Send a request message to %s?" server))
98 (save-window-excursion
99 (message-mail server subject)
101 (delete-region (point) (point-max))
103 (message "Requesting external body...")
104 (message-send-and-exit)
105 (setq info "Request is sent.")
107 (setq info "Request is not sent."))
108 (goto-char (point-min))
109 (insert "[" info "]\n\n")))
112 (defun mm-inline-external-body (handle &optional no-display)
113 "Show the external-body part of HANDLE.
114 This function replaces the buffer of HANDLE with a buffer contains
116 If NO-DISPLAY is nil, display it. Otherwise, do nothing after replacing."
117 (let* ((access-type (cdr (assq 'access-type
118 (cdr (mm-handle-type handle)))))
119 (func (cdr (assq (intern
122 (error "Couldn't find access type."))))
123 mm-extern-function-alist)))
124 gnus-displaying-mime buf
126 (unless (mm-handle-cache handle)
128 (error (format "Access type (%s) is not supported." access-type)))
130 (mm-insert-part handle)
131 (goto-char (point-max))
133 (setq handles (mm-dissect-buffer t)))
134 (unless (bufferp (car handles))
135 (mm-destroy-parts handles)
136 (error "Multipart external body is not supported."))
137 (save-excursion ;; single part
138 (set-buffer (setq buf (mm-handle-buffer handles)))
142 (funcall func handle)
145 (mm-destroy-parts handles))))
146 (mm-handle-set-cache handle handles))
147 (if (listp (car gnus-article-mime-handles))
148 (push handles gnus-article-mime-handles)
149 (setq gnus-article-mime-handles
150 (list handles gnus-article-mime-handles))))
154 (narrow-to-region (point) (point))
155 (gnus-display-mime (mm-handle-cache handle))
156 (mm-handle-set-undisplayer
159 (let (buffer-read-only)
161 ;; This is only valid on XEmacs.
162 (mapcar (lambda (prop)
164 (face-property 'default prop) (current-buffer)))
165 '(background background-pixmap foreground))
167 (delete-region ,(point-min-marker) ,(point-max-marker))))))))))
169 ;; mm-extern.el ends here