comparison lisp/gnus/mm-extern.el @ 56927:55fd4f77387a after-merge-gnus-5_10

Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523 Merge from emacs--gnus--5.10, gnus--rel--5.10 Patches applied: * miles@gnu.org--gnu-2004/emacs--gnus--5.10--base-0 tag of miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-464 * miles@gnu.org--gnu-2004/emacs--gnus--5.10--patch-1 Import from CVS branch gnus-5_10-branch * miles@gnu.org--gnu-2004/emacs--gnus--5.10--patch-2 Merge from lorentey@elte.hu--2004/emacs--multi-tty--0, emacs--cvs-trunk--0 * miles@gnu.org--gnu-2004/emacs--gnus--5.10--patch-3 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/emacs--gnus--5.10--patch-4 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-18 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-19 Remove autoconf-generated files from archive * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-20 Update from CVS
author Miles Bader <miles@gnu.org>
date Sat, 04 Sep 2004 13:13:48 +0000
parents
children 0be1bcd6830a
comparison
equal deleted inserted replaced
56926:f8e248e9a717 56927:55fd4f77387a
1 ;;; mm-extern.el --- showing message/external-body
2 ;; Copyright (C) 2000, 2001, 2003 Free Software Foundation, Inc.
3
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
5 ;; Keywords: message external-body
6
7 ;; This file is part of GNU Emacs.
8
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.
13
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.
18
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.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (eval-when-compile (require 'cl))
29
30 (require 'mm-util)
31 (require 'mm-decode)
32 (require 'mm-url)
33
34 (defvar mm-extern-function-alist
35 '((local-file . mm-extern-local-file)
36 (url . mm-extern-url)
37 (anon-ftp . mm-extern-anon-ftp)
38 (ftp . mm-extern-ftp)
39 ;;; (tftp . mm-extern-tftp)
40 (mail-server . mm-extern-mail-server)
41 ;;; (afs . mm-extern-afs))
42 ))
43
44 (defvar mm-extern-anonymous "anonymous")
45
46 (defun mm-extern-local-file (handle)
47 (erase-buffer)
48 (let ((name (cdr (assq 'name (cdr (mm-handle-type handle)))))
49 (coding-system-for-read mm-binary-coding-system))
50 (unless name
51 (error "The filename is not specified"))
52 (mm-disable-multibyte)
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)))))
56
57 (defun mm-extern-url (handle)
58 (erase-buffer)
59 (let ((url (cdr (assq 'url (cdr (mm-handle-type handle)))))
60 (name buffer-file-name)
61 (coding-system-for-read mm-binary-coding-system))
62 (unless url
63 (error "URL is not specified"))
64 (mm-with-unibyte-current-buffer
65 (mm-url-insert-file-contents url))
66 (mm-disable-multibyte)
67 (setq buffer-file-name name)))
68
69 (defun mm-extern-anon-ftp (handle)
70 (erase-buffer)
71 (let* ((params (cdr (mm-handle-type handle)))
72 (name (cdr (assq 'name params)))
73 (site (cdr (assq 'site params)))
74 (directory (cdr (assq 'directory params)))
75 (mode (cdr (assq 'mode params)))
76 (path (concat "/" (or mm-extern-anonymous
77 (read-string (format "ID for %s: " site)))
78 "@" site ":" directory "/" name))
79 (coding-system-for-read mm-binary-coding-system))
80 (unless name
81 (error "The filename is not specified"))
82 (mm-disable-multibyte)
83 (mm-insert-file-contents path nil nil nil nil t)))
84
85 (defun mm-extern-ftp (handle)
86 (let (mm-extern-anonymous)
87 (mm-extern-anon-ftp handle)))
88
89 (defun mm-extern-mail-server (handle)
90 (require 'message)
91 (let* ((params (cdr (mm-handle-type handle)))
92 (server (cdr (assq 'server params)))
93 (subject (or (cdr (assq 'subject params)) "none"))
94 (buf (current-buffer))
95 info)
96 (if (y-or-n-p (format "Send a request message to %s?" server))
97 (save-window-excursion
98 (message-mail server subject)
99 (message-goto-body)
100 (delete-region (point) (point-max))
101 (insert-buffer-substring buf)
102 (message "Requesting external body...")
103 (message-send-and-exit)
104 (setq info "Request is sent.")
105 (message info))
106 (setq info "Request is not sent."))
107 (goto-char (point-min))
108 (insert "[" info "]\n\n")))
109
110 ;;;###autoload
111 (defun mm-inline-external-body (handle &optional no-display)
112 "Show the external-body part of HANDLE.
113 This function replaces the buffer of HANDLE with a buffer contains
114 the entire message.
115 If NO-DISPLAY is nil, display it. Otherwise, do nothing after replacing."
116 (let* ((access-type (cdr (assq 'access-type
117 (cdr (mm-handle-type handle)))))
118 (func (cdr (assq (intern
119 (downcase
120 (or access-type
121 (error "Couldn't find access type"))))
122 mm-extern-function-alist)))
123 gnus-displaying-mime buf
124 handles)
125 (unless (mm-handle-cache handle)
126 (unless func
127 (error (format "Access type (%s) is not supported" access-type)))
128 (with-temp-buffer
129 (mm-insert-part handle)
130 (goto-char (point-max))
131 (insert "\n\n")
132 (setq handles (mm-dissect-buffer t)))
133 (unless (bufferp (car handles))
134 (mm-destroy-parts handles)
135 (error "Multipart external body is not supported"))
136 (save-excursion ;; single part
137 (set-buffer (setq buf (mm-handle-buffer handles)))
138 (let (good)
139 (unwind-protect
140 (progn
141 (funcall func handle)
142 (setq good t))
143 (unless good
144 (mm-destroy-parts handles))))
145 (mm-handle-set-cache handle handles))
146 (setq gnus-article-mime-handles
147 (mm-merge-handles gnus-article-mime-handles handles)))
148 (unless no-display
149 (save-excursion
150 (save-restriction
151 (narrow-to-region (point) (point))
152 (gnus-display-mime (mm-handle-cache handle))
153 (mm-handle-set-undisplayer
154 handle
155 `(lambda ()
156 (let (buffer-read-only)
157 (condition-case nil
158 ;; This is only valid on XEmacs.
159 (mapcar (lambda (prop)
160 (remove-specifier
161 (face-property 'default prop) (current-buffer)))
162 '(background background-pixmap foreground))
163 (error nil))
164 (delete-region ,(point-min-marker) ,(point-max-marker))))))))))
165
166 (provide 'mm-extern)
167
168 ;;; arch-tag: 9653808e-14d9-4172-86e6-adceaa05378e
169 ;;; mm-extern.el ends here