<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc on Wed Jun 25 00:04:11 PDT 2003 -->
<TITLE>
JavaMail 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" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
  <TR ALIGN="center" VALIGN="top">
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/MimeUtility.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
  </TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>

<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../javax/mail/internet/MimePartDataSource.html"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../../javax/mail/internet/NewsAddress.html"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
  <A HREF="../../../index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
&nbsp;<A HREF="MimeUtility.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  SUMMARY: &nbsp;INNER&nbsp;|&nbsp;<A HREF="#field_summary">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: &nbsp;<A HREF="#field_detail">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<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>

 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. <p>

 The <code>mail.mime.decodetext.strict</code> 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 <code>mail.mime.decodetext.strict</code> System property is
 set to <code>"false"</code>, an attempt will be made to decode these
 illegal encoded words. The default is true. <p>

 The <code>mail.mime.encodeeol.strict</code> 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 <code>mail.mime.encodeeol.strict</code>
 System property is set to <code>"true"</code>, such an encoding will
 be used when necessary.  The default is false. <p>

 In addition, the <code>mail.mime.charset</code> 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 <code>file.encoding</code> 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.
<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" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Field Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#ALL">ALL</A></B></CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
</TABLE>
&nbsp;
<!-- ======== CONSTRUCTOR SUMMARY ======== -->


<!-- ========== METHOD SUMMARY =========== -->

<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Method Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;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&nbsp;is,
       java.lang.String&nbsp;encoding)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Decode the given input stream.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;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&nbsp;etext)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Decode "unstructured" headers, that is, headers that are defined
 as '*text' as per RFC 822.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;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&nbsp;eword)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The string is parsed using the rules in RFC 2047 for parsing
 an "encoded-word".</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;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&nbsp;os,
       java.lang.String&nbsp;encoding)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Wrap an encoder around the given output stream.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.io.OutputStream</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#encode(java.io.OutputStream, java.lang.String, java.lang.String)">encode</A></B>(java.io.OutputStream&nbsp;os,
       java.lang.String&nbsp;encoding,
       java.lang.String&nbsp;filename)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Wrap an encoder around the given output stream.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;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&nbsp;text)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Encode a RFC 822 "text" token into mail-safe form as per
 RFC 2047.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;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&nbsp;text,
           java.lang.String&nbsp;charset,
           java.lang.String&nbsp;encoding)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Encode a RFC 822 "text" token into mail-safe form as per
 RFC 2047.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;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&nbsp;word)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Encode a RFC 822 "word" token into mail-safe form as per
 RFC 2047.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;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&nbsp;word,
           java.lang.String&nbsp;charset,
           java.lang.String&nbsp;encoding)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Encode a RFC 822 "word" token into mail-safe form as per
 RFC 2047.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#getDefaultJavaCharset()">getDefaultJavaCharset</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the default charset corresponding to the system's current 
 default locale.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#getEncoding(javax.activation.DataHandler)">getEncoding</A></B>(javax.activation.DataHandler&nbsp;dh)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Same as <code>getEncoding(DataSource)</code> except that instead
 of reading the data from an <code>InputStream</code> it uses the
 <code>writeTo</code> method to examine the data.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;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&nbsp;ds)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;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&nbsp;charset)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Convert a MIME charset name into a valid Java charset name.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;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&nbsp;charset)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Convert a java charset into its MIME charset name.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;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&nbsp;word,
      java.lang.String&nbsp;specials)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A utility method to quote a word, if the word contains any
 characters from the specified 'specials' list.</TD>
</TR>
</TABLE>
&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
<TD><B>Methods inherited from class java.lang.Object</B></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
</TR>
</TABLE>
&nbsp;
<P>

<!-- ============ FIELD DETAIL =========== -->

<A NAME="field_detail"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="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" CLASS="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&nbsp;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>
 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".
 </ul><DD><DL>
<DT><B>Parameters:</B><DD><CODE>ds</CODE> - DataSource<DT><B>Returns:</B><DD>the encoding. This is either "7bit",
			"quoted-printable" or "base64"</DL>
</DD>
</DL>
<HR>

<A NAME="getEncoding(javax.activation.DataHandler)"><!-- --></A><H3>
getEncoding</H3>
<PRE>
public static java.lang.String <B>getEncoding</B>(javax.activation.DataHandler&nbsp;dh)</PRE>
<DL>
<DD>Same as <code>getEncoding(DataSource)</code> except that instead
 of reading the data from an <code>InputStream</code> it uses the
 <code>writeTo</code> method to examine the data.  This is more
 efficient in the common case of a <code>DataHandler</code>
 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 <code>InputStream</code> the
 <code>DataHandler</code> uses a thread, a pair of pipe streams,
 and the <code>writeTo</code> method to produce the data. <p><DD><DL>
<DT><B>Since: </B><DD>JavaMail 1.2</DD>
</DL>
</DD>
</DL>
<HR>

<A NAME="decode(java.io.InputStream, java.lang.String)"><!-- --></A><H3>
decode</H3>
<PRE>
public static java.io.InputStream <B>decode</B>(java.io.InputStream&nbsp;is,
                                         java.lang.String&nbsp;encoding)
                                  throws <A HREF="../../../javax/mail/MessagingException.html">MessagingException</A></PRE>
<DL>
<DD>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.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>is</CODE> - input stream<DD><CODE>encoding</CODE> - the encoding of the stream.<DT><B>Returns:</B><DD>decoded input stream.</DL>
</DD>
</DL>
<HR>

<A NAME="encode(java.io.OutputStream, java.lang.String)"><!-- --></A><H3>
encode</H3>
<PRE>
public static java.io.OutputStream <B>encode</B>(java.io.OutputStream&nbsp;os,
                                          java.lang.String&nbsp;encoding)
                                   throws <A HREF="../../../javax/mail/MessagingException.html">MessagingException</A></PRE>
<DL>
<DD>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.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>os</CODE> - output stream<DD><CODE>encoding</CODE> - the encoding of the stream.<DT><B>Returns:</B><DD>output stream that applies the
				specified encoding.</DL>
</DD>
</DL>
<HR>

<A NAME="encode(java.io.OutputStream, java.lang.String, java.lang.String)"><!-- --></A><H3>
encode</H3>
<PRE>
public static java.io.OutputStream <B>encode</B>(java.io.OutputStream&nbsp;os,
                                          java.lang.String&nbsp;encoding,
                                          java.lang.String&nbsp;filename)
                                   throws <A HREF="../../../javax/mail/MessagingException.html">MessagingException</A></PRE>
<DL>
<DD>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 <code>filename</code> parameter is used with the "uuencode"
 encoding and is included in the encoded output.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>os</CODE> - output stream<DD><CODE>encoding</CODE> - the encoding of the stream.<DD><CODE>filename</CODE> - name for the file being encoded (only used
                          with uuencode)<DT><B>Returns:</B><DD>output stream that applies the
                          specified encoding.<DT><B>Since: </B><DD>JavaMail 1.2</DD>
</DL>
</DD>
</DL>
<HR>

<A NAME="encodeText(java.lang.String)"><!-- --></A><H3>
encodeText</H3>
<PRE>
public static java.lang.String <B>encodeText</B>(java.lang.String&nbsp;text)
                                   throws java.io.UnsupportedEncodingException</PRE>
<DL>
<DD>Encode a RFC 822 "text" token into mail-safe form as per
 RFC 2047. <p>

 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. <p>

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

 Example of usage:
 <p><blockquote><pre>

  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
  }

 </pre></blockquote><p><DD><DL>
<DT><B>Parameters:</B><DD><CODE>text</CODE> - Unicode string<DT><B>Returns:</B><DD>Unicode string containing only US-ASCII characters<DT><B>Throws:</B><DD><CODE>java.io.UnsupportedEncodingException</CODE> - if the encoding fails</DL>
</DD>
</DL>
<HR>

<A NAME="encodeText(java.lang.String, java.lang.String, java.lang.String)"><!-- --></A><H3>
encodeText</H3>
<PRE>
public static java.lang.String <B>encodeText</B>(java.lang.String&nbsp;text,
                                          java.lang.String&nbsp;charset,
                                          java.lang.String&nbsp;encoding)
                                   throws java.io.UnsupportedEncodingException</PRE>
<DL>
<DD>Encode a RFC 822 "text" token into mail-safe form as per
 RFC 2047. <p>

 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. <p>

 Note that this method should be used to encode only 
 "unstructured" RFC 822 headers.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>text</CODE> - the header value<DD><CODE>charset</CODE> - the charset. If this parameter is null, the
		platform's default chatset is used.<DD><CODE>encoding</CODE> - 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.<DT><B>Returns:</B><DD>Unicode string containing only US-ASCII characters</DL>
</DD>
</DL>
<HR>

<A NAME="decodeText(java.lang.String)"><!-- --></A><H3>
decodeText</H3>
<PRE>
public static java.lang.String <B>decodeText</B>(java.lang.String&nbsp;etext)
                                   throws java.io.UnsupportedEncodingException</PRE>
<DL>
<DD>Decode "unstructured" headers, that is, headers that are defined
 as '*text' as per RFC 822. <p>

 The string is decoded using the algorithm specified in
 RFC 2047, Section 6.1.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 <p>

 Example of usage:
 <p><blockquote><pre>

  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;

 </pre></blockquote><p><DD><DL>
<DT><B>Parameters:</B><DD><CODE>etext</CODE> - the possibly encoded value<DT><B>Throws:</B><DD><CODE>java.io.UnsupportedEncodingException</CODE> - if the charset
			conversion failed.</DL>
</DD>
</DL>
<HR>

<A NAME="encodeWord(java.lang.String)"><!-- --></A><H3>
encodeWord</H3>
<PRE>
public static java.lang.String <B>encodeWord</B>(java.lang.String&nbsp;word)
                                   throws java.io.UnsupportedEncodingException</PRE>
<DL>
<DD>Encode a RFC 822 "word" token into mail-safe form as per
 RFC 2047. <p>

 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. <p>
 
 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.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>word</CODE> - Unicode string<DT><B>Returns:</B><DD>Array of Unicode strings containing only US-ASCII 
		characters.<DT><B>Throws:</B><DD><CODE>java.io.UnsupportedEncodingException</CODE> - if the encoding fails</DL>
</DD>
</DL>
<HR>

<A NAME="encodeWord(java.lang.String, java.lang.String, java.lang.String)"><!-- --></A><H3>
encodeWord</H3>
<PRE>
public static java.lang.String <B>encodeWord</B>(java.lang.String&nbsp;word,
                                          java.lang.String&nbsp;charset,
                                          java.lang.String&nbsp;encoding)
                                   throws java.io.UnsupportedEncodingException</PRE>
<DL>
<DD>Encode a RFC 822 "word" token into mail-safe form as per
 RFC 2047. <p>

 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. <p><DD><DL>
<DT><B>Parameters:</B><DD><CODE>word</CODE> - Unicode string<DD><CODE>charset</CODE> - the MIME charset<DD><CODE>encoding</CODE> - 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.<DT><B>Returns:</B><DD>Unicode string containing only US-ASCII characters<DT><B>Throws:</B><DD><CODE>java.io.UnsupportedEncodingException</CODE> - if the encoding fails</DL>
</DD>
</DL>
<HR>

<A NAME="decodeWord(java.lang.String)"><!-- --></A><H3>
decodeWord</H3>
<PRE>
public static java.lang.String <B>decodeWord</B>(java.lang.String&nbsp;eword)
                                   throws <A HREF="../../../javax/mail/internet/ParseException.html">ParseException</A>,
                                          java.io.UnsupportedEncodingException</PRE>
<DL>
<DD>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.<p><DD><DL>
<DT><B>Parameters:</B><DD><CODE>eword</CODE> - the possibly encoded value<DT><B>Throws:</B><DD><CODE><A HREF="../../../javax/mail/internet/ParseException.html">ParseException</A></CODE> - if the string is not an
			encoded-word as per RFC 2047.<DD><CODE>java.io.UnsupportedEncodingException</CODE> - if the charset
			conversion failed.</DL>
</DD>
</DL>
<HR>

<A NAME="quote(java.lang.String, java.lang.String)"><!-- --></A><H3>
quote</H3>
<PRE>
public static java.lang.String <B>quote</B>(java.lang.String&nbsp;word,
                                     java.lang.String&nbsp;specials)</PRE>
<DL>
<DD>A utility method to quote a word, if the word contains any
 characters from the specified 'specials' list.<p>

 The <code>HeaderTokenizer</code> class defines two special
 sets of delimiters - MIME and RFC 822. <p>

 This method is typically used during the generation of 
 RFC 822 and MIME header fields.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>word</CODE> - word to be quoted<DD><CODE>specials</CODE> - the set of special characters<DT><B>Returns:</B><DD>the possibly quoted word<DT><B>See Also: </B><DD><A HREF="../../../javax/mail/internet/HeaderTokenizer.html#MIME"><CODE>HeaderTokenizer.MIME</CODE></A>, 
<A HREF="../../../javax/mail/internet/HeaderTokenizer.html#RFC822"><CODE>HeaderTokenizer.RFC822</CODE></A></DL>
</DD>
</DL>
<HR>

<A NAME="javaCharset(java.lang.String)"><!-- --></A><H3>
javaCharset</H3>
<PRE>
public static java.lang.String <B>javaCharset</B>(java.lang.String&nbsp;charset)</PRE>
<DL>
<DD>Convert a MIME charset name into a valid Java charset name. <p><DD><DL>
<DT><B>Parameters:</B><DD><CODE>charset</CODE> - the MIME charset name<DT><B>Returns:</B><DD>the Java charset equivalent. If a suitable mapping is
		not available, the passed in charset is itself returned.</DL>
</DD>
</DL>
<HR>

<A NAME="mimeCharset(java.lang.String)"><!-- --></A><H3>
mimeCharset</H3>
<PRE>
public static java.lang.String <B>mimeCharset</B>(java.lang.String&nbsp;charset)</PRE>
<DL>
<DD>Convert a java charset into its MIME charset name. <p>

 Note that a future version of JDK (post 1.2) might provide
 this functionality, in which case, we may deprecate this
 method then.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>charset</CODE> - the JDK charset<DT><B>Returns:</B><DD>the MIME/IANA equivalent. If a mapping
			is not possible, the passed in charset itself
			is returned.<DT><B>Since: </B><DD>JavaMail 1.1</DD>
</DL>
</DD>
</DL>
<HR>

<A NAME="getDefaultJavaCharset()"><!-- --></A><H3>
getDefaultJavaCharset</H3>
<PRE>
public static java.lang.String <B>getDefaultJavaCharset</B>()</PRE>
<DL>
<DD>Get the default charset corresponding to the system's current 
 default locale.  If the System property <code>mail.mime.charset</code>
 is set, a system charset corresponding to this MIME charset will be
 returned. <p><DD><DL>
<DT><B>Returns:</B><DD>the default charset of the system's default locale, 
 		as a Java charset. (NOT a MIME charset)<DT><B>Since: </B><DD>JavaMail 1.1</DD>
</DL>
</DD>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>

<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_bottom"><!-- --></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
  <TR ALIGN="center" VALIGN="top">
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/MimeUtility.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
  </TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>

<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../javax/mail/internet/MimePartDataSource.html"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../../javax/mail/internet/NewsAddress.html"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
  <A HREF="../../../index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
&nbsp;<A HREF="MimeUtility.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  SUMMARY: &nbsp;INNER&nbsp;|&nbsp;<A HREF="#field_summary">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: &nbsp;<A HREF="#field_detail">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->

<HR>

</BODY>
</HTML>
