From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/61711 Path: news.gmane.org!not-for-mail From: Geoff Kuenning Newsgroups: gmane.emacs.gnus.general Subject: [Patch] Improved mm-display-part for application/octet-stream Date: 19 Jan 2006 00:27:46 -0800 Organization: Linux Private Site Message-ID: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1137689863 11310 80.91.229.2 (19 Jan 2006 16:57:43 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 19 Jan 2006 16:57:43 +0000 (UTC) Original-X-From: ding-owner+m10239@lists.math.uh.edu Thu Jan 19 17:57:39 2006 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from malifon.math.uh.edu ([129.7.128.13]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Ezd4l-0001MY-IL for ding-account@gmane.org; Thu, 19 Jan 2006 17:55:55 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu ident=lists) by malifon.math.uh.edu with smtp (Exim 3.20 #1) id 1Ezd4c-00020H-00; Thu, 19 Jan 2006 10:55:46 -0600 Original-Received: from nas01.math.uh.edu ([129.7.128.39]) by malifon.math.uh.edu with esmtp (Exim 3.20 #1) id 1EzV96-0000XK-00 for ding@lists.math.uh.edu; Thu, 19 Jan 2006 02:27:52 -0600 Original-Received: from quimby.gnus.org ([80.91.224.244]) by nas01.math.uh.edu with esmtp (Exim 4.52) id 1EzV91-000569-EA for ding@lists.math.uh.edu; Thu, 19 Jan 2006 02:27:52 -0600 Original-Received: from news by quimby.gnus.org with local (Exim 3.35 #1 (Debian)) id 1EzV90-0002g5-00 for ; Thu, 19 Jan 2006 09:27:46 +0100 Original-To: ding@gnus.org Original-Path: not-for-mail Original-Newsgroups: gnus.ding Original-Lines: 53 Original-NNTP-Posting-Host: wl-119.cine.hmc.edu Original-X-Trace: quimby.gnus.org 1137659266 9031 134.173.200.119 (19 Jan 2006 08:27:46 GMT) Original-X-Complaints-To: usenet@quimby.gnus.org Original-NNTP-Posting-Date: Thu, 19 Jan 2006 08:27:46 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 X-Spam-Score: -2.6 (--) Precedence: bulk Original-Sender: ding-owner@lists.math.uh.edu Xref: news.gmane.org gmane.emacs.gnus.general:61711 Archived-At: 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