1 ;;; mm-extern.el --- showing message/external-body
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
6 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
7 ;; Keywords: message external-body
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published
13 ;; by the Free Software Foundation; either version 2, or (at your
14 ;; option) any later version.
16 ;; GNU Emacs 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.
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., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
30 (eval-when-compile (require 'cl))
36 (defvar mm-extern-function-alist
37 '((local-file . mm-extern-local-file)
39 (anon-ftp . mm-extern-anon-ftp)
41 ;;; (tftp . mm-extern-tftp)
42 (mail-server . mm-extern-mail-server)
43 ;;; (afs . mm-extern-afs))
46 (defvar mm-extern-anonymous "anonymous")
48 (defun mm-extern-local-file (handle)
50 (let ((name (cdr (assq 'name (cdr (mm-handle-type handle)))))
51 (coding-system-for-read mm-binary-coding-system))
53 (error "The filename is not specified"))
54 (mm-disable-multibyte)
55 (if (file-exists-p name)
56 (mm-insert-file-contents name nil nil nil nil t)
57 (error "File %s is gone" name))))
59 (defun mm-extern-url (handle)
61 (let ((url (cdr (assq 'url (cdr (mm-handle-type handle)))))
62 (name buffer-file-name)
63 (coding-system-for-read mm-binary-coding-system))
65 (error "URL is not specified"))
66 (mm-with-unibyte-current-buffer
67 (mm-url-insert-file-contents url))
68 (mm-disable-multibyte)
69 (setq buffer-file-name name)))
71 (defun mm-extern-anon-ftp (handle)
73 (let* ((params (cdr (mm-handle-type handle)))
74 (name (cdr (assq 'name params)))
75 (site (cdr (assq 'site params)))
76 (directory (cdr (assq 'directory params)))
77 (mode (cdr (assq 'mode params)))
78 (path (concat "/" (or mm-extern-anonymous
79 (read-string (format "ID for %s: " site)))
80 "@" site ":" directory "/" name))
81 (coding-system-for-read mm-binary-coding-system))
83 (error "The filename is not specified"))
84 (mm-disable-multibyte)
85 (mm-insert-file-contents path nil nil nil nil t)))
87 (defun mm-extern-ftp (handle)
88 (let (mm-extern-anonymous)
89 (mm-extern-anon-ftp handle)))
91 (defun mm-extern-mail-server (handle)
93 (let* ((params (cdr (mm-handle-type handle)))
94 (server (cdr (assq 'server params)))
95 (subject (or (cdr (assq 'subject params)) "none"))
96 (buf (current-buffer))
98 (if (y-or-n-p (format "Send a request message to %s?" server))
99 (save-window-excursion
100 (message-mail server subject)
102 (delete-region (point) (point-max))
103 (insert-buffer-substring buf)
104 (message "Requesting external body...")
105 (message-send-and-exit)
106 (setq info "Request is sent.")
108 (setq info "Request is not sent."))
109 (goto-char (point-min))
110 (insert "[" info "]\n\n")))
113 (defun mm-inline-external-body (handle &optional no-display)
114 "Show the external-body part of HANDLE.
115 This function replaces the buffer of HANDLE with a buffer contains
117 If NO-DISPLAY is nil, display it. Otherwise, do nothing after replacing."
118 (let* ((access-type (cdr (assq 'access-type
119 (cdr (mm-handle-type handle)))))
120 (func (cdr (assq (intern
123 (error "Couldn't find access type"))))
124 mm-extern-function-alist)))
125 gnus-displaying-mime buf
127 (unless (mm-handle-cache handle)
129 (error "Access type (%s) is not supported" access-type))
131 (mm-insert-part handle)
132 (goto-char (point-max))
134 (setq handles (mm-dissect-buffer t)))
135 (unless (bufferp (car handles))
136 (mm-destroy-parts handles)
137 (error "Multipart external body is not supported"))
138 (save-excursion ;; single part
139 (set-buffer (setq buf (mm-handle-buffer handles)))
143 (funcall func handle)
146 (mm-destroy-parts handles))))
147 (mm-handle-set-cache handle handles))
148 (setq gnus-article-mime-handles
149 (mm-merge-handles gnus-article-mime-handles handles)))
153 (narrow-to-region (point) (point))
154 (gnus-display-mime (mm-handle-cache handle))
155 (mm-handle-set-undisplayer
158 (let (buffer-read-only)
160 ;; This is only valid on XEmacs.
161 (mapcar (lambda (prop)
163 (face-property 'default prop) (current-buffer)))
164 '(background background-pixmap foreground))
166 (delete-region ,(point-min-marker) ,(point-max-marker))))))))))
170 ;;; mm-extern.el ends here