MimeUtility (Java EE 5)

Java EE API


javax.mail.internet Class MimeUtility

java.lang.Object
  extended by javax.mail.internet.MimeUtility

public class MimeUtility
extends Object


这是一个提供各种与 MIME 相关的功能的实用工具类。

提供了一组方法,可以根据 RFC 2047 编码和解码 MIME 头。关于处理此类头的方式简述如下:

RFC 822 邮件头只能包含 US-ASCII 字符。包含非 US-ASCII 字符的头必须进行编码,使其仅包含 US-ASCII 字符。此过程通常需要使用 BASE64 或 QP 来编码某些字符。RFC 2047 详细描述了这一点。

在 Java 中,String 包含(16 位)Unicode 字符。ASCII 是 Unicode 的一个子集(占用范围为 0 - 127)。仅包含 ASCII 字符的 String 对于邮件是安全的。如果 String 包含非 US-ASCII 字符,则它必须进行编码。此步骤比较复杂的地方在于,Unicode 还不是广泛使用的字符集,因此应该先将 String 通过字符集编码转换为另一种字符集,然后再进行传输编码。

注意,要获取对于邮件安全的 String 的实际字节(比如,要通过 SMTP 发送邮件),必须执行

	byte[] bytes = string.getBytes("iso-8859-1");	

 

MimeMessage 及 MimeBodyPart 上的 setHeaderaddHeader 方法假定给定的头值为仅包含 US-ASCII 字符的 Unicode 字符串。因此,这些方法的调用者必须确保它们传递的值不包含非 US-ASCII 字符。此类中的方法帮助实现这一点。

MimeMessage 和 MimeBodyPart 上的 getHeader 方法系列返回原始头值。它们可能根据 RFC 2047 进行了编码,如果是这样,则必须解码成 Unicode String。此类中的方法帮助实现这一点。

几个系统属性用于控制严格遵守 MIME 规范。注意,这些属性不是会话属性,但必须作为系统属性进行全局设置。

mail.mime.decodetext.strict 属性控制 MIME 编码字符的解码。MIME 规范要求该编码字符以空格分隔的单词开始。有些邮件程序在单词的中间包含了编码字符,这是不正确的。如果 mail.mime.decodetext.strict 系统属性设置为 "false",则将尝试解码这些非法编码字符。默认值为 true。

mail.mime.encodeeol.strict 属性控制选择类型不为 "text" 的 MIME 部分的 Content-Transfer-Encoding。这些部分经常包含文本数据,适合允许普通行结尾转换的编码。在很少的情况下,这些部分包含整个文本数据,但需要可保持 CR 和 LF 字符不变的编码操作。如果 mail.mime.encodeeol.strict 系统属性设置为 "true",则必要时将使用这种编码。默认值为 false。

此外,使用 mail.mime.charset 系统属性可以指定用于编码字符和文本部分的默认 MIME 字符集(若没有指定其他字符集)。通常,默认的 MIME 字符集派生自默认的 Java 字符集,该字符集在 file.encoding 系统属性中指定。大多数应用程序不需要明确设置默认的 MIME 字符集。如果要用于邮件消息的默认 MIME 字符集与用于存储在系统中的文件的字符集不同,则应该设置此属性。

英文文档:

This is a utility class that provides various MIME related functionality.

There are a set of methods to encode and decode MIME headers as per RFC 2047. A brief description on handling such headers is given below:

RFC 822 mail headers must contain only US-ASCII characters. Headers that contain non US-ASCII characters must be encoded so that they contain only US-ASCII characters. Basically, this process involves using either BASE64 or QP to encode certain characters. RFC 2047 describes this in detail.

In Java, Strings contain (16 bit) Unicode characters. ASCII is a subset of Unicode (and occupies the range 0 - 127). A String that contains only ASCII characters is already mail-safe. If the String contains non US-ASCII characters, it must be encoded. An additional complexity in this step is that since Unicode is not yet a widely used charset, one might want to first charset-encode the String into another charset and then do the transfer-encoding.

Note that to get the actual bytes of a mail-safe String (say, for sending over SMTP), one must do

        byte[] bytes = string.getBytes("iso-8859-1");   

 

The setHeader and addHeader methods on MimeMessage and MimeBodyPart assume that the given header values are Unicode strings that contain only US-ASCII characters. Hence the callers of those methods must insure that the values they pass do not contain non US-ASCII characters. The methods in this class help do this.

The getHeader family of methods on MimeMessage and MimeBodyPart return the raw header value. These might be encoded as per RFC 2047, and if so, must be decoded into Unicode Strings. The methods in this class help to do this.

Several System properties control strict conformance to the MIME spec. Note that these are not session properties but must be set globally as System properties.

The mail.mime.decodetext.strict property controls decoding of MIME encoded words. The MIME spec requires that encoded words start at the beginning of a whitespace separated word. Some mailers incorrectly include encoded words in the middle of a word. If the mail.mime.decodetext.strict System property is set to "false", an attempt will be made to decode these illegal encoded words. The default is true.

The mail.mime.encodeeol.strict property controls the choice of Content-Transfer-Encoding for MIME parts that are not of type "text". Often such parts will contain textual data for which an encoding that allows normal end of line conventions is appropriate. In rare cases, such a part will appear to contain entirely textual data, but will require an encoding that preserves CR and LF characters without change. If the mail.mime.encodeeol.strict System property is set to "true", such an encoding will be used when necessary. The default is false.

In addition, the mail.mime.charset System property can be used to specify the default MIME charset to use for encoded words and text parts that don't otherwise specify a charset. Normally, the default MIME charset is derived from the default Java charset, as specified in the file.encoding System property. Most applications will have no need to explicitly set the default MIME charset. In cases where the default MIME charset to be used for mail messages is different than the charset used for files stored on the system, this property should be set.

Version:
1.60, 07/05/15
Author:
John Mani, Bill Shannon

Field Summary
static int
 
Method Summary
static InputStream
static String
static String
static OutputStream
static OutputStream
static String
static String
static String
static String
static String
static String
static String
static String
static String
static String
static String
static String
 
Methods inherited from class java.lang.Object
 

Field Detail

英文文档:

ALL

public static final int ALL
See Also:
Constant Field Values
Method Detail

public static String getEncoding(DataSource ds)
获取应该用于此数据源的输入流的内容转换编码,使其对于邮件是安全的。

这里使用的算法如下:

  • 如果此数据源的基本类型为 "text",而且其输入流中的所有字节为 US-ASCII,则编码为 "7bit"。如果超过一半的字节为非 US-ASCII,则编码为 "base64"。如果不到一半的字节为非 US-ASCII,则编码为 "quoted-printable"。
  • 如果此数据源的基本类型不是 "text",若其输入流中的所有字节为 US-ASCII,则编码为 "7bit"。只要有一个非 US-ASCII 字符,编码就是 "base64"。
ds
DataSource
return 编码。为 "7bit"、"quoted-printable" 或 "base64"。
英文文档:

getEncoding

public static String getEncoding(DataSource ds)
Get the content-transfer-encoding that should be applied to the input stream of this datasource, to make it mailsafe.

The algorithm used here is:

  • If the primary type of this datasource is "text" and if all the bytes in its input stream are US-ASCII, then the encoding is "7bit". If more than half of the bytes are non-US-ASCII, then the encoding is "base64". If less than half of the bytes are non-US-ASCII, then the encoding is "quoted-printable".
  • If the primary type of this datasource is not "text", then if all the bytes of its input stream are US-ASCII, the encoding is "7bit". If there is even one non-US-ASCII character, the encoding is "base64".

Parameters:
ds - DataSource
Returns:
the encoding. This is either "7bit", "quoted-printable" or "base64"

public static String getEncoding(DataHandler dh)
getEncoding(DataSource) 相同,区别在于它不是从 InputStream 中读取数据,而是使用 writeTo 方法检查数据。这在使用对象和 MIME 类型(例如,一个 "text/plain" String)创建 DataHandler 时(一般情况)效率更高。在需要 InputStream 的情况下,DataHandler 将使用一个线程、一对管道流和 writeTo 方法生成数据。

since
JavaMail 1.2

英文文档:

getEncoding

public static String getEncoding(DataHandler dh)
Same as getEncoding(DataSource) except that instead of reading the data from an InputStream it uses the writeTo method to examine the data. This is more efficient in the common case of a DataHandler created with an object and a MIME type (for example, a "text/plain" String) because all the I/O is done in this thread. In the case requiring an InputStream the DataHandler uses a thread, a pair of pipe streams, and the writeTo method to produce the data.

Since:
JavaMail 1.2

public static java.io.InputStream decode(java.io.InputStream is, String encoding) throws MessagingException
解码给定的输入流。返回的 InputStream 为已解码的输入流。这里支持所有 RFC 2045 中定义的编码。包括 "base64"、"quoted-printable"、"7bit"、"8bit" 和 "binary"。此外,还支持 "uuencode"。
is 输入流
encoding 流的编码。
return 已解码的输入流。
英文文档:

decode

public static InputStream decode(InputStream is,
                                 String encoding)
                          throws MessagingException
Decode the given input stream. The Input stream returned is the decoded input stream. All the encodings defined in RFC 2045 are supported here. They include "base64", "quoted-printable", "7bit", "8bit", and "binary". In addition, "uuencode" is also supported.

Parameters:
is - input stream
encoding - the encoding of the stream.
Returns:
decoded input stream.
Throws:
MessagingException

public static java.io.OutputStream encode(java.io.OutputStream os, String encoding) throws MessagingException
用编码器包装给定的输出流。这里支持所有 RFC 2045 中定义的编码。包括 "base64"、"quoted-printable"、"7bit"、"8bit" 和 "binary"。此外,还支持 "uuencode"。
os 输出流
encoding 流的编码。
return 应用指定编码的输出流。
英文文档:

encode

public static OutputStream encode(OutputStream os,
                                  String encoding)
                           throws MessagingException
Wrap an encoder around the given output stream. All the encodings defined in RFC 2045 are supported here. They include "base64", "quoted-printable", "7bit", "8bit" and "binary". In addition, "uuencode" is also supported.

Parameters:
os - output stream
encoding - the encoding of the stream.
Returns:
output stream that applies the specified encoding.
Throws:
MessagingException

public static java.io.OutputStream encode(java.io.OutputStream os, String encoding, String filename) throws MessagingException
用编码器包装给定的输出流。这里支持所有 RFC 2045 中定义的编码。包括 "base64"、"quoted-printable"、"7bit"、"8bit" 和 "binary"。此外,还支持 "uuencode"。filename 参数与 "uuencode" 编码一起使用,包含在已编码的输出中。
os 输出流
encoding 流的编码。
filename 将被编码的文件的名称(仅与 uuencode 一起使用)
return 应用于指定编码的输出流。
since
JavaMail 1.2
英文文档:

encode

public static OutputStream encode(OutputStream os,
                                  String encoding,
                                  String filename)
                           throws MessagingException
Wrap an encoder around the given output stream. All the encodings defined in RFC 2045 are supported here. They include "base64", "quoted-printable", "7bit", "8bit" and "binary". In addition, "uuencode" is also supported. The filename parameter is used with the "uuencode" encoding and is included in the encoded output.

Parameters:
os - output stream
encoding - the encoding of the stream.
filename - name for the file being encoded (only used with uuencode)
Returns:
output stream that applies the specified encoding.
Throws:
MessagingException
Since:
JavaMail 1.2

public static String encodeText(String text) throws java.io.UnsupportedEncodingException
根据 RFC 2047,将 RFC 822 "text" 标记编码为对于邮件安全的形式。

对于非 US-ASCII 字符,将检查给定的 Unicode 字符串。如果该字符串仅包含 US-ASCII 字符,则按原样返回。如果字符串包含非 US-ASCII 字符,它首先将使用平台的默认字符集进行字符编码,然后使用 B 或 Q 编码传输编码。所得字节将作为仅包含 ASCII 字符的 Unicode 字符串返回。

注意,此方法应该仅用于编码“非结构化”RFC 822 头。

用法示例:

MimePart part = ...
String rawvalue = "FooBar Mailer, Japanese version 1.1"
try {
// If we know for sure that rawvalue contains only US-ASCII 
// characters, we can skip the encoding part
part.setHeader("X-mailer", MimeUtility.encodeText(rawvalue));
} catch (UnsupportedEncodingException e) {
// encoding failure
} catch (MessagingException me) {
// setHeader() failure
  }

 

text Unicode 字符串
return 仅包含 US-ASCII 字符的 Unicode 字符串
Throwsjava.io.UnsupportedEncodingException: 如果编码失败

英文文档:

encodeText

public static String encodeText(String text)
                         throws UnsupportedEncodingException
Encode a RFC 822 "text" token into mail-safe form as per RFC 2047.

The given Unicode string is examined for non US-ASCII characters. If the string contains only US-ASCII characters, it is returned as-is. If the string contains non US-ASCII characters, it is first character-encoded using the platform's default charset, then transfer-encoded using either the B or Q encoding. The resulting bytes are then returned as a Unicode string containing only ASCII characters.

Note that this method should be used to encode only "unstructured" RFC 822 headers.

Example of usage:

  MimePart part = ...
  String rawvalue = "FooBar Mailer, Japanese version 1.1"
  try {
    // If we know for sure that rawvalue contains only US-ASCII 
    // characters, we can skip the encoding part
    part.setHeader("X-mailer", MimeUtility.encodeText(rawvalue));
  } catch (UnsupportedEncodingException e) {
    // encoding failure
  } catch (MessagingException me) {
   // setHeader() failure
  }

 

Parameters:
text - Unicode string
Returns:
Unicode string containing only US-ASCII characters
Throws:
UnsupportedEncodingException - if the encoding fails

public static String encodeText(String text, String charset, String encoding) throws java.io.UnsupportedEncodingException
根据 RFC 2047,将 RFC 822 "text" 标记编码为对于邮件安全的形式。

对于非 US-ASCII 字符,将检查给定的 Unicode 字符串。如果该字符串仅包含 US-ASCII 字符,则按原样返回。如果字符串包含非 US-ASCII 字符,它首先将使用指定的字符集进行字符编码,然后使用 B 或 Q 编码传输编码。所得字节将作为仅包含 ASCII 字符的 Unicode 字符串返回。

注意,此方法应该仅用于编码“非结构化”RFC 822 头。

text 头值
charset 字符集。如果此参数为 null,则使用平台的默认字符集。
encoding 要使用的编码。当前支持的值为 "B" 和 "Q"。如果此参数为 null,则在大部分字符使用 ASCII 字符集编码时使用 "Q" 编码;其他情况使用 "B" 编码。
return 仅包含 US-ASCII 字符的 Unicode 字符串

英文文档:

encodeText

public static String encodeText(String text,
                                String charset,
                                String encoding)
                         throws UnsupportedEncodingException
Encode a RFC 822 "text" token into mail-safe form as per RFC 2047.

The given Unicode string is examined for non US-ASCII characters. If the string contains only US-ASCII characters, it is returned as-is. If the string contains non US-ASCII characters, it is first character-encoded using the specified charset, then transfer-encoded using either the B or Q encoding. The resulting bytes are then returned as a Unicode string containing only ASCII characters.

Note that this method should be used to encode only "unstructured" RFC 822 headers.

Parameters:
text - the header value
charset - the charset. If this parameter is null, the platform's default chatset is used.
encoding - the encoding to be used. Currently supported values are "B" and "Q". If this parameter is null, then the "Q" encoding is used if most of characters to be encoded are in the ASCII charset, otherwise "B" encoding is used.
Returns:
Unicode string containing only US-ASCII characters
Throws:
UnsupportedEncodingException

public static String decodeText(String etext) throws java.io.UnsupportedEncodingException
解码“非结构化”头,即根据 RFC 822 定义为 '*text' 的头。

使用 RFC 2047 第 6.1 节中指定的算法对字符串进行解码。如果任何序列的字符集转换失败,则抛出 UnsupportedEncodingException。如果 String 不是 RFC 2047 样式的编码头,则按原样返回。

用法示例:

MimePart part = ...
String rawvalue = null;
String  value = null;
try {
if ((rawvalue = part.getHeader("X-mailer")[0]) != null)
value = MimeUtility.decodeText(rawvalue);
} catch (UnsupportedEncodingException e) {
// Don't care
value = rawvalue;
} catch (MessagingException me) { }

return value;

 

etext 可能的编码值
Throwsjava.io.UnsupportedEncodingException: 如果字符集转换失败。

英文文档:

decodeText

public static String decodeText(String etext)
                         throws UnsupportedEncodingException
Decode "unstructured" headers, that is, headers that are defined as '*text' as per RFC 822.

The string is decoded using the algorithm specified in RFC 2047, Section 6.1. If the charset-conversion fails for any sequence, an UnsupportedEncodingException is thrown. If the String is not an RFC 2047 style encoded header, it is returned as-is

Example of usage:

  MimePart part = ...
  String rawvalue = null;
  String  value = null;
  try {
    if ((rawvalue = part.getHeader("X-mailer")[0]) != null)
      value = MimeUtility.decodeText(rawvalue);
  } catch (UnsupportedEncodingException e) {
      // Don't care
      value = rawvalue;
  } catch (MessagingException me) { }

  return value;

 

Parameters:
etext - the possibly encoded value
Throws:
UnsupportedEncodingException - if the charset conversion failed.

public static String encodeWord(String word) throws java.io.UnsupportedEncodingException
根据 RFC 2047,将 RFC 822 "word" 标记编码为对于邮件安全的形式。

对于非 US-ASCII 字符,将检查给定的 Unicode 字符串。如果该字符串仅包含 US-ASCII 字符,则按原样返回。如果字符串包含非 US-ASCII 字符,它首先将使用平台的默认字符集进行字符编码,然后使用 B 或 Q 编码传输编码。所得字节将作为仅包含 ASCII 字符的 Unicode 字符串返回。

此方法在创建 RFC 822 "phrases" 时使用。例如,InternetAddress 类使用此方法编码其 'phrase' 组件。

word Unicode 字符串
return 仅包含 US-ASCII 字符的 Unicode 字符串数组。
Throwsjava.io.UnsupportedEncodingException: 如果编码失败

英文文档:

encodeWord

public static String encodeWord(String word)
                         throws UnsupportedEncodingException
Encode a RFC 822 "word" token into mail-safe form as per RFC 2047.

The given Unicode string is examined for non US-ASCII characters. If the string contains only US-ASCII characters, it is returned as-is. If the string contains non US-ASCII characters, it is first character-encoded using the platform's default charset, then transfer-encoded using either the B or Q encoding. The resulting bytes are then returned as a Unicode string containing only ASCII characters.

This method is meant to be used when creating RFC 822 "phrases". The InternetAddress class, for example, uses this to encode it's 'phrase' component.

Parameters:
word - Unicode string
Returns:
Array of Unicode strings containing only US-ASCII characters.
Throws:
UnsupportedEncodingException - if the encoding fails

public static String encodeWord(String word, String charset, String encoding) throws java.io.UnsupportedEncodingException
根据 RFC 2047,将 RFC 822 "word" 标记编码为对于邮件安全的形式。

对于非 US-ASCII 字符,将检查给定的 Unicode 字符串。如果该字符串仅包含 US-ASCII 字符,则按原样返回。如果字符串包含非 US-ASCII 字符,它首先将使用指定的字符集进行字符编码,然后使用 B 或 Q 编码传输编码。所得字节将作为仅包含 ASCII 字符的 Unicode 字符串返回。

word Unicode 字符串
charset MIME 字符集
encoding 要使用的编码。当前支持的值为 "B" 和 "Q"。如果此参数为 null,则在大部分字符使用 ASCII 字符集编码时使用 "Q" 编码;其他情况使用 "B" 编码。
return 仅包含 US-ASCII 字符的 Unicode 字符串
Throwsjava.io.UnsupportedEncodingException: 如果编码失败

英文文档:

encodeWord

public static String encodeWord(String word,
                                String charset,
                                String encoding)
                         throws UnsupportedEncodingException
Encode a RFC 822 "word" token into mail-safe form as per RFC 2047.

The given Unicode string is examined for non US-ASCII characters. If the string contains only US-ASCII characters, it is returned as-is. If the string contains non US-ASCII characters, it is first character-encoded using the specified charset, then transfer-encoded using either the B or Q encoding. The resulting bytes are then returned as a Unicode string containing only ASCII characters.

Parameters:
word - Unicode string
charset - the MIME charset
encoding - the encoding to be used. Currently supported values are "B" and "Q". If this parameter is null, then the "Q" encoding is used if most of characters to be encoded are in the ASCII charset, otherwise "B" encoding is used.
Returns:
Unicode string containing only US-ASCII characters
Throws:
UnsupportedEncodingException - if the encoding fails

public static String decodeWord(String eword) throws ParseException, java.io.UnsupportedEncodingException
使用 RFC 2047 中解析 "encoded-word" 的规则来解析字符串。如果解析失败,则抛出 ParseException。否则,对它进行传输解码,然后通过字符集转换变为 Unicode。如果字符集转换失败,则抛出 UnsupportedEncodingException。

eword 编码值
ThrowsParseException: 如果字符串不是根据 RFC 2047 解析的 encoded-word
Throwsjava.io.UnsupportedEncodingException: 如果字符集转换失败。

英文文档:

decodeWord

public static String decodeWord(String eword)
                         throws ParseException,
                                UnsupportedEncodingException
The string is parsed using the rules in RFC 2047 for parsing an "encoded-word". If the parse fails, a ParseException is thrown. Otherwise, it is transfer-decoded, and then charset-converted into Unicode. If the charset-conversion fails, an UnsupportedEncodingException is thrown.

Parameters:
eword - the encoded value
Throws:
ParseException - if the string is not an encoded-word as per RFC 2047.
UnsupportedEncodingException - if the charset conversion failed.

public static String quote(String word, String specials)
一个给单词加引号的实用工具方法,只要该单词包含指定 'specials' 列表中的任意字符即可。

HeaderTokenizer 类定义两组特殊的分界符 - MIME 和 RFC 822。

此方法通常在生成 RFC 822 和 MIME 头字段时使用。

word 要加引号的单词
specials 特殊字符的集合
return 可能的引用单词
See also MIME, RFC822

英文文档:

quote

public static String quote(String word,
                           String specials)
A utility method to quote a word, if the word contains any characters from the specified 'specials' list.

The HeaderTokenizer class defines two special sets of delimiters - MIME and RFC 822.

This method is typically used during the generation of RFC 822 and MIME header fields.

Parameters:
word - word to be quoted
specials - the set of special characters
Returns:
the possibly quoted word
See Also:
HeaderTokenizer.MIME, HeaderTokenizer.RFC822

public static String fold(int used, String s)
如果可能,在连续的空白处折叠字符串,使每行的字符数不大于 76 个。如果有 76 个以上的连续非空白字符,则字符串在此序列后的第一个空白处进行折叠。参数 used 指示在当前行中使用的字符数,它通常为头名称的长度。

注意,字符串中的换行符没有被转义;应该对它们进行转义。

used 目前在行中使用的字符数
s 要折叠的字符串
return 已折叠的字符串
since
JavaMail 1.4

英文文档:

fold

public static String fold(int used,
                          String s)
Fold a string at linear whitespace so that each line is no longer than 76 characters, if possible. If there are more than 76 non-whitespace characters consecutively, the string is folded at the first whitespace after that sequence. The parameter used indicates how many characters have been used in the current line; it is usually the length of the header name.

Note that line breaks in the string aren't escaped; they probably should be.

Parameters:
used - characters used in line so far
s - the string to fold
Returns:
the folded string
Since:
JavaMail 1.4

public static String unfold(String s)
展开已折叠的头。移除所有未经转义的换行符和空格前面的换行符。
s 要展开的字符串
return 已展开的字符串
since
JavaMail 1.4
英文文档:

unfold

public static String unfold(String s)
Unfold a folded header. Any line breaks that aren't escaped and are followed by whitespace are removed.

Parameters:
s - the string to unfold
Returns:
the unfolded string
Since:
JavaMail 1.4

public static String javaCharset(String charset)
将 MIME 字符集名称转换为有效的 Java 字符集名称。

charset MIME 字符集名称
return 等效的 Java 字符集。如果没有可用的合适映射,则传入的字符集就是返回的字符集。

英文文档:

javaCharset

public static String javaCharset(String charset)
Convert a MIME charset name into a valid Java charset name.

Parameters:
charset - the MIME charset name
Returns:
the Java charset equivalent. If a suitable mapping is not available, the passed in charset is itself returned.

public static String mimeCharset(String charset)
将 Java 字符集转换为它的 MIME 字符集名称。

注意,以后的 JDK 版本(1.2 以后)可能会提供此功能,届时将不再需要此方法。

charset JDK 字符集
return MIME/IANA 等效字符集。如果没有合适映射,则传入的字符集就是返回的字符集。
since
JavaMail 1.1

英文文档:

mimeCharset

public static String mimeCharset(String charset)
Convert a java charset into its MIME charset name.

Note that a future version of JDK (post 1.2) might provide this functionality, in which case, we may deprecate this method then.

Parameters:
charset - the JDK charset
Returns:
the MIME/IANA equivalent. If a mapping is not possible, the passed in charset itself is returned.
Since:
JavaMail 1.1

public static String getDefaultJavaCharset()
获取与系统的当前默认语言环境对应的默认字符集。如果设置了 mail.mime.charset 系统属性,则返回与此 MIME 字符集对应的系统字符集。

return 系统默认语言环境的默认字符集,作为 Java 字符集。(不是 MIME 字符集)
since
JavaMail 1.1

英文文档:

getDefaultJavaCharset

public static String getDefaultJavaCharset()
Get the default charset corresponding to the system's current default locale. If the System property mail.mime.charset is set, a system charset corresponding to this MIME charset will be returned.

Returns:
the default charset of the system's default locale, as a Java charset. (NOT a MIME charset)
Since:
JavaMail 1.1


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!