Mercurial > emacs
diff lisp/gnus/mm-decode.el @ 69572:b4faac2800dd
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-163
Merge from gnus--rel--5.10
Patches applied:
* gnus--rel--5.10 (patch 58-61)
- Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sun, 19 Mar 2006 19:39:53 +0000 |
parents | 6580c61aced7 |
children | ab0b847baba4 e3bacb89536a |
line wrap: on
line diff
--- a/lisp/gnus/mm-decode.el Sun Mar 19 19:38:48 2006 +0000 +++ b/lisp/gnus/mm-decode.el Sun Mar 19 19:39:53 2006 +0000 @@ -36,6 +36,7 @@ (autoload 'executable-find "executable") (autoload 'mm-inline-partial "mm-partial") (autoload 'mm-inline-external-body "mm-extern") + (autoload 'mm-extern-cache-contents "mm-extern") (autoload 'mm-insert-inline "mm-view")) (defvar gnus-current-window-configuration) @@ -1082,17 +1083,35 @@ ;;; Functions for outputting parts ;;; +(defmacro mm-with-part (handle &rest forms) + "Run FORMS in the temp buffer containing the contents of HANDLE." + `(let* ((handle ,handle) + ;; The multibyteness of the temp buffer should be turned on + ;; if inserting a multibyte string. Contrarily, the buffer's + ;; multibyteness should be off if inserting a unibyte string, + ;; especially if a string contains 8bit data. + (default-enable-multibyte-characters + (with-current-buffer (mm-handle-buffer handle) + (mm-multibyte-p)))) + (with-temp-buffer + (insert-buffer-substring (mm-handle-buffer handle)) + (mm-disable-multibyte) + (mm-decode-content-transfer-encoding + (mm-handle-encoding handle) + (mm-handle-media-type handle)) + ,@forms))) +(put 'mm-with-part 'lisp-indent-function 1) +(put 'mm-with-part 'edebug-form-spec '(body)) + (defun mm-get-part (handle) "Return the contents of HANDLE as a string." - (let ((default-enable-multibyte-characters - (with-current-buffer (mm-handle-buffer handle) - (mm-multibyte-p)))) - (with-temp-buffer - (insert-buffer-substring (mm-handle-buffer handle)) - (mm-disable-multibyte) - (mm-decode-content-transfer-encoding - (mm-handle-encoding handle) - (mm-handle-media-type handle)) + (if (equal (mm-handle-media-type handle) "message/external-body") + (progn + (unless (mm-handle-cache handle) + (mm-extern-cache-contents handle)) + (with-current-buffer (mm-handle-buffer (mm-handle-cache handle)) + (buffer-string))) + (mm-with-part handle (buffer-string)))) (defun mm-insert-part (handle) @@ -1148,18 +1167,19 @@ (defun mm-save-part (handle) "Write HANDLE to a file." - (let* ((name (mail-content-type-get (mm-handle-type handle) 'name)) - (filename (mail-content-type-get - (mm-handle-disposition handle) 'filename)) - file) + (let ((filename (or (mail-content-type-get + (mm-handle-disposition handle) 'filename) + (mail-content-type-get + (mm-handle-type handle) 'name))) + file) (when filename (setq filename (gnus-map-function mm-file-name-rewrite-functions (file-name-nondirectory filename)))) (setq file (mm-with-multibyte - (read-file-name "Save MIME part to: " - (or mm-default-directory default-directory) - nil nil (or filename name "")))) + (read-file-name "Save MIME part to: " + (or mm-default-directory default-directory) + nil nil (or filename "")))) (setq mm-default-directory (file-name-directory file)) (and (or (not (file-exists-p file)) (yes-or-no-p (format "File %s already exists; overwrite? "