5. Composite Media Type 值
两种复合顶层 media types 是: multipart 和 message.
5.1. Multipart Media Type
multipart 类型用于将多个 body parts 组合到单个消息中. 每个部分都是独立实体, 拥有自己的头部和正文.
5.1.1. 通用语法
所有 multipart 类型共享通用语法. boundary 参数是必需的:
Content-Type: multipart/mixed; boundary="----=_Part_0_123456789.987654321"
------=_Part_0_123456789.987654321
Content-Type: text/plain
First part content
------=_Part_0_123456789.987654321
Content-Type: text/html
<html>Second part content`</html>`
------=_Part_0_123456789.987654321--
5.1.3. Mixed Subtype
multipart/mixed 用于需要按顺序呈现的独立部分.
用例: 邮件正文 + 附件
Content-Type: multipart/mixed; boundary="boundary123"
--boundary123
Content-Type: text/plain
Email body
--boundary123
Content-Type: application/pdf
Content-Disposition: attachment; filename="document.pdf"
[PDF data]
--boundary123--
5.1.4. Alternative Subtype
multipart/alternative 用于同一内容的不同表示. 邮件客户端应选择其能够理解的最后一个版本.
用例: 纯文本 + HTML 版本
Content-Type: multipart/alternative; boundary="alt123"
--alt123
Content-Type: text/plain
Plain text version
--alt123
Content-Type: text/html
<html><body>HTML version`</body>``</html>`
--alt123--
5.1.5. Digest Subtype
multipart/digest 用于转发多条消息. 默认部分类型是 message/rfc822.
5.1.6. Parallel Subtype
multipart/parallel 表示各部分应同时呈现.
5.1.7. 其他 Multipart Subtypes
multipart/related: 相关部分 (例如 HTML + 嵌入图像)multipart/form-data: HTML 表单文件上传multipart/byteranges: HTTP 范围请求
5.2. Message Media Type
message 类型用于封装另一条消息.
5.2.1. RFC822 Subtype
message/rfc822 用于封装完整 RFC 822 消息.
Content-Type: message/rfc822
From: [email protected]
To: [email protected]
Subject: Forwarded message
This is the forwarded message content.
5.2.2. Partial Subtype
message/partial 用于将大消息拆分为多个片段.
参数:
id: 唯一标识符number: 片段编号total: 片段总数
Content-Type: message/partial;
id="[email protected]";
number=1;
total=3
5.2.3. External-Body Subtype
message/external-body 用于引用存储在其他位置的数据.
访问类型:
ftp: FTP 服务器http: HTTP URLlocal-file: 本地文件mail-server: 邮件服务器
Content-Type: message/external-body;
access-type=URL;
URL="http://example.com/file.pdf"
Content-Type: application/pdf
Content-Description: Large PDF File
典型嵌套结构:
multipart/mixed
├── text/plain (正文)
├── multipart/alternative
│ ├── text/plain
│ └── text/html
└── application/pdf (附件)