Rupert Swarbrick | 3 Nov 2008 19:13

Re: Auto-overriding *.pdf application/octet-stream MIME type?

Greg Troxel <gdt <at> work.lexort.com> writes:

>   From: Simon Josefsson <simon <at> josefsson.org>
>
>   What do people think about a variable that can be used to auto-override
>   MIME types based on filename extensions?  I get a lot of *.pdf marked as
>   application/octet-stream and selecting 'View as Type' feels dull.
>
> I have been annoyed by dealing with messages that come with wrong mime
> types and definitely second the notion that support would be nice.
>
>   Something like this:
>
>   (setq mm-content-type-mapping
>         '(("application/octet-stream" "*.pdf" "application/pdf")))
>
>   The cells would be of the form (INCOMING-TYPE EXTENSION MAPPED-TYPE),
>   and either of INCOMING-TYPE or EXTENSION can be nil to match anything.
>
> That looks good to me.  I would have at first left out the first item,
> but on reflection I think that almost all miscoded objects are labeled
> application/octet-stream.  This lets one have the narrowest effective
> configuration.

May I suggest that a list of 3 elements is as above, but one can leave
out the first to match all incoming MIME types?

So

  ("application/octet-stream" "*.pdf" "application/pdf")

would be as above and

  ("*.pdf" "application/pdf")

would match more - anything called blah.pdf would be relabelled
application/pdf no matter what MIME type it had.

But I'd suggest that both the first and the second values were treated
as regexes. Then I can say things like

  (".*xml.*" ".*" "application/xml")

(that was off the top of my head. There are probably better
examples). Also, maybe one should allow some magic, so that "*.pdf" gets
turned into ".*\.pdf" for newish users not to get bitten. Maybe rewrite
anything of the form

  ^\*\.\(.*\)$

to

  ^.*\.\\1$

Or maybe strip off the "*" bit and don't require the ^,$?

Anyway, I suspect this problem (of regexes vs shell globs) has been
given a canonical solution somewhere else in the emacs code-base. Does
anyone know?

Rupert

Gmane