From 54e573e6f6f76c59e958cc20840dc3b57e72ee0a Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Fri, 5 May 2006 01:53:06 +0000 Subject: [PATCH] Revision: emacs@sv.gnu.org/emacs--devo--0--patch-265 Merge from gnus--rel--5.10 Patches applied: * gnus--rel--5.10 (patch 99-100) - Merge from emacs--devo--0 - Update from CVS --- lisp/gnus/ChangeLog | 21 +++++++++++++++ lisp/gnus/gnus-art.el | 61 +++++++++++++++++++++++++++--------------- lisp/gnus/mm-decode.el | 22 +++++++-------- 3 files changed, 71 insertions(+), 33 deletions(-) diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog index cecc180f522..7f0f248c7cf 100644 --- a/lisp/gnus/ChangeLog +++ b/lisp/gnus/ChangeLog @@ -1,3 +1,24 @@ +2006-05-04 Stefan Monnier + + * mm-decode.el (mm-dissect-buffer): Remove spurious double assignment. + (mm-copy-to-buffer): Use with-current-buffer. + (mm-display-part): Simplify. + (mm-inlinable-p): Add optional arg `type'. + + * gnus-art.el (gnus-mime-view-part-as-type): Add optional PRED + argument. + (gnus-mime-view-part-externally, gnus-mime-view-part-internally): + Try harder to show the attachment internally or externally using + gnus-mime-view-part-as-type. + +2006-05-04 Reiner Steib + + * gnus-art.el (gnus-mime-view-part-as-type-internal): Try to fetch + `filename' from Content-Disposition if Content-Type doesn't + provide `name'. + (gnus-mime-view-part-as-type): Set default instead of + initial-input. + 2006-04-28 Katsumi Yamaoka * mm-uu.el (mm-uu-pgp-encrypted-extract-1): Assume buffer is made diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el index 7e3b843d500..208103f805d 100644 --- a/lisp/gnus/gnus-art.el +++ b/lisp/gnus/gnus-art.el @@ -4317,21 +4317,29 @@ Deleting parts may malfunction or destroy the article; continue? ") (defun gnus-mime-view-part-as-type-internal () (gnus-article-check-buffer) - (let* ((name (mail-content-type-get - (mm-handle-type (get-text-property (point) 'gnus-data)) - 'name)) + (let* ((handle (get-text-property (point) 'gnus-data)) + (name (or + ;; Content-Type: foo/bar; name=... + (mail-content-type-get (mm-handle-type handle) 'name) + ;; Content-Disposition: attachment; filename=... + (cdr (assq 'filename (cdr (mm-handle-disposition handle)))))) (def-type (and name (mm-default-file-encoding name)))) (and def-type (cons def-type 0)))) -(defun gnus-mime-view-part-as-type (&optional mime-type) - "Choose a MIME media type, and view the part as such." +(defun gnus-mime-view-part-as-type (&optional mime-type pred) + "Choose a MIME media type, and view the part as such. +If non-nil, PRED is a predicate to use during completion to limit the +available media-types." (interactive) (unless mime-type - (setq mime-type (completing-read - "View as MIME type: " - (mapcar #'list (mailcap-mime-types)) - nil nil - (gnus-mime-view-part-as-type-internal)))) + (setq mime-type + (let ((default (gnus-mime-view-part-as-type-internal))) + (completing-read + (format "View as MIME type (default %s): " + (car default)) + (mapcar #'list (mailcap-mime-types)) + pred nil nil nil + (car default))))) (gnus-article-check-buffer) (let ((handle (get-text-property (point) 'gnus-data))) (when handle @@ -4511,12 +4519,18 @@ specified charset." (mm-inlined-types nil) (mail-parse-charset gnus-newsgroup-charset) (mail-parse-ignored-charsets - (save-excursion (set-buffer gnus-summary-buffer) - gnus-newsgroup-ignored-charsets))) - (when handle - (if (mm-handle-undisplayer handle) - (mm-remove-part handle) - (mm-display-part handle))))) + (with-current-buffer gnus-summary-buffer + gnus-newsgroup-ignored-charsets)) + (type (mm-handle-media-type handle)) + (method (mailcap-mime-info type)) + (mm-enable-external t)) + (if (not (stringp method)) + (gnus-mime-view-part-as-type + nil (lambda (type) (stringp (mailcap-mime-info type)))) + (when handle + (if (mm-handle-undisplayer handle) + (mm-remove-part handle) + (mm-display-part handle)))))) (defun gnus-mime-view-part-internally (&optional handle) "View the MIME part under point with an internal viewer. @@ -4528,13 +4542,16 @@ If no internal viewer is available, use an external viewer." (mm-inline-large-images t) (mail-parse-charset gnus-newsgroup-charset) (mail-parse-ignored-charsets - (save-excursion (set-buffer gnus-summary-buffer) - gnus-newsgroup-ignored-charsets)) + (with-current-buffer gnus-summary-buffer + gnus-newsgroup-ignored-charsets)) (inhibit-read-only t)) - (when handle - (if (mm-handle-undisplayer handle) - (mm-remove-part handle) - (mm-display-part handle))))) + (if (not (mm-inlinable-p handle)) + (gnus-mime-view-part-as-type + nil (lambda (type) (mm-inlinable-p handle type))) + (when handle + (if (mm-handle-undisplayer handle) + (mm-remove-part handle) + (mm-display-part handle)))))) (defun gnus-mime-action-on-part (&optional action) "Do something with the MIME attachment at \(point\)." diff --git a/lisp/gnus/mm-decode.el b/lisp/gnus/mm-decode.el index b79e081f0e1..c5fd5d3c258 100644 --- a/lisp/gnus/mm-decode.el +++ b/lisp/gnus/mm-decode.el @@ -562,7 +562,7 @@ Postpone undisplaying of viewers for types in description) (setq type (split-string (car ctl) "/")) (setq subtype (cadr type) - type (pop type)) + type (car type)) (setq result (cond @@ -641,16 +641,15 @@ Postpone undisplaying of viewers for types in (defun mm-copy-to-buffer () "Copy the contents of the current buffer to a fresh buffer." - (save-excursion (let ((obuf (current-buffer)) beg) (goto-char (point-min)) (search-forward-regexp "^\n" nil t) (setq beg (point)) - (set-buffer + (with-current-buffer ;; Preserve the data's unibyteness (for url-insert-file-contents). (let ((default-enable-multibyte-characters (mm-multibyte-p))) - (generate-new-buffer " *mm*"))) + (generate-new-buffer " *mm*")) (insert-buffer-substring obuf beg) (current-buffer)))) @@ -701,7 +700,8 @@ external if displayed external." (forward-line 1) (mm-insert-inline handle (mm-get-part handle)) 'inline) - (if (and method ;; If nil, we always use "save". + (setq external + (and method ;; If nil, we always use "save". (stringp method) ;; 'mailcap-save-binary-file (or (eq mm-enable-external t) (and (eq mm-enable-external 'ask) @@ -714,9 +714,7 @@ external if displayed external." (concat " \"" (format method filename) "\"") "") - "? "))))) - (setq external t) - (setq external nil)) + "? ")))))) (if external (mm-display-external handle (or method 'mailcap-save-binary-file)) @@ -1019,10 +1017,12 @@ external if displayed external." methods nil))) result)) -(defun mm-inlinable-p (handle) - "Say whether HANDLE can be displayed inline." +(defun mm-inlinable-p (handle &optional type) + "Say whether HANDLE can be displayed inline. +TYPE is the mime-type of the object; it defaults to the one given +in HANDLE." + (unless type (setq type (mm-handle-media-type handle))) (let ((alist mm-inline-media-tests) - (type (mm-handle-media-type handle)) test) (while alist (when (string-match (caar alist) type) -- 2.39.2