javax.mail.internet 
Class MimeUtility
java.lang.Object
  |
  +--javax.mail.internet.MimeUtility
--------------------------------------------------------------------------------public class MimeUtility
extends java.lang.Object
This is a utility class that provides various MIME related functionality. There are a set of methods to encode and decode MIME headers as per RFC 2047. A brief description on handling such headers is given below: RFC 822 mail headers must contain only US-ASCII characters. Headers that contain non US-ASCII characters must be encoded so that they contain only US-ASCII characters. Basically, this process involves using either BASE64 or QP to encode certain characters. RFC 2047 describes this in detail. In Java, Strings contain (16 bit) Unicode characters. ASCII is a subset of Unicode (and occupies the range 0 - 127). A String that contains only ASCII characters is already mail-safe. If the String contains non US-ASCII characters, it must be encoded. An additional complexity in this step is that since Unicode is not yet a widely used charset, one might want to first charset-encode the String into another charset and then do the transfer-encoding. Note that to get the actual bytes of a mail-safe String (say, for sending over SMTP), one must do  byte[] bytes = string.getBytes("iso-8859-1");  
The setHeader() and addHeader() methods on MimeMessage and MimeBodyPart assume that the given header values are Unicode strings that contain only US-ASCII characters. Hence the callers of those methods must insure that the values they pass do not contain non US-ASCII characters. The methods in this class help do this. The getHeader() family of methods on MimeMessage and MimeBodyPart return the raw header value. These might be encoded as per RFC 2047, and if so, must be decoded into Unicode Strings. The methods in this class help to do this. --------------------------------------------------------------------------------Field Summary 
static int ALL 
            
  Method Summary 
static java.io.InputStream decode(java.io.InputStream is, java.lang.String encoding) 
          Decode the given input stream. 
static java.lang.String decodeText(java.lang.String etext) 
          Decode "unstructured" headers, that is, headers that are defined as '*text' as per RFC 822. 
static java.lang.String decodeWord(java.lang.String eword) 
          The string is parsed using the rules in RFC 2047 for parsing an "encoded-word". 
static java.io.OutputStream encode(java.io.OutputStream os, java.lang.String encoding) 
          Wrap an encoder around the given output stream. 
static java.io.OutputStream encode(java.io.OutputStream os, java.lang.String encoding, java.lang.String filename) 
          Wrap an encoder around the given output stream. 
static java.lang.String encodeText(java.lang.String text) 
          Encode a RFC 822 "text" token into mail-safe form as per RFC 2047. 
static java.lang.String encodeText(java.lang.String text, java.lang.String charset, java.lang.String encoding) 
          Encode a RFC 822 "text" token into mail-safe form as per RFC 2047. 
static java.lang.String encodeWord(java.lang.String word) 
          Encode a RFC 822 "word" token into mail-safe form as per RFC 2047. 
static java.lang.String encodeWord(java.lang.String word, java.lang.String charset, java.lang.String encoding) 
          Encode a RFC 822 "word" token into mail-safe form as per RFC 2047. 
static java.lang.String getDefaultJavaCharset() 
          Get the default charset corresponding to the system's current default locale. 
static java.lang.String getEncoding(javax.activation.DataHandler dh) 
          Same as getEncoding(DataSource) except that instead of reading the data from an InputStream it uses the writeTo method to examine the data. 
static java.lang.String getEncoding(javax.activation.DataSource ds) 
          Get the content-transfer-encoding that should be applied to the input stream of this datasource, to make it mailsafe. 
static java.lang.String javaCharset(java.lang.String charset) 
          Convert a MIME charset name into a valid Java charset name. 
static java.lang.String mimeCharset(java.lang.String charset) 
          Convert a java charset into its MIME charset name. 
static java.lang.String quote(java.lang.String word, java.lang.String specials) 
          A utility method to quote a word, if the word contains any characters from the specified 'specials' list.