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 (mm-insert-file-contents name nil nil nil nil t)))
55 (defun mm-extern-url (handle)
58 (let ((url (cdr (assq 'url (cdr (mm-handle-type handle)))))
59 (name buffer-file-name)
60 (coding-system-for-read mm-binary-coding-system))
62 (error "URL is not specified."))
63 (mm-with-unibyte-current-buffer-mule4
64 (url-insert-file-contents url))
65 (mm-disable-multibyte-mule4)
66 (setq buffer-file-name name)))
68 (defun mm-extern-anon-ftp (handle)
70 (let* ((params (cdr (mm-handle-type handle)))
71 (name (cdr (assq 'name params)))
72 (site (cdr (assq 'site params)))
73 (directory (cdr (assq 'directory params)))
74 (mode (cdr (assq 'mode params)))
75 (path (concat "/" (or mm-extern-anonymous
76 (read-string (format "ID for %s: " site)))
77 "@" site ":" directory "/" name))
78 (coding-system-for-read mm-binary-coding-system))
80 (error "The filename is not specified."))
81 (mm-disable-multibyte-mule4)
82 (mm-insert-file-contents path nil nil nil nil t)))
84 (defun mm-extern-ftp (handle)
85 (let (mm-extern-anonymous)
86 (mm-extern-anon-ftp handle)))
88 (defun mm-extern-mail-server (handle)
90 (let* ((params (cdr (mm-handle-type handle)))
91 (server (cdr (assq 'server params)))
92 (subject (or (cdr (assq 'subject params)) "none"))
93 (buf (current-buffer))
95 (if (y-or-n-p (format "Send a request message to %s?" server))
96 (save-window-excursion
97 (message-mail server subject)
99 (delete-region (point) (point-max))
101 (message "Requesting external body...")
102 (message-send-and-exit)
103 (setq info "Request is sent.")
105 (setq info "Request is not sent."))
106 (goto-char (point-min))
107 (insert "[" info "]\n\n")))
110 (defun mm-inline-external-body (handle &optional no-display)
111 "Show the external-body part of HANDLE.
112 This function replaces the buffer of HANDLE with a buffer contains
114 If NO-DISPLAY is nil, display it. Otherwise, do nothing after replacing."
115 (let* ((access-type (cdr (assq 'access-type
116 (cdr (mm-handle-type handle)))))
117 (func (cdr (assq (intern (downcase access-type))
118 mm-extern-function-alist)))
119 gnus-displaying-mime buf
121 (unless (mm-handle-cache handle)
123 (error (format "Access type (%s) is not supported." access-type)))
125 (mm-insert-part handle)
126 (goto-char (point-max))
128 (setq handles (mm-dissect-buffer t)))
129 (unless (bufferp (car handles))
130 (mm-destroy-parts handles)
131 (error "Multipart external body is not supported."))
132 (save-excursion ;; single part
133 (set-buffer (setq buf (mm-handle-buffer handles)))
135 (funcall func handle)
137 (mm-destroy-parts handles)
139 (mm-handle-set-cache handle handles))
140 (push handles gnus-article-mime-handles))
144 (narrow-to-region (point) (point))
145 (gnus-display-mime (mm-handle-cache handle))
146 (mm-handle-set-undisplayer
149 (let (buffer-read-only)
151 ;; This is only valid on XEmacs.
152 (mapcar (lambda (prop)
154 (face-property 'default prop) (current-buffer)))
155 '(background background-pixmap foreground))
157 (delete-region ,(point-min-marker) ,(point-max-marker))))))))))
159 ;; mm-extern.el ends here