X-Git-Url: https://cgit.sxemacs.org/?a=blobdiff_plain;f=lisp%2Fmm-decode.el;h=99076ccda8b49dafec382b73a29d8055c04ba2f0;hb=5373bfad87db6ba2d971da5ae2fc17888518267b;hp=a807b9c4bb432e6adec3a1d4dee1796c2c2e332b;hpb=be1899eee844f46edaefc78441a7a40b62d00570;p=gnus diff --git a/lisp/mm-decode.el b/lisp/mm-decode.el index a807b9c4b..99076ccda 100644 --- a/lisp/mm-decode.el +++ b/lisp/mm-decode.el @@ -35,6 +35,7 @@ (eval-and-compile (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) @@ -1076,21 +1077,44 @@ external if displayed external." ;;; Functions for outputting parts ;;; -(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)) +(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 &optional no-cache) + "Return the contents of HANDLE as a string. +If NO-CACHE is non-nil, cached contents of a message/external-body part +are ignored." + (if (and (not no-cache) + (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) - "Insert the contents of HANDLE in the current buffer." +(defun mm-insert-part (handle &optional no-cache) + "Insert the contents of HANDLE in the current buffer. +If NO-CACHE is non-nil, cached contents of a message/external-body part +are ignored." (save-excursion (insert (cond ((eq (mail-content-type-get (mm-handle-type handle) 'charset) @@ -1098,9 +1122,9 @@ external if displayed external." (with-current-buffer (mm-handle-buffer handle) (buffer-string))) ((mm-multibyte-p) - (mm-string-as-multibyte (mm-get-part handle))) + (mm-string-as-multibyte (mm-get-part handle no-cache))) (t - (mm-get-part handle)))))) + (mm-get-part handle no-cache)))))) (defun mm-file-name-delete-whitespace (file-name) "Remove all whitespace characters from FILE-NAME." @@ -1143,18 +1167,19 @@ string if you do not like underscores." (defun mm-save-part (handle &optional prompt) "Write HANDLE to a file. PROMPT overrides the default one used to ask user for a file name." - (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 (or prompt "Save MIME part to: ") - (or mm-default-directory default-directory) - nil nil (or filename name "")))) + (read-file-name (or prompt "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? "