unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Displaying MIME parts internally/externally in Gnus
@ 2005-11-21  2:42 Stefan Monnier
  2005-12-02 15:11 ` Stefan Monnier
  2005-12-02 16:27 ` Reiner Steib
  0 siblings, 2 replies; 12+ messages in thread
From: Stefan Monnier @ 2005-11-21  2:42 UTC (permalink / raw)


Many attachments come with poor content-type description, in which case Gnus
typically doesn't know what to do with it.  When doing "view externally",
such attachments are actually saved.  I don't know about you, but I don't
consider "saving" as a sort of "viewing" activity.  If I had wanted to save
the attachment I'd have used something more like, say, the "Save"
command instead, don't you think?

Similar problems happen for "view internally".  So I suggest the patch below
which tries harder to show the attachment internally or externally: if the
content-type can't be displayed as requested, it asks the user what kind of
content-type to use instead.

A minor variant of it has been mildly tested (and only on Emacs-CVS), and
it's based on a very shallow understanding of the code, so it's probably
not perfect.

If there's no objection I'll install it, otherwise please tell me what's
wrong with it.


        Stefan


--- gnus-art.el	23 oct 2005 22:29:41 -0400	1.98
+++ gnus-art.el	20 nov 2005 21:33:17 -0500	
@@ -4276,14 +4276,16 @@
 	 (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
+                     pred nil
 		     (gnus-mime-view-part-as-type-internal))))
   (gnus-article-check-buffer)
   (let ((handle (get-text-property (point) 'gnus-data)))
@@ -4450,12 +4452,18 @@
 	 (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)))
+          (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)))))
+          (mm-display-part handle))))))
 
 (defun gnus-mime-view-part-internally (&optional handle)
   "View the MIME part under point with an internal viewer.
@@ -4467,13 +4475,16 @@
 	 (mm-inline-large-images t)
 	 (mail-parse-charset gnus-newsgroup-charset)
 	 (mail-parse-ignored-charsets
-	  (save-excursion (set-buffer gnus-summary-buffer)
+          (with-current-buffer gnus-summary-buffer
 			  gnus-newsgroup-ignored-charsets))
 	 (inhibit-read-only t))
+    (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)))))
+          (mm-display-part handle))))))
 
 (defun gnus-mime-action-on-part (&optional action)
   "Do something with the MIME attachment at \(point\)."

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2006-05-06 12:42 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-21  2:42 Displaying MIME parts internally/externally in Gnus Stefan Monnier
2005-12-02 15:11 ` Stefan Monnier
     [not found]   ` <m31wvwgt0w.fsf@quimbies.gnus.org>
     [not found]     ` <873bgcns63.fsf-monnier+emacs@gnu.org>
     [not found]       ` <m3mzekdxn0.fsf@quimbies.gnus.org>
     [not found]         ` <jwvwtdomay3.fsf-monnier+emacs@gnu.org>
     [not found]           ` <m3vet8p2w4.fsf@quimbies.gnus.org>
2006-05-03 14:01             ` Reiner Steib
2006-05-03 16:36               ` Lars Magne Ingebrigtsen
2006-05-03 23:32               ` Katsumi Yamaoka
2006-05-04 11:01                 ` Reiner Steib
2006-05-04 12:04                   ` Stefan Monnier
2006-05-04 12:43                     ` Reiner Steib
2006-05-04 15:18                       ` Stefan Monnier
2006-05-06 12:42                         ` Reiner Steib
2005-12-02 16:27 ` Reiner Steib
2005-12-02 21:28   ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).