A MIME document beginswith case-insensitive ASCII Header lines. The first line is
MIME-Version: 1.0
This and all lines are terminated by a CRLF linebreak (two octets: decimal 13 then 10).
Since any header field may include a comment,
MIME-Version: 1.0 (Generated by GBD-killer 3.7)
is also acceptable.
Next is
Content-Type: type/subtype ;
where type is "application", "audio", "image","message", "multipart", "text", "video",an x-token, or an iana-token.
An iana-token is a publicly-defined extension token, registered with theInternet Assigned Numbers Authority (IANA).
An unregistered x-token is the two characters "X-" or "x-"followed, with no intervening white space, by any token.
The Content-Typeline may end with any number of paramater-equals-valuepairs, each preceeded by a semicolon.
For the multipart type, 4 initial subtypes were defined, including theprimary "mixed" subtype, "alternative" for representingthe same data in multiple formats, "parallel" for parts intendedto be viewed simultaneously, and "digest" for multipart entitiesin which each part is of type "message".
For the image type, "jpeg" and "gif" subtypes aredefined.
For the text type, the defined subtype is "plain".
Next is
Content-Transfer-Encoding : mechanism ;
where mechanism is "7bit" (the data is all representedas short lines of US-ASCII data), "quoted-printable"(data that largely consists of octets that correspond to printable charactersin the ASCII character set), "base64", "8bit"( the lines are short, but there may be non-ASCII characters (octets withthe high-order bit set), "binary" (not only maynon-ASCII characters be present, but also that the lines are not necessarilyshort enough for SMTP transport), or x-token. If the Content-Transfer-Encodingheader field is not present, "7bit" is assumed. The values "8bit","7bit", and "binary" all mean that NO encoding hasalready been performed.
If a bit stream is to be encoded via one of these content transver encodingmechanisms, it must first be converted to an 8-bit byte stream using thenetwork standard bit order ("big-endian"), in which the earlierbits in a stream become the higher-order bits in a byte.
Example header:
Content-Type: text/plain; charset=ISO-8859-1 Content-transfer-encoding: base64For <B>base64</B>, the encoded data are consistently only about
33 percent larger than the unencoded data.
(3 bytes become 4 encoded characters.)
This encoding is virtually identical to the one used in
Privacy Enhanced Mail (PEM) applications. Each 6-bit group is used as an index into an array of 64 printable characters. The character referenced by the index is placed in the output string. These characters, identified in Table 1, below, are selected so as to be universally representable, and the set excludes characters with particular significance to SMTP (e.g., ".", CR, LF) and to the encapsulation boundaries defined in this document (e.g., "-"). Table 1: The Base64 Alphabet Value Encoding Value Encoding Value Encoding Value Encoding 0 A 17 R 34 i 51 z 1 B 18 S 35 j 52 0 2 C 19 T 36 k 53 1 3 D 20 U 37 l 54 2 4 E 21 V 38 m 55 3 5 F 22 W 39 n 56 4 6 G 23 X 40 o 57 5 7 H 24 Y 41 p 58 6 8 I 25 Z 42 q 59 7 9 J 26 a 43 r 60 8 10 K 27 b 44 s 61 9 11 L 28 c 45 t 62 + 12 M 29 d 46 u 63 / 13 N 30 e 47 v 14 O 31 f 48 w (pad) = 15 P 32 g 49 x 16 Q 33 h 50 yThe output stream (encoded bytes) must be represented in lines
of no more than 76 characters each.
All line breaks or other characters not found in Table 1
must be ignored by decoding software.