Class MimeEncoder
Provides RFC 2045 Base64 and Quoted-Printable encoding/decoding, RFC 2047 encoded-word encoding/decoding for message headers, and MIME boundary/message-id generation.
提供 RFC 2045 Base64 和 Quoted-Printable 编解码, RFC 2047 编码字(encoded-word)编解码用于消息头, 以及 MIME 边界/消息ID 生成。
Features | 主要功能:
- Base64 MIME encoding (76-char line wrap) - Base64 MIME 编码(76字符换行)
- Quoted-Printable encoding/decoding (RFC 2045) - Quoted-Printable 编解码
- RFC 2047 encoded-word for non-ASCII headers - RFC 2047 编码字用于非ASCII邮件头
- Unique boundary and message-id generation - 唯一边界和消息ID生成
Security | 安全性:
- Thread-safe: Yes (stateless utility) - 线程安全: 是(无状态工具类)
- Null-safe: No (callers must provide non-null arguments) - 空值安全: 否
- Since:
- JDK 25, opencode-base-email V1.0.3
- Author:
- Leon Soo
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]decodeBase64(String data) Decode a MIME Base64 encoded string to binary data 将 MIME Base64 编码字符串解码为二进制数据static StringdecodeQuotedPrintable(String text) Decode a Quoted-Printable encoded string 解码 Quoted-Printable 编码字符串static StringdecodeQuotedPrintable(String text, Charset charset) Decode a Quoted-Printable encoded string with the specified charset 使用指定字符集解码 Quoted-Printable 编码字符串static StringdecodeWord(String encoded) Decode an RFC 2047 encoded-word string 解码 RFC 2047 编码字字符串static StringencodeBase64(byte[] data) Encode binary data to MIME Base64 with 76-character line wrapping 将二进制数据编码为 MIME Base64(76字符换行)static StringencodeQuotedPrintable(String text, String charset) Encode text to Quoted-Printable encoding per RFC 2045 按 RFC 2045 将文本编码为 Quoted-Printable 编码static StringencodeWord(String word, String charset) Encode a header word using RFC 2047 Base64 encoding 使用 RFC 2047 Base64 编码对邮件头字词进行编码static StringGenerate a unique MIME boundary string 生成唯一的 MIME 边界字符串static StringgenerateMessageId(String domain) Generate a unique Message-ID header value 生成唯一的 Message-ID 邮件头值
-
Method Details
-
encodeBase64
Encode binary data to MIME Base64 with 76-character line wrapping 将二进制数据编码为 MIME Base64(76字符换行)- Parameters:
data- the data to encode | 要编码的数据- Returns:
- the Base64 encoded string | Base64 编码字符串
-
decodeBase64
Decode a MIME Base64 encoded string to binary data 将 MIME Base64 编码字符串解码为二进制数据- Parameters:
data- the Base64 string to decode | 要解码的 Base64 字符串- Returns:
- the decoded bytes | 解码后的字节
-
encodeQuotedPrintable
Encode text to Quoted-Printable encoding per RFC 2045 按 RFC 2045 将文本编码为 Quoted-Printable 编码Non-printable characters and '=' are encoded as =XX hex pairs. Lines are soft-wrapped at 76 characters with '=' continuation.
不可打印字符和'='被编码为 =XX 十六进制对。 行在76字符处用'='软换行。
- Parameters:
text- the text to encode | 要编码的文本charset- the charset name for byte conversion | 字节转换的字符集名称- Returns:
- the Quoted-Printable encoded string | Quoted-Printable 编码字符串
-
decodeQuotedPrintable
-
decodeQuotedPrintable
Decode a Quoted-Printable encoded string with the specified charset 使用指定字符集解码 Quoted-Printable 编码字符串- Parameters:
text- the Quoted-Printable text to decode | 要解码的 Quoted-Printable 文本charset- the charset for decoding | 解码字符集- Returns:
- the decoded string | 解码后的字符串
-
encodeWord
Encode a header word using RFC 2047 Base64 encoding 使用 RFC 2047 Base64 编码对邮件头字词进行编码Produces encoded-words of the form
=?charset?B?base64?=. Only encodes if the word contains non-ASCII characters.生成形如
=?charset?B?base64?=的编码字。 仅在字词包含非ASCII字符时进行编码。- Parameters:
word- the word to encode | 要编码的字词charset- the charset name (e.g., "UTF-8") | 字符集名称- Returns:
- the RFC 2047 encoded word, or the original if pure ASCII | 编码后的字词,纯ASCII则返回原文
-
decodeWord
Decode an RFC 2047 encoded-word string 解码 RFC 2047 编码字字符串Handles both B (Base64) and Q (Quoted-Printable) encodings. Non-encoded text is returned as-is.
支持 B(Base64)和 Q(Quoted-Printable)编码。 非编码文本原样返回。
- Parameters:
encoded- the encoded string (may contain multiple encoded-words) | 编码字符串- Returns:
- the decoded string | 解码后的字符串
-
generateBoundary
Generate a unique MIME boundary string 生成唯一的 MIME 边界字符串- Returns:
- the boundary string (without leading "--") | 边界字符串(不含前导"--")
-
generateMessageId
-