mimeutility.html
来自「SUN的JAVA MAIL API」· HTML 代码 · 共 677 行 · 第 1/2 页
HTML
677 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc on Fri Feb 18 09:56:10 PST 2000 -->
<TITLE>
JavaMail 1.1 API documentation: Class MimeUtility
</TITLE>
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
</HEAD>
<BODY BGCOLOR="white">
<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_top"><!-- --></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" ID="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT ID="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="package-summary.html"><FONT ID="NavBarFont1"><B>Package</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" ID="NavBarCell1Rev"> <FONT ID="NavBarFont1Rev"><B>Class</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="class-use/MimeUtility.html"><FONT ID="NavBarFont1"><B>Use</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="package-tree.html"><FONT ID="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT ID="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="../../../index-files/index-1.html"><FONT ID="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT ID="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" ID="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../javax/mail/internet/MimePartDataSource.html"><B>PREV CLASS</B></A>
<A HREF="../../../javax/mail/internet/NewsAddress.html"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" ID="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html" TARGET="_top"><B>FRAMES</B></A>
<A HREF="MimeUtility.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD>
</TR>
<TR>
<TD VALIGN="top" ID="NavBarCell3"><FONT SIZE="-2">
SUMMARY: INNER | <A HREF="#field_summary">FIELD</A> | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" ID="NavBarCell3"><FONT SIZE="-2">
DETAIL: <A HREF="#field_detail">FIELD</A> | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
javax.mail.internet</FONT>
<BR>
Class MimeUtility</H2>
<PRE>
java.lang.Object
|
+--<B>javax.mail.internet.MimeUtility</B>
</PRE>
<HR>
<DL>
<DT>public class <B>MimeUtility</B><DT>extends java.lang.Object</DL>
<P>
This is a utility class that provides various MIME related
functionality. <p>
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: <p>
RFC 822 mail headers <strong>must</strong> 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. <p>
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.
<p>
Note that to get the actual bytes of a mail-safe String (say,
for sending over SMTP), one must do
<p><blockquote><pre>
byte[] bytes = string.getBytes("iso-8859-1");
</pre></blockquote><p>
The <code>setHeader()</code> and <code>addHeader()</code> 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. <p>
The <code>getHeader()</code> 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.
<P>
<HR>
<P>
<!-- ======== INNER CLASS SUMMARY ======== -->
<!-- =========== FIELD SUMMARY =========== -->
<A NAME="field_summary"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" ID="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Field Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#ALL">ALL</A></B></CODE>
<BR>
</TD>
</TR>
</TABLE>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" ID="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Method Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.io.InputStream</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#decode(java.io.InputStream, java.lang.String)">decode</A></B>(java.io.InputStream is,
java.lang.String encoding)</CODE>
<BR>
Decode the given input stream.</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#decodeText(java.lang.String)">decodeText</A></B>(java.lang.String etext)</CODE>
<BR>
Decode "unstructured" headers, that is, headers that are defined
as '*text' as per RFC 822.</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#decodeWord(java.lang.String)">decodeWord</A></B>(java.lang.String eword)</CODE>
<BR>
The string is parsed using the rules in RFC 2047 for parsing
an "encoded-word".</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.io.OutputStream</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#encode(java.io.OutputStream, java.lang.String)">encode</A></B>(java.io.OutputStream os,
java.lang.String encoding)</CODE>
<BR>
Wrap an encoder around the given output stream.</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#encodeText(java.lang.String)">encodeText</A></B>(java.lang.String text)</CODE>
<BR>
Encode a RFC 822 "text" token into mail-safe form as per
RFC 2047.</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#encodeText(java.lang.String, java.lang.String, java.lang.String)">encodeText</A></B>(java.lang.String text,
java.lang.String charset,
java.lang.String encoding)</CODE>
<BR>
Encode a RFC 822 "text" token into mail-safe form as per
RFC 2047.</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#encodeWord(java.lang.String)">encodeWord</A></B>(java.lang.String word)</CODE>
<BR>
Encode a RFC 822 "word" token into mail-safe form as per
RFC 2047.</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#encodeWord(java.lang.String, java.lang.String, java.lang.String)">encodeWord</A></B>(java.lang.String word,
java.lang.String charset,
java.lang.String encoding)</CODE>
<BR>
Encode a RFC 822 "word" token into mail-safe form as per
RFC 2047.</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#getDefaultJavaCharset()">getDefaultJavaCharset</A></B>()</CODE>
<BR>
Get the default charset corresponding to the system's current
default locale.</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#getEncoding(javax.activation.DataSource)">getEncoding</A></B>(javax.activation.DataSource ds)</CODE>
<BR>
Get the content-transfer-encoding that should be applied
to the input stream of this datasource, to make it mailsafe.</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#javaCharset(java.lang.String)">javaCharset</A></B>(java.lang.String charset)</CODE>
<BR>
Convert a MIME charset name into a valid Java charset name.</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#mimeCharset(java.lang.String)">mimeCharset</A></B>(java.lang.String charset)</CODE>
<BR>
Convert a java charset into its MIME charset name.</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#quote(java.lang.String, java.lang.String)">quote</A></B>(java.lang.String word,
java.lang.String specials)</CODE>
<BR>
A utility method to quote a word, if the word contains any
characters from the specified 'specials' list.
The <code>HeaderTokenizer</code> class defines two special
sets of delimiters - MIME and RFC 822.</TD>
</TR>
</TABLE>
<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#EEEEFF" ID="TableSubHeadingColor">
<TD><B>Methods inherited from class java.lang.Object</B></TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD><CODE>clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait</CODE></TD>
</TR>
</TABLE>
<P>
<!-- ============ FIELD DETAIL =========== -->
<A NAME="field_detail"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" ID="TableHeadingColor">
<TD COLSPAN=1><FONT SIZE="+2">
<B>Field Detail</B></FONT></TD>
</TR>
</TABLE>
<A NAME="ALL"><!-- --></A><H3>
ALL</H3>
<PRE>
public static final int <B>ALL</B></PRE>
<DL>
</DL>
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<!-- ============ METHOD DETAIL ========== -->
<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" ID="TableHeadingColor">
<TD COLSPAN=1><FONT SIZE="+2">
<B>Method Detail</B></FONT></TD>
</TR>
</TABLE>
<A NAME="getEncoding(javax.activation.DataSource)"><!-- --></A><H3>
getEncoding</H3>
<PRE>
public static java.lang.String <B>getEncoding</B>(javax.activation.DataSource ds)</PRE>
<DL>
<DD>Get the content-transfer-encoding that should be applied
to the input stream of this datasource, to make it mailsafe. <p>
The algorithm used here is: <br>
<ul>
<li>
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".
<li>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?