Class MimeParser
Parses raw RFC 2822 MIME messages into structured ParsedMessage
records. Handles multipart messages (mixed, alternative, related),
Content-Transfer-Encoding (base64, quoted-printable, 7bit, 8bit),
RFC 2047 encoded headers, and various date formats.
将原始 RFC 2822 MIME 消息解析为结构化的 ParsedMessage 记录。
处理多部分消息(mixed、alternative、related)、内容传输编码
(base64、quoted-printable、7bit、8bit)、RFC 2047 编码邮件头和各种日期格式。
Features | 主要功能:
- Header parsing with continuation line unfolding - 邮件头解析及折叠行展开
- Multipart boundary extraction and recursive parsing - 多部分边界提取和递归解析
- Content-Transfer-Encoding decoding - 内容传输编码解码
- RFC 2047 encoded-word decoding for headers - RFC 2047 编码字解码
- Multiple date format support - 多种日期格式支持
- DoS protection with configurable max depth - 可配置最大深度的 DoS 防护
- Attachment extraction - 附件提取
Security | 安全性:
- Thread-safe: Yes (stateless utility) - 线程安全: 是(无状态工具类)
- Recursion depth limited to 50 - 递归深度限制为 50
- Since:
- JDK 25, opencode-base-email V1.0.3
- Author:
- Leon Soo
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic ParsedMessageParse a complete raw MIME message into aParsedMessage将完整的原始 MIME 消息解析为ParsedMessageparseHeaders(String rawMessage) Parse just the headers from a raw message 仅从原始消息中解析邮件头
-
Method Details
-
parse
Parse a complete raw MIME message into aParsedMessage将完整的原始 MIME 消息解析为ParsedMessageSplits the message at the first blank line to separate headers from body, then recursively parses multipart structures to extract text, HTML, and attachments.
在第一个空行处分割消息以分离邮件头和消息体,然后递归解析多部分结构以 提取文本、HTML和附件。
- Parameters:
rawMessage- the raw RFC 2822 message string | 原始 RFC 2822 消息字符串- Returns:
- the parsed message | 解析后的消息
- Throws:
IllegalArgumentException- if rawMessage is null or empty | 消息为空时抛出
-
parseHeaders
Parse just the headers from a raw message 仅从原始消息中解析邮件头Returns a map of header names (original case) to their values. Continuation lines are unfolded.
返回邮件头名称(原始大小写)到值的映射。折叠行会被展开。
- Parameters:
rawMessage- the raw RFC 2822 message string | 原始 RFC 2822 消息字符串- Returns:
- the headers map | 邮件头映射
- Throws:
IllegalArgumentException- if rawMessage is null or empty | 消息为空时抛出
-