Chapter 3

Understanding MIME


CONTENTS


Introduction

As you will learn later in this book, Multipurpose Internet Mail Extensions (MIME) play an important part in the world of Netscape Navigator plug-ins. MIME was originally created for handling additional data types in electronic mail. With the advent of the World Wide Web, MIME was quickly adopted for use in Web servers and browsers.

A plug-in is registered by the Navigator using resource embedded MIME information. The file extension used for a given file is an important part of determining the file's MIME type. For example, a file in Microsoft wave audio format has no MIME information in the actual file. The MIME type-in this case, audio/x-wav-is determined by the file extension only.

Developers of plug-ins supporting new data types need to create a new MIME type for the data files. A new MIME type or subtype should be prefaced with an x-. The new type should be submitted to the Internet Assigned Numbers Authority (IANA) for formal review. In most cases, you only need a subtype. A new top-level type requires publication of an RFC and must go through the Internet standards process.

MIME Overview

When the standards for Internet mail were created in 1982, they provided for only ASCII characters and a 1000-character line limit, and they had a message length restriction. As time passed and technology such as multimedia came of age, a new electronic mail standard was needed to handle the large number of new data types. The MIME standard was adopted 10 years later in 1992.

Using the new MIME standard, a mail message can contain the following:

Images
Audio
Video
Binary data
Multiple fonts
Additional character sets
Multiple objects in the same message
Unlimited line and message length

To handle these new data types, MIME defines the following header fields:

As a plug-in developer, you are really only concerned with the Content-Type and the file extension.

Content Types

The current MIME standard supports a number of top-level MIME types. Some of these types, such as multipart and message, apply only to electronic mail and might not have any Navigator plug-in applications. The current top level types are covered in the following sections.

text

The text type is a human-readable format used to represent text in a number of different character sets. Examples of text subtypes are plain, richtext, and html.

multipart

The multipart type allows a mail message to combine several different MIME types within a single message. This format has very little application for plug-ins.

application

The application type is a catch-all for binary data. If your plug-in uses binary data that is not an image, audio, or video, this one's for you. Some current application subtypes are postscript, wordperfect5.1, mathmatica, and zip.

message

The message type is used to encapsulate a mail message. Again, this is not of much use for plug-ins.

image

The image type handles still image or picture data in many different formats. This type plays an important role in displaying graphics on a Web browser. Some examples are jpeg, gif, and tiff.

audio

The audio type handles audio data, usually in PCM format. Most audio subtypes such as x-wav and x-aiff are still going through IANA approval. Approved audio subtypes are basic and 32kadpcm.

video

The video type is used for transmitting video data. This video data can contain interleaved audio, depending on the video file format. mpeg and quicktime are examples of video subtypes.

Current MIME Types and Subtypes

The Content-Type header field is most important because it contains the MIME type and subtype. The syntax for this field is as follows:

type/subtype[;parameter]

The Internet Assigned Numbers Authority (IANA) is in charge of approving and tracking media types and subtypes for use in the MIME specification. IANA is operated by the Information Sciences Institute (ISI) of the University of Southern California (USC). You might want to visit their home page at http://www.isi.edu.

Figure 3.1 : The Information Sciences Institute home page.

For a current list of IANA approved media types, keep an eye on this file:

ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/media-types

At the time of this writing, IANA's approved type and subtype list looks like this:

Type            Subtype         Description                 Reference
----            ------         ----------                 --------
text            plain                            [RFC152 1,Borenstein]
                richtext                         [R FC1521,Borenstein]
                enriched                         &n bsp;          [RFC1896]
                tab-separated-values                   [Paul Lindner]
                html                                         [RFC1866]
                sgml                                         [RFC1874]

multipart       mixed                            [RFC1521,Borenstein]
                alternative                      [RFC1521,Borenste in]
                digest                         &nbs p; [RFC1521,Borenstein]
                parallel                         [R FC1521,Borenstein]
                appledouble                [MacMime,Patrik Faltstrom]
                header-set                              [Dave Crocker]
                form-data                         & nbsp;         [RFC1867]
                related                         &nb sp;           [RFC1872]
                report                         &nbs p;            [RFC1892]
                voice-message                        &nb sp;      [RFC1911]

message         rfc822                           [RFC1521,Borenstein]
                partial                         &nb sp;[RFC1521,Borenstein]
                external-body                    [RFC1521,Borenstein]
                news                        [RFC 1036, Henry Spencer]

application     octet-stream                     [RFC1521,Borenstein]
                postscript                       [RFC1521,Bor enstein]
                oda                          & nbsp;   [RFC1521,Borenstein]
                atomicmail                    [atomicmail,Borenstein]
                andrew-inset                [andrew-inset,Borenstein]
                slate                           ; [slate,terry crowley]
                wita              [Wang Info Transfer,Larry Campbell]
                dec-dx            [Digital Doc Trans, Larry Campbell]
                dca-rft        [IBM Doc Content Arch, Larry Campbell]
                activemessage                        &nb sp; [Ehud Shapiro]
                rtf                          & nbsp;         [Paul Lindner]
                applefile                  [MacMime,Patrik Faltstrom]
                mac-binhex40               [MacMime,Patrik Faltstrom]
                news-message-id              [RFC1036, Henry Spencer]
                news-transmission            [RFC1036, Henry Spencer]
                wordperfect5.1                        &n bsp;[Paul Lindner]
                pdf                          & nbsp;         [Paul Lindner]
                zip                          & nbsp;         [Paul Lindner]
                macwriteii                              [Paul Lindner]
                msword                         &nbs p;       [Paul Lindner]
                remote-printing                        [ RFC1486,Rose]
                mathematica                          ;    [Van Nostern]
                cybercash                         & nbsp;        [Eastlake]
                commonground                        &nbs p;        [Glazer]
                iges                                           [Parks]
                riscos                         &nbs p;              [Smith]
                eshop                           ;                [Katz]
                x400-bp                         &nb sp;           [RFC1494]
                sgml                                         [RFC1874]
                cals-1840                         & nbsp;         [RFC1895]
                vnd.framemaker                        &n bsp;      [Wexler]
                vnd.mif                         &nb sp;            [Wexler]
                vnd.ms-excel                        &nbs p;          [Gill]
                vnd.ms-powerpoint                         ;      [Gill]
                vnd.ms-project                        &n bsp;        [Gill]
                vnd.ms-works                        &nbs p;          [Gill]
                vnd.ms-tnef                          ;           [Gill]
                vnd.svd                         &nb sp;            [Becker]
                vnd.music-niff                        &n bsp;      [Butler]
                
image           jpeg                             [RFC152 1,Borenstein]
                gif                          & nbsp;   [RFC1521,Borenstein]
                ief             Image Exchange Format       [RFC1314]
                g3fax                           ;             [RFC1494]
                tiff            Tag Image File Format          [Rose]
                cgm             Computer Graphics Metafile  [Francis]
                naplps                         &nbs p;             [Ferber]
                vnd.dwg                         &nb sp;            [Moline]
                vnd.svf                         &nb sp;            [Moline]
                vnd.dxf                         &nb sp;            [Moline]

audio           basic                            [RFC1521,Bor enstein]
                32kadpcm                         &n bsp;          [RFC1911]

video           mpeg                             [RFC152 1,Borenstein]
                quicktime                         & nbsp;    [Paul Lindner]
                vnd.vivo                         &n bsp;            [Wolfe]

Notice that the reference field holds the Request for Comment (RFC) document numbers that contain further specification for the given media type. A number of places archive RFCs. Here is a convenient URL for reading RFCs:

http://www.uwaterloo.ca/uw_infoserv/rfc.html

For easy access to IANA information, check out their home page at this address:

http://www.isi.edu/div7/iana

Figure 3.2 shows IANA's home page at the time of this writing.

Figure 3.2 : The Internet Assigned Numbers Authority home page.

Netscape Navigator and MIME Configuration

Netscape Navigator provides a means for you to configure MIME types with helper applications. Figure 3.3 shows the Helpers configuration screen for Navigator 3.x. The first column indicates the file type or the MIME type. The second column determines the action that the browser should take when encountering this MIME type. These actions can be the name of a helper application or the keywords Ask User, Browser, and Save. The Action column can also contain the name of an external program to use as a helper application. The third column determines the file extension that is associated with the given MIME type.

Figure 3.3 : Navigator's 3.x MIME type configuration screen.

You can toggle the associated action for a MIME type by selecting one of the four radio buttons: View in Browser, Save to Disk, Unknown: Prompt User, and Launch the Application. These buttons correspond to the column actions Browser, Save, Ask User, and the application name, respectively.

As you might have guessed, the Browser keyword indicates that the Web browser should handle the MIME type internally. Good examples of this are image/gif and text/html. Save, as the name says, simply saves the file to disk. The Ask User keyword prompts the user for action. The user can elect to save the file or configure an external helper application to handle the file.

A MIME type's action can be to launch an external helper application to handle the file. As you can see in Figure 3.3, when Launch the Application is selected, an entry field and Browse button are provided to enter the appropriate external application.

New Types

You can add a new type to the MIME configuration by clicking on the Create New Type button. This brings up a small dialog in which you can enter the new MIME type and MIME subtype. After the new type is entered, fill in the appropriate file extension and action.

Many Windows-based helper applications add new MIME types to Navigator's configuration through the use of DDE or OLE. This technique automates the process and avoids user intervention. See Chapter 4, "Helper Applications and Network Communications," for a listing of the appropriate DDE topics and OLE methods for automated MIME type configuration.

What About Plug-Ins?

Figure 3.3 shows the MIME configuration screen for the Windows version of Navigator 3.0. This version does not provide for plug-in to MIME type configuration. The Macintosh and UNIX versions 3.0 of Navigator have this capability, but this feature is slated for Windows in Navigator 4.x.

A New MIME Type for Your Plug-In

You will learn in the upcoming chapters that a plug-in requires three resources for the Navigator to recognize it. These resources are as follows:

MIMEType
FileExtents
FileOpenName

Of the three, MIMEType and FileExtents help Navigator determine whether or not to load your plug-in code module. The FileOpenName resource is used for the Files of type: field in the File Open dialog.

Initial Development

Your initial plug-in development and testing usually does not involve a Web server. It is much easier to debug a plug-in using local data files instead of files on a server. To open a local data file in Netscape Navigator use the File|Open File main menu item to select your test data file. You can screen out files of the wrong extension by using the Files of type drop-down and selecting your type. Figure 3.4 shows an AVI file being opened.

Figure 3.4 : Navigator's File Open dialog.

When you are testing on a local machine you don't have to worry much about which MIME type you use. Just be sure that the browser doesn't already handle the type such as text/html. After a local file is opened, Navigator determines the MIME type by mapping the file extension to the MIME type, both of which are located in your plug-in's resource.

Going Live

When your plug-in is ready for the real world, things become a bit more complicated. File content type on a Web server is determined by the server, not by Netscape's Navigator. So your newly invented MIME type (called application/x-whatever) is not mapped to your newly created extension. This is a common plug-in developer's pitfall. The plug-in loads fine with a local file, but when the file is put on a Web server it doesn't load.

Many plug-in developers have server access and can simply add the new type to the server configuration. However, you should still go through the proper steps to register your new media type. That way, when your plug-in becomes wildly popular, Web servers will be aware of the new media type.

Registering a New Media Type

IANA has established a procedure for review and approval of new media types. To give you an idea of just what is required for this registration, here is an e-mail template:

To: IANA@isi.edu
Subject: Registration of new Media Type content-type/subtype

Media Type name:

Media subtype name:

Required parameters:

Optional parameters:

Encoding considerations:

Security considerations:

Publish specification:

Contact E-mail address:

In most cases, your plug-in uses an existing top-level media type. If it doesn't, you must explain why an existing type cannot be used. The published specification must be an Internet RFC or RFC-to-be for a new top-level media type.

A good source for further registration information is a document called Media Type Registration Procedure, which is located at the following address:

http://www.netscape.com/assist/helper_apps/rfc3

Conclusion

Now that you are a MIME expert, here are a few things to remember:

What's Next?

Another type of application that is MIME type-dependent is Netscape helper applications. Helper applications were the predecessor to Navigator plug-ins. Many of these helper applications use a direct socket interface. The next chapter focuses on Navigator helper applications and Windows socket programming.