在RFC 2822文档中定义了简单的 ASCII编码的Email的邮件格式,然而随着Internet的发展,Email邮件仅仅传输简单的文本已经满足不了用户的需求,为了在Email 中传输大量HTML、图像、声音以及各种附件格式,一种新的扩展的邮件格式应运而生——MIME。由于在MIME邮件格式非常复杂,大量的RFC文档中对MIME邮件格式进行了定义与说明,比如RFC2045, RFC2046, RFC2047, RFC2049, RFC2231, RFC2387, RFC4288, RFC4289等。因此,MIME邮件格式为我们提供了极大的灵活性的同时也给我们解读MIME格式的Email邮件带来了极大的困难。以下就一封具体的邮件原始信息对MIME邮件格式作出一个概要的介绍。
解释几个常用且不易理解的Content-Type开头的MIME首部:






































这封Email具有一个邮件首部,然后是邮件的主体部分,它包括一个文本和一个HTML类型。可以注意到这样一行编码“boundary="----=_NextPart_000_0003_01C7118D.38E01920" ”,它是用来隔离MIME邮件的各个实体部分。
在RFC2822中定义了MIME邮件首部的格式:

例如:
MIME-Version: 1.0
Content-Type: multipart/alternative;
Content-Type: text/plain;
Content-Transfer-Encoding: base64
最常见也用途最都的MIME首部是以Content-Type开头的,在RFC2046给出了它的定义,大致与如下内容相似:
Content-Type: text/plain;
Content-Type: text/plain; charset=ISO-8859-1
Content-Type: text/plain; charset=us-ascii
Content-Type: text/plain; charset=utf-8
Content-Type: text/html;
Content-Type: text/html; charset=ISO-8859-1
Content-Type: text/css
Content-Type: image/gif; name=image004.gif
Content-Type: image/jpeg; name="image005.jpg"
Content-Type: message/delivery-status
Content-Type: message/rfc822
Content-Type: audio/x-mpeg
Content-Type: video/mpeg-2
Content-Type: application/msword
Content-Type: application/mspowerpoint
Content-Type: application/zip
Content-Type: multipart/mixed; boundary="----=_Part_3431_12384933.1139387792352"
Content-Type: multipart/alternative; boundary="----=_Part_4088_29304219.1115463798628"
Content-Type: multipart/related; boundary="----=_Part_2067_9241611.1139322711488"
Content-Type: multipart/digest; boundary="----=Next message 15543233913938263541"
Content-Type: multipart/report; report-type=delivery-status;
boundary="k04G6HJ9025016.1136391237/carbon.singnet.com.sg"
Content-Type: multipart/parallel
1) Content-Type: multipart/mixed
它表明这封Email邮件中包含各种格式的MIME实体但没有具体给出每个实体的类型。
2) Content-Type: multipart/alternative
如果同一封Email邮件既以文本格式又以HTML格式发送,那么要使用Content-Type: multipart/alternative。这两种邮件格式实际上是显示同样的内容但是具有不同的编码。
3) Content-Type: multipart/related
用于在同一封邮件中发送HTML文本和图像或者是其他类似类型。
邮件主体的编码:
主要是包括quoted-printable与base64两种类型的编码。
(待续)