Gnus development mailing list
 help / color / mirror / Atom feed
From: Geoff Kuenning <geoff@cs.hmc.edu>
Subject: [Patch] Improved mm-display-part for application/octet-stream
Date: 19 Jan 2006 00:27:46 -0800	[thread overview]
Message-ID: <pnid5iosjul.fsf@bow.cs.hmc.edu> (raw)

I am constantly frustrated by correspondents with broken mailers who
send me attachments that are identified as application/octet-stream,
even though they have a specific type (90% of the time it's .doc;
another 9% is .pdf) that should be identified as such.

Since I can't do the right thing and fix the broken mailers, I did the
next best thing: I revised mm-display-part to pick out the proper type
based on the file extension.  The revised version is below.  The first
"when" clause is new; everthing else is the same.  If people like the
idea, I'd like to see it get into the main tree (how do I make that
happen?).

(defun mm-display-part (handle &optional no-default)
  "Display the MIME part represented by HANDLE.
Returns nil if the part is removed; inline if displayed inline;
external if displayed external."
  (save-excursion
    (mailcap-parse-mailcaps)
    (if (mm-handle-displayed-p handle)
	(mm-remove-part handle)
      (let* ((type (mm-handle-media-type handle))
	     (method (mailcap-mime-info type)))
	(when (and
               (not method)
               (equal type "application/octet-stream"))
	  (let* ((filename (cdr (assoc 'name (nth 1 handle))))
		(start (string-match "\\.[^.]*$" filename)))
	    (when start
	      (setq type
		    (mailcap-extension-to-mime (substring filename start)))
	      (setq method (mailcap-mime-info type))
	      )))
	(if (mm-inlined-p handle)
	    (progn
	      (forward-line 1)
	      (mm-display-inline handle)
	      'inline)
	  (when (or method
		    (not no-default))
	    (if (and (not method)
		     (equal "text" (car (split-string type))))
		(progn
		  (forward-line 1)
		  (mm-insert-inline handle (mm-get-part handle))
		  'inline)
	      (mm-display-external
	       handle (or method 'mailcap-save-binary-file)))))))))

-- 
    Geoff Kuenning   geoff@cs.hmc.edu   http://www.cs.hmc.edu/~geoff/

If at first you succeed, try to hide your astonishment.
	-- Harry F. Banks



             reply	other threads:[~2006-01-19  8:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-19  8:27 Geoff Kuenning [this message]
2006-01-19 19:54 ` Reiner Steib

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pnid5iosjul.fsf@bow.cs.hmc.edu \
    --to=geoff@cs.hmc.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).