MIME is every where and we might have used it countless times during our software career. But what exactly is MIME? I posed this question to some of my software developer friends and got ambiguous answers. Some refer to MIME as MIME type, some tried to quote the full form of MIME. It was clear that MIME is not very well understood concept. In this post we will try to shed some light on what is this MIME?
As per RFC 822, original mail protocols were built to support only standard US ASCII charset. This left a lot to be desired.
- What if sender wants to send a message in a different charset say Hindi, or Spanish or any other charset?
- What if sender wants to send a multipart message?
- What if sender wants to add some non text attachment?
- What if senders wants to set message header in some other charset?
To address these concerns The Internet Engineering Task Force (IETF) came up with new format for Mail Message. This was an extension to famous RFC822. This new format is referred to as MIME messages.
What is MIME?
MIME stands for Multipurpose Internet Mail Extensions MIME is an Internet standard that extends the email messages to support, non ASCII text content, non text attachment, Multipart message body and non US-ASCII header. The MIME was so successful that is was adopted as message format for general web and lots of other technologies. MIME format are defined using following RFC docs.
- RFC 2045: Describes various headers used to describe the structure of MIME messages.
- RFC 2046: Defines an initial set of Media Types
- RFC 2047: Describes extensions to RFC 822 to allow non-US-ASCII text data in Internet mail header fields
- RFC 2048: Specifies various IANA registration procedures for MIME-related facilities
- RFC 2049: Provides MIME conformance criteria as well as some examples of MIME message formats, acknowledgements, and the bibliography.
Structure of a MIME message
MIME-Version: 1.0 From: Nathaniel Borenstein <firstname.lastname@example.org> To: Ned Freed <email@example.com> Date: Fri, 07 Oct 1994 16:15:05 -0700 (PDT) Subject: A multipart example Content-Type: multipart/mixed; boundary=unique-boundary-1 --unique-boundary-1 ... Some text appears here ... --unique-boundary-1 Content-type: text/plain; charset=US-ASCII --unique-boundary-1 Content-Type: multipart/parallel; boundary=unique-boundary-2 --unique-boundary-2 Content-Type: audio/basic Content-Transfer-Encoding: base64 ... base64-encoded 8000 Hz single-channel mu-law-format audio data goes here ... --unique-boundary-2 Content-Type: image/jpeg Content-Transfer-Encoding: base64 ... base64-encoded image data goes here ... --unique-boundary-2-- --unique-boundary-1 Content-type: text/enriched <b>this is a test</b> --unique-boundary-1 Content-Type: message/rfc822 From: (mailbox in US-ASCII) To: (address in US-ASCII) Subject: (subject in US-ASCII) Content-Type: Text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: Quoted-printable ... Additional text in ISO-8859-1 goes here ... --unique-boundary-1--
Above is an example of a MIME message. On close inspection you will find that it has following parts.
- Multiple body part which are of different content types
A MIME Multipart message can contain one or more body part, which can have different content-types, the body parts can be embedded in another body part and are enclosed within boundary specified in boundary param on content-type header of parent body part.
Dissecting MIME Headers
Presence of this header let us know that we have a mime email message. The original intention of this header was to support future versions of mime. But the way MIME is implemented makes it impossible to change the version. Now version is always fixed to 1.0 and signifies that we have a non US ASCII message with non text attachments.
Content Type Header
Content-Type: multipart/mixed; boundary=unique-boundary-1
Content Type header defines the data type present in the body and body parts of the messages. This helps the client in choosing the appropriate mechanism by which they can display the message to user. The type/subtype definition is can you buy viagra online generally followed by a boundary value. The boundary value represents a body part block and all the body part must start and end with that boundary. For example
--unique-boundary-1-- body part goes here --unique-boundary-1--
Content Disposition Header
content-disposition = "Content-Disposition" ":" disposition-type *( ";" disposition-parm ) disposition-type = "attachment" | disp-extension-token disposition-parm = filename-parm | disp-extension-parm filename-parm = "filename" "=" quoted-string disp-extension-token = token disp-extension-parm = token "=" ( token | quoted-string ) An example is Content-Disposition: attachment; filename="fname.ext"
The body type of a MIME message should be show as is unless a content disposition header is specified as attachment. When Content-Disposition : attachment header is specified then it means that body part should not be displayed normally, rather it should be displayed as attachment and clicking it should result in downloading of body part in file name specified by the filename param of the header.
As we know that lots of protocol like SMTP allows messages only with 7BIT encoding. Now with MIME it is possible to send across 8-bit, binary data as well. This becomes possible only by encoding the 8-bit or binary data in a 7BIT format. To do this MIME provides Content-Transfer-Encoding header. For example consider a body part consisting of an audio file.
Content-Type: audio/basic Content-Transfer-Encoding: base64
Now since audio file is in binary format so it should be reencoded in 7BIT format. We use Content-Transfer-Encoding header to convert it in BASE 64 encoded 7BIT supported format. Apart for base 64 we also have following encoding.
- 7BIT – default
I hope that this post sheds some extra light on what MIME is. This POST is a result of research and reading I have done in last few days and as I am human, this could have some errors as well. If any of you find some vital basic points missing please let me know so that I can add it to the post. If you find this post useful please drop a comment or two.