[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6. MIME Support

MIME is an emerging standard for multimedia mail. It offers a very flexible typing mechanism. The type of a file or message is specified in two parts, separated by a '/'. The first part is the general category of the data (text, application, image, etc.). The second part is the specific type of data (postscript, png, jpeg, etc.). So `text/html' specifies an HTML document, whereas `image/x-xwindowdump' specifies an image of an Xwindow taken with the `xwd' program.

This typing allows much more flexibility in naming files. HTTP/1.0 servers can now send back content-type headers in response to a request, and not have the client second-guess it based on file extensions. HTML files can now be named `something.png' (not a great idea, but possible).

6.1 Adding MIME types based on file extensions  How to map file extensions onto MIME types (e.g., `.png -> image/png)'.
6.2 Specifying Viewers  How to specify external and internal viewers for files that Emacs/W3 cannot handle natively.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1 Adding MIME types based on file extensions

For some protocols however, it is still necessary to guess the content of a file based on the file extension. This type of guess-work should only be needed when accessing files via FTP, local file access, or old HTTP/0.9 servers.

Instead of specifying how to view things twice, once based on content-type and once based on the file extension, it is easier to map file extensions to MIME content-types. The variable that controls this is mm-mime-extensions.

This variable is an assoc list of file extensions and the corresponding MIME content-type. A sample entry looks like: `(".movie" . "video/x-sgi-movie")' This makes all files that end in `.movie' (`foo.movie' and `bar.movie') be interpreted as SGI animation files. If a content-type is defined for the document, then this is over-ridden. Regular expressions can NOT be used.

Both Mosaic and the NCSA HTTP daemon rely on a separate file for mapping file extensions to MIME types. Instead of having the users of Emacs/W3 duplicate this in lisp, this file can be parsed using the url-parse-mimetypes function. This function is called each time w3 is loaded. It tries to locate mimetype files in several places. If the environment variable MIMETYPES is nonempty, then this is assumed to specify a UNIX-like path of mimetype files (this is a colon separated string of pathnames). If the MIMETYPES environment variable is empty, then Emacs/W3 looks for these files:

  1. `~/.mime-types'
  2. `/etc/mime-types'
  3. `/usr/etc/mime-types'
  4. `/usr/local/etc/mime-types'
  5. `/usr/local/www/conf/mime-types'

Each line contains information for one HTTP type. These types resemble MIME types. To add new ones, use subtypes beginning with x-, such as application/x-myprogram. Lines beginning with # are comment lines, and suitably ignored. Each line consists of:

type/subtype ext1 ext2 ... extn

type/subtype is the MIME-like type of the document. ext* is any number of space-separated filename extensions which correspond to the MIME type.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.2 Specifying Viewers

Not all files look as they should when parsed as an HTML document (whitespace is stripped, paragraphs are reformatted, and lots of little changes that make the document look unrecognizable). Files may be passed to external programs or Emacs Lisp functions to be viewed.

Not all files can be viewed accurately from within an Emacs session (PNG files for example, or audio files). For this reason, the user can specify file "viewers" based on MIME content-types. This is done with a standard mailcap file. See section E. Mailcap Files.

As an alternative, the function mm-add-mailcap-entry can also be used from an appropriate hook. See section 11.5 Hooks. This functions takes three arguments, the major type ("image"), the minor type ("png"), and an assoc list of information about the viewer. Please see the URL documentation for more specific information on what this assoc list should look like.

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by XEmacs Webmaster on October, 2 2007 using texi2html