Subversion Repositories javautils

Rev

Blame | Last modification | View Log | RSS feed

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <!--NewPage-->
  3. <HTML>
  4. <HEAD>
  5. <!-- Generated by javadoc (build 1.6.0_10) on Tue Nov 17 12:13:40 PST 2009 -->
  6. <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  7. <TITLE>
  8. MimeUtility (JavaMail API documentation)
  9. </TITLE>
  10.  
  11. <META NAME="date" CONTENT="2009-11-17">
  12.  
  13. <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
  14.  
  15. <SCRIPT type="text/javascript">
  16. function windowTitle()
  17. {
  18.     if (location.href.indexOf('is-external=true') == -1) {
  19.         parent.document.title="MimeUtility (JavaMail API documentation)";
  20.     }
  21. }
  22. </SCRIPT>
  23. <NOSCRIPT>
  24. </NOSCRIPT>
  25.  
  26. </HEAD>
  27.  
  28. <BODY BGCOLOR="white" onload="windowTitle();">
  29. <HR>
  30.  
  31.  
  32. <!-- ========= START OF TOP NAVBAR ======= -->
  33. <A NAME="navbar_top"><!-- --></A>
  34. <A HREF="#skip-navbar_top" title="Skip navigation links"></A>
  35. <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
  36. <TR>
  37. <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
  38. <A NAME="navbar_top_firstrow"><!-- --></A>
  39. <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
  40.   <TR ALIGN="center" VALIGN="top">
  41.   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
  42.   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
  43.   <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
  44.   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/MimeUtility.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
  45.   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
  46.   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
  47.   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
  48.   <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
  49.   </TR>
  50. </TABLE>
  51. </TD>
  52. <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
  53. </EM>
  54. </TD>
  55. </TR>
  56.  
  57. <TR>
  58. <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
  59. &nbsp;<A HREF="../../../javax/mail/internet/MimePartDataSource.html" title="class in javax.mail.internet"><B>PREV CLASS</B></A>&nbsp;
  60. &nbsp;<A HREF="../../../javax/mail/internet/NewsAddress.html" title="class in javax.mail.internet"><B>NEXT CLASS</B></A></FONT></TD>
  61. <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
  62.   <A HREF="../../../index.html?javax/mail/internet/MimeUtility.html" target="_top"><B>FRAMES</B></A>  &nbsp;
  63. &nbsp;<A HREF="MimeUtility.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;
  64. &nbsp;<SCRIPT type="text/javascript">
  65.   <!--
  66.   if(window==top) {
  67.     document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>');
  68.   }
  69.   //-->
  70. </SCRIPT>
  71. <NOSCRIPT>
  72.   <A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>
  73. </NOSCRIPT>
  74.  
  75.  
  76. </FONT></TD>
  77. </TR>
  78. <TR>
  79. <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  80.   SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;<A HREF="#field_summary">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
  81. <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  82. DETAIL:&nbsp;<A HREF="#field_detail">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
  83. </TR>
  84. </TABLE>
  85. <A NAME="skip-navbar_top"></A>
  86. <!-- ========= END OF TOP NAVBAR ========= -->
  87.  
  88. <HR>
  89. <!-- ======== START OF CLASS DATA ======== -->
  90. <H2>
  91. <FONT SIZE="-1">
  92. javax.mail.internet</FONT>
  93. <BR>
  94. Class MimeUtility</H2>
  95. <PRE>
  96. <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</A>
  97.   <IMG SRC="../../../resources/inherit.gif" ALT="extended by "><B>javax.mail.internet.MimeUtility</B>
  98. </PRE>
  99. <HR>
  100. <DL>
  101. <DT><PRE>public class <B>MimeUtility</B><DT>extends <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></DL>
  102. </PRE>
  103.  
  104. <P>
  105. This is a utility class that provides various MIME related
  106.  functionality. <p>
  107.  
  108.  There are a set of methods to encode and decode MIME headers as
  109.  per RFC 2047.  Note that, in general, these methods are
  110.  <strong>not</strong> needed when using methods such as
  111.  <code>setSubject</code> and <code>setRecipients</code>; JavaMail
  112.  will automatically encode and decode data when using these "higher
  113. level" methods.  The methods below are only needed when maniuplating
  114.  raw MIME headers using <code>setHeader</code> and <code>getHeader</code>
  115.  methods.  A brief description on handling such headers is given below: <p>
  116.  
  117.  RFC 822 mail headers <strong>must</strong> contain only US-ASCII
  118.  characters. Headers that contain non US-ASCII characters must be
  119.  encoded so that they contain only US-ASCII characters. Basically,
  120.  this process involves using either BASE64 or QP to encode certain
  121.  characters. RFC 2047 describes this in detail. <p>
  122.  
  123.  In Java, Strings contain (16 bit) Unicode characters. ASCII is a
  124.  subset of Unicode (and occupies the range 0 - 127). A String
  125.  that contains only ASCII characters is already mail-safe. If the
  126.  String contains non US-ASCII characters, it must be encoded. An
  127.  additional complexity in this step is that since Unicode is not
  128.  yet a widely used charset, one might want to first charset-encode
  129.  the String into another charset and then do the transfer-encoding.
  130.  <p>
  131.  Note that to get the actual bytes of a mail-safe String (say,
  132.  for sending over SMTP), one must do
  133.  <p><blockquote><pre>
  134.  
  135.         byte[] bytes = string.getBytes("iso-8859-1");  
  136.  
  137.  </pre></blockquote><p>
  138.  
  139.  The <code>setHeader</code> and <code>addHeader</code> methods
  140.  on MimeMessage and MimeBodyPart assume that the given header values
  141.  are Unicode strings that contain only US-ASCII characters. Hence
  142.  the callers of those methods must insure that the values they pass
  143.  do not contain non US-ASCII characters. The methods in this class
  144.  help do this. <p>
  145.  
  146.  The <code>getHeader</code> family of methods on MimeMessage and
  147.  MimeBodyPart return the raw header value. These might be encoded
  148.  as per RFC 2047, and if so, must be decoded into Unicode Strings.
  149.  The methods in this class help to do this. <p>
  150.  
  151.  Several System properties control strict conformance to the MIME
  152.  spec.  Note that these are not session properties but must be set
  153.  globally as System properties. <p>
  154.  
  155.  The <code>mail.mime.decodetext.strict</code> property controls
  156.  decoding of MIME encoded words.  The MIME spec requires that encoded
  157.  words start at the beginning of a whitespace separated word.  Some
  158.  mailers incorrectly include encoded words in the middle of a word.
  159.  If the <code>mail.mime.decodetext.strict</code> System property is
  160.  set to <code>"false"</code>, an attempt will be made to decode these
  161.  illegal encoded words. The default is true. <p>
  162.  
  163.  The <code>mail.mime.encodeeol.strict</code> property controls the
  164.  choice of Content-Transfer-Encoding for MIME parts that are not of
  165.  type "text".  Often such parts will contain textual data for which
  166.  an encoding that allows normal end of line conventions is appropriate.
  167.  In rare cases, such a part will appear to contain entirely textual
  168.  data, but will require an encoding that preserves CR and LF characters
  169.  without change.  If the <code>mail.mime.encodeeol.strict</code>
  170.  System property is set to <code>"true"</code>, such an encoding will
  171.  be used when necessary.  The default is false. <p>
  172.  
  173.  In addition, the <code>mail.mime.charset</code> System property can
  174.  be used to specify the default MIME charset to use for encoded words
  175.  and text parts that don't otherwise specify a charset.  Normally, the
  176. default MIME charset is derived from the default Java charset, as
  177. specified in the <code>file.encoding</code> System property.  Most
  178. applications will have no need to explicitly set the default MIME
  179. charset.  In cases where the default MIME charset to be used for
  180. mail messages is different than the charset used for files stored on
  181. the system, this property should be set. <p>
  182.  
  183. The current implementation also supports the following System property.
  184. <p>
  185. The <code>mail.mime.ignoreunknownencoding</code> property controls
  186. whether unknown values in the <code>Content-Transfer-Encoding</code>
  187. header, as passed to the <code>decode</code> method, cause an exception.
  188. If set to <code>"true"</code>, unknown values are ignored and 8bit
  189. encoding is assumed.  Otherwise, unknown values cause a MessagingException
  190. to be thrown.
  191. <P>
  192.  
  193. <P>
  194. <HR>
  195.  
  196. <P>
  197. <!-- =========== FIELD SUMMARY =========== -->
  198.  
  199. <A NAME="field_summary"><!-- --></A>
  200. <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
  201. <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
  202. <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
  203. <B>Field Summary</B></FONT></TH>
  204. </TR>
  205. <TR BGCOLOR="white" CLASS="TableRowColor">
  206. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  207. <CODE>static&nbsp;int</CODE></FONT></TD>
  208. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#ALL">ALL</A></B></CODE>
  209.  
  210. <BR>
  211. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
  212. </TR>
  213. </TABLE>
  214. &nbsp;
  215. <!-- ========== METHOD SUMMARY =========== -->
  216.  
  217. <A NAME="method_summary"><!-- --></A>
  218. <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
  219. <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
  220. <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
  221. <B>Method Summary</B></FONT></TH>
  222. </TR>
  223. <TR BGCOLOR="white" CLASS="TableRowColor">
  224. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  225. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html?is-external=true" title="class or interface in java.io">InputStream</A></CODE></FONT></TD>
  226. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#decode(java.io.InputStream, java.lang.String)">decode</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html?is-external=true" title="class or interface in java.io">InputStream</A>&nbsp;is,
  227.       <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;encoding)</CODE>
  228.  
  229. <BR>
  230. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Decode the given input stream.</TD>
  231. </TR>
  232. <TR BGCOLOR="white" CLASS="TableRowColor">
  233. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  234. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD>
  235. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#decodeText(java.lang.String)">decodeText</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;etext)</CODE>
  236.  
  237. <BR>
  238. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Decode "unstructured" headers, that is, headers that are defined
  239. as '*text' as per RFC 822.</TD>
  240. </TR>
  241. <TR BGCOLOR="white" CLASS="TableRowColor">
  242. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  243. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD>
  244. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#decodeWord(java.lang.String)">decodeWord</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;eword)</CODE>
  245.  
  246. <BR>
  247. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The string is parsed using the rules in RFC 2047 and RFC 2231 for
  248. parsing an "encoded-word".</TD>
  249. </TR>
  250. <TR BGCOLOR="white" CLASS="TableRowColor">
  251. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  252. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/OutputStream.html?is-external=true" title="class or interface in java.io">OutputStream</A></CODE></FONT></TD>
  253. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#encode(java.io.OutputStream, java.lang.String)">encode</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/OutputStream.html?is-external=true" title="class or interface in java.io">OutputStream</A>&nbsp;os,
  254.       <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;encoding)</CODE>
  255.  
  256. <BR>
  257. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Wrap an encoder around the given output stream.</TD>
  258. </TR>
  259. <TR BGCOLOR="white" CLASS="TableRowColor">
  260. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  261. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/OutputStream.html?is-external=true" title="class or interface in java.io">OutputStream</A></CODE></FONT></TD>
  262. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#encode(java.io.OutputStream, java.lang.String, java.lang.String)">encode</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/OutputStream.html?is-external=true" title="class or interface in java.io">OutputStream</A>&nbsp;os,
  263.       <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;encoding,
  264.       <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;filename)</CODE>
  265.  
  266. <BR>
  267. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Wrap an encoder around the given output stream.</TD>
  268. </TR>
  269. <TR BGCOLOR="white" CLASS="TableRowColor">
  270. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  271. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD>
  272. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#encodeText(java.lang.String)">encodeText</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;text)</CODE>
  273.  
  274. <BR>
  275. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Encode a RFC 822 "text" token into mail-safe form as per
  276. RFC 2047.</TD>
  277. </TR>
  278. <TR BGCOLOR="white" CLASS="TableRowColor">
  279. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  280. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD>
  281. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#encodeText(java.lang.String, java.lang.String, java.lang.String)">encodeText</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;text,
  282.           <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;charset,
  283.           <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;encoding)</CODE>
  284.  
  285. <BR>
  286. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Encode a RFC 822 "text" token into mail-safe form as per
  287. RFC 2047.</TD>
  288. </TR>
  289. <TR BGCOLOR="white" CLASS="TableRowColor">
  290. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  291. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD>
  292. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#encodeWord(java.lang.String)">encodeWord</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;word)</CODE>
  293.  
  294. <BR>
  295. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Encode a RFC 822 "word" token into mail-safe form as per
  296. RFC 2047.</TD>
  297. </TR>
  298. <TR BGCOLOR="white" CLASS="TableRowColor">
  299. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  300. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD>
  301. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#encodeWord(java.lang.String, java.lang.String, java.lang.String)">encodeWord</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;word,
  302.           <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;charset,
  303.           <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;encoding)</CODE>
  304.  
  305. <BR>
  306. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Encode a RFC 822 "word" token into mail-safe form as per
  307. RFC 2047.</TD>
  308. </TR>
  309. <TR BGCOLOR="white" CLASS="TableRowColor">
  310. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  311. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD>
  312. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#fold(int, java.lang.String)">fold</A></B>(int&nbsp;used,
  313.     <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;s)</CODE>
  314.  
  315. <BR>
  316. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fold a string at linear whitespace so that each line is no longer
  317. than 76 characters, if possible.</TD>
  318. </TR>
  319. <TR BGCOLOR="white" CLASS="TableRowColor">
  320. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  321. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD>
  322. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#getDefaultJavaCharset()">getDefaultJavaCharset</A></B>()</CODE>
  323.  
  324. <BR>
  325. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the default charset corresponding to the system's current
  326.  default locale.</TD>
  327. </TR>
  328. <TR BGCOLOR="white" CLASS="TableRowColor">
  329. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  330. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD>
  331. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#getEncoding(javax.activation.DataHandler)">getEncoding</A></B>(<A HREF="http://java.sun.com/javase/technologies/desktop/javabeans/glasgow/javadocs/javax/activation/DataHandler.html?is-external=true" title="class or interface in javax.activation">DataHandler</A>&nbsp;dh)</CODE>
  332.  
  333. <BR>
  334. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Same as <code>getEncoding(DataSource)</code> except that instead
  335.  of reading the data from an <code>InputStream</code> it uses the
  336.  <code>writeTo</code> method to examine the data.</TD>
  337. </TR>
  338. <TR BGCOLOR="white" CLASS="TableRowColor">
  339. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  340. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD>
  341. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#getEncoding(javax.activation.DataSource)">getEncoding</A></B>(<A HREF="http://java.sun.com/javase/technologies/desktop/javabeans/glasgow/javadocs/javax/activation/DataSource.html?is-external=true" title="class or interface in javax.activation">DataSource</A>&nbsp;ds)</CODE>
  342.  
  343. <BR>
  344. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the content-transfer-encoding that should be applied
  345.  to the input stream of this datasource, to make it mailsafe.</TD>
  346. </TR>
  347. <TR BGCOLOR="white" CLASS="TableRowColor">
  348. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  349. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD>
  350. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#javaCharset(java.lang.String)">javaCharset</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;charset)</CODE>
  351.  
  352. <BR>
  353. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Convert a MIME charset name into a valid Java charset name.</TD>
  354. </TR>
  355. <TR BGCOLOR="white" CLASS="TableRowColor">
  356. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  357. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD>
  358. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#mimeCharset(java.lang.String)">mimeCharset</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;charset)</CODE>
  359.  
  360. <BR>
  361. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Convert a java charset into its MIME charset name.</TD>
  362. </TR>
  363. <TR BGCOLOR="white" CLASS="TableRowColor">
  364. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  365. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD>
  366. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#quote(java.lang.String, java.lang.String)">quote</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;word,
  367.       <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;specials)</CODE>
  368.  
  369. <BR>
  370. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A utility method to quote a word, if the word contains any
  371.  characters from the specified 'specials' list.</TD>
  372. </TR>
  373. <TR BGCOLOR="white" CLASS="TableRowColor">
  374. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  375. <CODE>static&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD>
  376. <TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#unfold(java.lang.String)">unfold</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;s)</CODE>
  377.  
  378. <BR>
  379. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Unfold a folded header.</TD>
  380. </TR>
  381. </TABLE>
  382. &nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
  383. <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
  384. <TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
  385. <TH ALIGN="left"><B>Methods inherited from class java.lang.<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></B></TH>
  386. </TR>
  387. <TR BGCOLOR="white" CLASS="TableRowColor">
  388. <TD><CODE><A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang">clone</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang">equals</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang">finalize</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang">getClass</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang">hashCode</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang">notify</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang">notifyAll</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang">toString</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang">wait</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang">wait</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#wait(long, int)" title="class or interface in java.lang">wait</A></CODE></TD>
  389. </TR>
  390. </TABLE>
  391. &nbsp;
  392. <P>
  393.  
  394. <!-- ============ FIELD DETAIL =========== -->
  395.  
  396. <A NAME="field_detail"><!-- --></A>
  397. <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
  398. <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
  399. <TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
  400. <B>Field Detail</B></FONT></TH>
  401. </TR>
  402. </TABLE>
  403.  
  404. <A NAME="ALL"><!-- --></A><H3>
  405. ALL</H3>
  406. <PRE>
  407. public static final int <B>ALL</B></PRE>
  408. <DL>
  409. <DL>
  410. <DT><B>See Also:</B><DD><A HREF="../../../constant-values.html#javax.mail.internet.MimeUtility.ALL">Constant Field Values</A></DL>
  411. </DL>
  412.  
  413. <!-- ============ METHOD DETAIL ========== -->
  414.  
  415. <A NAME="method_detail"><!-- --></A>
  416. <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
  417. <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
  418. <TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
  419. <B>Method Detail</B></FONT></TH>
  420. </TR>
  421. </TABLE>
  422.  
  423. <A NAME="getEncoding(javax.activation.DataSource)"><!-- --></A><H3>
  424. getEncoding</H3>
  425. <PRE>
  426. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>getEncoding</B>(<A HREF="http://java.sun.com/javase/technologies/desktop/javabeans/glasgow/javadocs/javax/activation/DataSource.html?is-external=true" title="class or interface in javax.activation">DataSource</A>&nbsp;ds)</PRE>
  427. <DL>
  428. <DD>Get the content-transfer-encoding that should be applied
  429.  to the input stream of this datasource, to make it mailsafe. <p>
  430.  
  431.  The algorithm used here is: <br>
  432.  <ul>
  433.  <li>
  434.  If the primary type of this datasource is "text" and if all
  435.  the bytes in its input stream are US-ASCII, then the encoding
  436.  is "7bit". If more than half of the bytes are non-US-ASCII, then
  437.  the encoding is "base64". If less than half of the bytes are
  438.  non-US-ASCII, then the encoding is "quoted-printable".
  439.  <li>
  440.  If the primary type of this datasource is not "text", then if
  441.  all the bytes of its input stream are US-ASCII, the encoding
  442.  is "7bit". If there is even one non-US-ASCII character, the
  443.  encoding is "base64".
  444.  </ul>
  445. <P>
  446. <DD><DL>
  447. <DT><B>Parameters:</B><DD><CODE>ds</CODE> - DataSource
  448. <DT><B>Returns:</B><DD>the encoding. This is either "7bit",
  449.                         "quoted-printable" or "base64"</DL>
  450. </DD>
  451. </DL>
  452. <HR>
  453.  
  454. <A NAME="getEncoding(javax.activation.DataHandler)"><!-- --></A><H3>
  455. getEncoding</H3>
  456. <PRE>
  457. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>getEncoding</B>(<A HREF="http://java.sun.com/javase/technologies/desktop/javabeans/glasgow/javadocs/javax/activation/DataHandler.html?is-external=true" title="class or interface in javax.activation">DataHandler</A>&nbsp;dh)</PRE>
  458. <DL>
  459. <DD>Same as <code>getEncoding(DataSource)</code> except that instead
  460.  of reading the data from an <code>InputStream</code> it uses the
  461.  <code>writeTo</code> method to examine the data.  This is more
  462.  efficient in the common case of a <code>DataHandler</code>
  463.  created with an object and a MIME type (for example, a
  464.  "text/plain" String) because all the I/O is done in this
  465.  thread.  In the case requiring an <code>InputStream</code> the
  466.  <code>DataHandler</code> uses a thread, a pair of pipe streams,
  467.  and the <code>writeTo</code> method to produce the data. <p>
  468. <P>
  469. <DD><DL>
  470. <DT><B>Since:</B></DT>
  471.   <DD>JavaMail 1.2</DD>
  472. </DL>
  473. </DD>
  474. </DL>
  475. <HR>
  476.  
  477. <A NAME="decode(java.io.InputStream, java.lang.String)"><!-- --></A><H3>
  478. decode</H3>
  479. <PRE>
  480. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html?is-external=true" title="class or interface in java.io">InputStream</A> <B>decode</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html?is-external=true" title="class or interface in java.io">InputStream</A>&nbsp;is,
  481.                                  <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;encoding)
  482.                           throws <A HREF="../../../javax/mail/MessagingException.html" title="class in javax.mail">MessagingException</A></PRE>
  483. <DL>
  484. <DD>Decode the given input stream. The Input stream returned is
  485.  the decoded input stream. All the encodings defined in RFC 2045
  486.  are supported here. They include "base64", "quoted-printable",
  487.  "7bit", "8bit", and "binary". In addition, "uuencode" is also
  488.  supported. <p>
  489.  
  490.  In the current implementation, if the
  491.  <code>mail.mime.ignoreunknownencoding</code> system property is set to
  492.  <code>"true"</code>, unknown encoding values are ignored and the
  493.  original InputStream is returned.
  494. <P>
  495. <DD><DL>
  496. <DT><B>Parameters:</B><DD><CODE>is</CODE> - input stream<DD><CODE>encoding</CODE> - the encoding of the stream.
  497. <DT><B>Returns:</B><DD>decoded input stream.
  498. <DT><B>Throws:</B>
  499. <DD><CODE><A HREF="../../../javax/mail/MessagingException.html" title="class in javax.mail">MessagingException</A></CODE> - if the encoding is unknown</DL>
  500. </DD>
  501. </DL>
  502. <HR>
  503.  
  504. <A NAME="encode(java.io.OutputStream, java.lang.String)"><!-- --></A><H3>
  505. encode</H3>
  506. <PRE>
  507. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/OutputStream.html?is-external=true" title="class or interface in java.io">OutputStream</A> <B>encode</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/OutputStream.html?is-external=true" title="class or interface in java.io">OutputStream</A>&nbsp;os,
  508.                                   <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;encoding)
  509.                            throws <A HREF="../../../javax/mail/MessagingException.html" title="class in javax.mail">MessagingException</A></PRE>
  510. <DL>
  511. <DD>Wrap an encoder around the given output stream.
  512.  All the encodings defined in RFC 2045 are supported here.
  513.  They include "base64", "quoted-printable", "7bit", "8bit" and
  514.  "binary". In addition, "uuencode" is also supported.
  515. <P>
  516. <DD><DL>
  517. <DT><B>Parameters:</B><DD><CODE>os</CODE> - output stream<DD><CODE>encoding</CODE> - the encoding of the stream.
  518. <DT><B>Returns:</B><DD>output stream that applies the
  519.                                 specified encoding.
  520. <DT><B>Throws:</B>
  521. <DD><CODE><A HREF="../../../javax/mail/MessagingException.html" title="class in javax.mail">MessagingException</A></CODE> - if the encoding is unknown</DL>
  522. </DD>
  523. </DL>
  524. <HR>
  525.  
  526. <A NAME="encode(java.io.OutputStream, java.lang.String, java.lang.String)"><!-- --></A><H3>
  527. encode</H3>
  528. <PRE>
  529. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/OutputStream.html?is-external=true" title="class or interface in java.io">OutputStream</A> <B>encode</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/OutputStream.html?is-external=true" title="class or interface in java.io">OutputStream</A>&nbsp;os,
  530.                                   <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;encoding,
  531.                                   <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;filename)
  532.                            throws <A HREF="../../../javax/mail/MessagingException.html" title="class in javax.mail">MessagingException</A></PRE>
  533. <DL>
  534. <DD>Wrap an encoder around the given output stream.
  535.  All the encodings defined in RFC 2045 are supported here.
  536.  They include "base64", "quoted-printable", "7bit", "8bit" and
  537.  "binary". In addition, "uuencode" is also supported.
  538.  The <code>filename</code> parameter is used with the "uuencode"
  539.  encoding and is included in the encoded output.
  540. <P>
  541. <DD><DL>
  542. <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
  543.                           with uuencode)
  544. <DT><B>Returns:</B><DD>output stream that applies the
  545.                           specified encoding.
  546. <DT><B>Throws:</B>
  547. <DD><CODE><A HREF="../../../javax/mail/MessagingException.html" title="class in javax.mail">MessagingException</A></CODE><DT><B>Since:</B></DT>
  548.   <DD>JavaMail 1.2</DD>
  549. </DL>
  550. </DD>
  551. </DL>
  552. <HR>
  553.  
  554. <A NAME="encodeText(java.lang.String)"><!-- --></A><H3>
  555. encodeText</H3>
  556. <PRE>
  557. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>encodeText</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;text)
  558.                          throws <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/UnsupportedEncodingException.html?is-external=true" title="class or interface in java.io">UnsupportedEncodingException</A></PRE>
  559. <DL>
  560. <DD>Encode a RFC 822 "text" token into mail-safe form as per
  561.  RFC 2047. <p>
  562.  
  563.  The given Unicode string is examined for non US-ASCII
  564.  characters. If the string contains only US-ASCII characters,
  565.  it is returned as-is.  If the string contains non US-ASCII
  566.  characters, it is first character-encoded using the platform's
  567. default charset, then transfer-encoded using either the B or
  568. Q encoding. The resulting bytes are then returned as a Unicode
  569. string containing only ASCII  characters. <p>
  570.  
  571. Note that this method should be used to encode only
  572. "unstructured" RFC 822 headers. <p>
  573.  
  574. Example of usage:
  575. <p><blockquote><pre>
  576.  
  577.  MimePart part = ...
  578.  String rawvalue = "FooBar Mailer, Japanese version 1.1"
  579.  try {
  580.    // If we know for sure that rawvalue contains only US-ASCII
  581.    // characters, we can skip the encoding part
  582.    part.setHeader("X-mailer", MimeUtility.encodeText(rawvalue));
  583.  } catch (UnsupportedEncodingException e) {
  584.    // encoding failure
  585.  } catch (MessagingException me) {
  586.   // setHeader() failure
  587.  }
  588.  
  589. </pre></blockquote><p>
  590. <P>
  591. <DD><DL>
  592. <DT><B>Parameters:</B><DD><CODE>text</CODE> - Unicode string
  593. <DT><B>Returns:</B><DD>Unicode string containing only US-ASCII characters
  594. <DT><B>Throws:</B>
  595. <DD><CODE><A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/UnsupportedEncodingException.html?is-external=true" title="class or interface in java.io">UnsupportedEncodingException</A></CODE> - if the encoding fails</DL>
  596. </DD>
  597. </DL>
  598. <HR>
  599.  
  600. <A NAME="encodeText(java.lang.String, java.lang.String, java.lang.String)"><!-- --></A><H3>
  601. encodeText</H3>
  602. <PRE>
  603. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>encodeText</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;text,
  604.                                <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;charset,
  605.                                <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;encoding)
  606.                         throws <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/UnsupportedEncodingException.html?is-external=true" title="class or interface in java.io">UnsupportedEncodingException</A></PRE>
  607. <DL>
  608. <DD>Encode a RFC 822 "text" token into mail-safe form as per
  609. RFC 2047. <p>
  610.  
  611. The given Unicode string is examined for non US-ASCII
  612. characters. If the string contains only US-ASCII characters,
  613. it is returned as-is.  If the string contains non US-ASCII
  614. characters, it is first character-encoded using the specified
  615. charset, then transfer-encoded using either the B or Q encoding.
  616. The resulting bytes are then returned as a Unicode string
  617. containing only ASCII characters. <p>
  618.  
  619. Note that this method should be used to encode only
  620. "unstructured" RFC 822 headers.
  621. <P>
  622. <DD><DL>
  623. <DT><B>Parameters:</B><DD><CODE>text</CODE> - the header value<DD><CODE>charset</CODE> - the charset. If this parameter is null, the
  624.                platform's default chatset is used.<DD><CODE>encoding</CODE> - the encoding to be used. Currently supported
  625.                 values are "B" and "Q". If this parameter is null, then
  626.                 the "Q" encoding is used if most of characters to be
  627.                 encoded are in the ASCII charset, otherwise "B" encoding
  628.                 is used.
  629. <DT><B>Returns:</B><DD>Unicode string containing only US-ASCII characters
  630. <DT><B>Throws:</B>
  631. <DD><CODE><A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/UnsupportedEncodingException.html?is-external=true" title="class or interface in java.io">UnsupportedEncodingException</A></CODE></DL>
  632. </DD>
  633. </DL>
  634. <HR>
  635.  
  636. <A NAME="decodeText(java.lang.String)"><!-- --></A><H3>
  637. decodeText</H3>
  638. <PRE>
  639. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>decodeText</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;etext)
  640.                          throws <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/UnsupportedEncodingException.html?is-external=true" title="class or interface in java.io">UnsupportedEncodingException</A></PRE>
  641. <DL>
  642. <DD>Decode "unstructured" headers, that is, headers that are defined
  643.  as '*text' as per RFC 822. <p>
  644.  
  645.  The string is decoded using the algorithm specified in
  646.  RFC 2047, Section 6.1. If the charset-conversion fails
  647.  for any sequence, an UnsupportedEncodingException is thrown.
  648.  If the String is not an RFC 2047 style encoded header, it is
  649.  returned as-is <p>
  650.  
  651.  Example of usage:
  652.  <p><blockquote><pre>
  653.  
  654.   MimePart part = ...
  655.   String rawvalue = null;
  656.   String  value = null;
  657.   try {
  658.     if ((rawvalue = part.getHeader("X-mailer")[0]) != null)
  659.       value = MimeUtility.decodeText(rawvalue);
  660.   } catch (UnsupportedEncodingException e) {
  661.       // Don't care
  662.      value = rawvalue;
  663.  } catch (MessagingException me) { }
  664.  
  665.  return value;
  666.  
  667. </pre></blockquote><p>
  668. <P>
  669. <DD><DL>
  670. <DT><B>Parameters:</B><DD><CODE>etext</CODE> - the possibly encoded value
  671. <DT><B>Throws:</B>
  672. <DD><CODE><A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/UnsupportedEncodingException.html?is-external=true" title="class or interface in java.io">UnsupportedEncodingException</A></CODE> - if the charset
  673.                        conversion failed.</DL>
  674. </DD>
  675. </DL>
  676. <HR>
  677.  
  678. <A NAME="encodeWord(java.lang.String)"><!-- --></A><H3>
  679. encodeWord</H3>
  680. <PRE>
  681. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>encodeWord</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;word)
  682.                         throws <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/UnsupportedEncodingException.html?is-external=true" title="class or interface in java.io">UnsupportedEncodingException</A></PRE>
  683. <DL>
  684. <DD>Encode a RFC 822 "word" token into mail-safe form as per
  685. RFC 2047. <p>
  686.  
  687. The given Unicode string is examined for non US-ASCII
  688. characters. If the string contains only US-ASCII characters,
  689. it is returned as-is.  If the string contains non US-ASCII
  690. characters, it is first character-encoded using the platform's
  691.  default charset, then transfer-encoded using either the B or
  692.  Q encoding. The resulting bytes are then returned as a Unicode
  693.  string containing only ASCII  characters. <p>
  694.  
  695.  This method is meant to be used when creating RFC 822 "phrases".
  696.  The InternetAddress class, for example, uses this to encode
  697.  it's 'phrase' component.
  698. <P>
  699. <DD><DL>
  700. <DT><B>Parameters:</B><DD><CODE>word</CODE> - Unicode string
  701. <DT><B>Returns:</B><DD>Array of Unicode strings containing only US-ASCII
  702.                characters.
  703. <DT><B>Throws:</B>
  704. <DD><CODE><A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/UnsupportedEncodingException.html?is-external=true" title="class or interface in java.io">UnsupportedEncodingException</A></CODE> - if the encoding fails</DL>
  705. </DD>
  706. </DL>
  707. <HR>
  708.  
  709. <A NAME="encodeWord(java.lang.String, java.lang.String, java.lang.String)"><!-- --></A><H3>
  710. encodeWord</H3>
  711. <PRE>
  712. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>encodeWord</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;word,
  713.                                <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;charset,
  714.                                <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;encoding)
  715.                         throws <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/UnsupportedEncodingException.html?is-external=true" title="class or interface in java.io">UnsupportedEncodingException</A></PRE>
  716. <DL>
  717. <DD>Encode a RFC 822 "word" token into mail-safe form as per
  718. RFC 2047. <p>
  719.  
  720. The given Unicode string is examined for non US-ASCII
  721. characters. If the string contains only US-ASCII characters,
  722. it is returned as-is.  If the string contains non US-ASCII
  723. characters, it is first character-encoded using the specified
  724. charset, then transfer-encoded using either the B or Q encoding.
  725. The resulting bytes are then returned as a Unicode string
  726. containing only ASCII characters. <p>
  727. <P>
  728. <DD><DL>
  729. <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
  730.                values are "B" and "Q". If this parameter is null, then
  731.                the "Q" encoding is used if most of characters to be
  732.                encoded are in the ASCII charset, otherwise "B" encoding
  733.                is used.
  734. <DT><B>Returns:</B><DD>Unicode string containing only US-ASCII characters
  735. <DT><B>Throws:</B>
  736. <DD><CODE><A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/UnsupportedEncodingException.html?is-external=true" title="class or interface in java.io">UnsupportedEncodingException</A></CODE> - if the encoding fails</DL>
  737. </DD>
  738. </DL>
  739. <HR>
  740.  
  741. <A NAME="decodeWord(java.lang.String)"><!-- --></A><H3>
  742. decodeWord</H3>
  743. <PRE>
  744. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>decodeWord</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;eword)
  745.                         throws <A HREF="../../../javax/mail/internet/ParseException.html" title="class in javax.mail.internet">ParseException</A>,
  746.                                <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/UnsupportedEncodingException.html?is-external=true" title="class or interface in java.io">UnsupportedEncodingException</A></PRE>
  747. <DL>
  748. <DD>The string is parsed using the rules in RFC 2047 and RFC 2231 for
  749. parsing an "encoded-word".  If the parse fails, a ParseException is
  750. thrown. Otherwise, it is transfer-decoded, and then
  751. charset-converted into Unicode. If the charset-conversion
  752. fails, an UnsupportedEncodingException is thrown.<p>
  753. <P>
  754. <DD><DL>
  755. <DT><B>Parameters:</B><DD><CODE>eword</CODE> - the encoded value
  756. <DT><B>Throws:</B>
  757. <DD><CODE><A HREF="../../../javax/mail/internet/ParseException.html" title="class in javax.mail.internet">ParseException</A></CODE> - if the string is not an
  758.                        encoded-word as per RFC 2047 and RFC 2231.
  759. <DD><CODE><A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/UnsupportedEncodingException.html?is-external=true" title="class or interface in java.io">UnsupportedEncodingException</A></CODE> - if the charset
  760.                        conversion failed.</DL>
  761. </DD>
  762. </DL>
  763. <HR>
  764.  
  765. <A NAME="quote(java.lang.String, java.lang.String)"><!-- --></A><H3>
  766. quote</H3>
  767. <PRE>
  768. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>quote</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;word,
  769.                           <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;specials)</PRE>
  770. <DL>
  771. <DD>A utility method to quote a word, if the word contains any
  772. characters from the specified 'specials' list.<p>
  773.  
  774. The <code>HeaderTokenizer</code> class defines two special
  775. sets of delimiters - MIME and RFC 822. <p>
  776.  
  777. This method is typically used during the generation of
  778. RFC 822 and MIME header fields.
  779. <P>
  780. <DD><DL>
  781. <DT><B>Parameters:</B><DD><CODE>word</CODE> - word to be quoted<DD><CODE>specials</CODE> - the set of special characters
  782. <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>,
  783. <A HREF="../../../javax/mail/internet/HeaderTokenizer.html#RFC822"><CODE>HeaderTokenizer.RFC822</CODE></A></DL>
  784. </DD>
  785. </DL>
  786. <HR>
  787.  
  788. <A NAME="fold(int, java.lang.String)"><!-- --></A><H3>
  789. fold</H3>
  790. <PRE>
  791. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>fold</B>(int&nbsp;used,
  792.                          <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;s)</PRE>
  793. <DL>
  794. <DD>Fold a string at linear whitespace so that each line is no longer
  795. than 76 characters, if possible.  If there are more than 76
  796. non-whitespace characters consecutively, the string is folded at
  797. the first whitespace after that sequence.  The parameter
  798. <code>used</code> indicates how many characters have been used in
  799. the current line; it is usually the length of the header name. <p>
  800.  
  801. Note that line breaks in the string aren't escaped; they probably
  802.  should be.
  803. <P>
  804. <DD><DL>
  805. <DT><B>Parameters:</B><DD><CODE>used</CODE> - characters used in line so far<DD><CODE>s</CODE> - the string to fold
  806. <DT><B>Returns:</B><DD>the folded string<DT><B>Since:</B></DT>
  807.   <DD>JavaMail 1.4</DD>
  808. </DL>
  809. </DD>
  810. </DL>
  811. <HR>
  812.  
  813. <A NAME="unfold(java.lang.String)"><!-- --></A><H3>
  814. unfold</H3>
  815. <PRE>
  816. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>unfold</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;s)</PRE>
  817. <DL>
  818. <DD>Unfold a folded header.  Any line breaks that aren't escaped and
  819. are followed by whitespace are removed.
  820. <P>
  821. <DD><DL>
  822. <DT><B>Parameters:</B><DD><CODE>s</CODE> - the string to unfold
  823. <DT><B>Returns:</B><DD>the unfolded string<DT><B>Since:</B></DT>
  824.  <DD>JavaMail 1.4</DD>
  825. </DL>
  826. </DD>
  827. </DL>
  828. <HR>
  829.  
  830. <A NAME="javaCharset(java.lang.String)"><!-- --></A><H3>
  831. javaCharset</H3>
  832. <PRE>
  833. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>javaCharset</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;charset)</PRE>
  834. <DL>
  835. <DD>Convert a MIME charset name into a valid Java charset name. <p>
  836. <P>
  837. <DD><DL>
  838. <DT><B>Parameters:</B><DD><CODE>charset</CODE> - the MIME charset name
  839. <DT><B>Returns:</B><DD>the Java charset equivalent. If a suitable mapping is
  840.                not available, the passed in charset is itself returned.</DL>
  841. </DD>
  842. </DL>
  843. <HR>
  844.  
  845. <A NAME="mimeCharset(java.lang.String)"><!-- --></A><H3>
  846. mimeCharset</H3>
  847. <PRE>
  848. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>mimeCharset</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;charset)</PRE>
  849. <DL>
  850. <DD>Convert a java charset into its MIME charset name. <p>
  851.  
  852. Note that a future version of JDK (post 1.2) might provide
  853. this functionality, in which case, we may deprecate this
  854. method then.
  855. <P>
  856. <DD><DL>
  857. <DT><B>Parameters:</B><DD><CODE>charset</CODE> - the JDK charset
  858. <DT><B>Returns:</B><DD>the MIME/IANA equivalent. If a mapping
  859.                        is not possible, the passed in charset itself
  860.                        is returned.<DT><B>Since:</B></DT>
  861.  <DD>JavaMail 1.1</DD>
  862. </DL>
  863. </DD>
  864. </DL>
  865. <HR>
  866.  
  867. <A NAME="getDefaultJavaCharset()"><!-- --></A><H3>
  868. getDefaultJavaCharset</H3>
  869. <PRE>
  870. public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>getDefaultJavaCharset</B>()</PRE>
  871. <DL>
  872. <DD>Get the default charset corresponding to the system's current
  873.  default locale.  If the System property <code>mail.mime.charset</code>
  874.  is set, a system charset corresponding to this MIME charset will be
  875.  returned. <p>
  876. <P>
  877. <DD><DL>
  878.  
  879. <DT><B>Returns:</B><DD>the default charset of the system's default locale,
  880.                as a Java charset. (NOT a MIME charset)<DT><B>Since:</B></DT>
  881.  <DD>JavaMail 1.1</DD>
  882. </DL>
  883. </DD>
  884. </DL>
  885. <!-- ========= END OF CLASS DATA ========= -->
  886. <HR>
  887.  
  888.  
  889. <!-- ======= START OF BOTTOM NAVBAR ====== -->
  890. <A NAME="navbar_bottom"><!-- --></A>
  891. <A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
  892. <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
  893. <TR>
  894. <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
  895. <A NAME="navbar_bottom_firstrow"><!-- --></A>
  896. <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
  897.  <TR ALIGN="center" VALIGN="top">
  898.  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
  899.  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
  900.  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
  901.  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/MimeUtility.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
  902.  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
  903.  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
  904.  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
  905.  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
  906.  </TR>
  907. </TABLE>
  908. </TD>
  909. <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
  910. </EM>
  911. </TD>
  912. </TR>
  913.  
  914. <TR>
  915. <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
  916. &nbsp;<A HREF="../../../javax/mail/internet/MimePartDataSource.html" title="class in javax.mail.internet"><B>PREV CLASS</B></A>&nbsp;
  917. &nbsp;<A HREF="../../../javax/mail/internet/NewsAddress.html" title="class in javax.mail.internet"><B>NEXT CLASS</B></A></FONT></TD>
  918. <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
  919.  <A HREF="../../../index.html?javax/mail/internet/MimeUtility.html" target="_top"><B>FRAMES</B></A>  &nbsp;
  920. &nbsp;<A HREF="MimeUtility.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;
  921. &nbsp;<SCRIPT type="text/javascript">
  922.  <!--
  923.  if(window==top) {
  924.    document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>');
  925.  }
  926.  //-->
  927. </SCRIPT>
  928. <NOSCRIPT>
  929.  <A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>
  930. </NOSCRIPT>
  931.  
  932.  
  933. </FONT></TD>
  934. </TR>
  935. <TR>
  936. <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  937.  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;<A HREF="#field_summary">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
  938. <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  939. DETAIL:&nbsp;<A HREF="#field_detail">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
  940. </TR>
  941. </TABLE>
  942. <A NAME="skip-navbar_bottom"></A>
  943. <!-- ======== END OF BOTTOM NAVBAR ======= -->
  944.  
  945. <HR>
  946. Copyright &#169; 2009 <a href="http://www.sun.com">Sun Microsystems, Inc.</a>. All Rights Reserved.
  947. </BODY>
  948. </HTML>
  949.