javax.mail.internet
Class MimeUtility

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

public class MimeUtility
extends java.lang.Object

Version:
$Rev: 467553 $ $Date: 2006-10-25 06:01:51 +0200 (Wed, 25 Oct 2006) $

Field Summary
static int ALL
           
 
Method Summary
static java.io.InputStream decode(java.io.InputStream in, java.lang.String encoding)
           
static java.lang.String decodeText(java.lang.String text)
          Decode a string of text obtained from a mail header into it's proper form.
static java.lang.String decodeWord(java.lang.String word)
          Parse a string using the RFC 2047 rules for an "encoded-word" type.
static java.io.OutputStream encode(java.io.OutputStream out, java.lang.String encoding)
          Wrap an encoder around a given output stream.
static java.io.OutputStream encode(java.io.OutputStream out, java.lang.String encoding, java.lang.String filename)
          Wrap an encoder around a given output stream.
static java.lang.String encodeText(java.lang.String word)
           
static java.lang.String encodeText(java.lang.String word, java.lang.String charset, java.lang.String encoding)
           
static java.lang.String encodeWord(java.lang.String word)
           
static java.lang.String encodeWord(java.lang.String word, java.lang.String charset, java.lang.String encoding)
           
static java.lang.String fold(int used, java.lang.String s)
          Perform RFC 2047 text folding on a string of text.
static java.lang.String getDefaultJavaCharset()
          Get the default character set to use, in Java name format.
static java.lang.String getEncoding(javax.activation.DataHandler handler)
          Examine the content of a data source and decide what type of transfer encoding should be used.
static java.lang.String getEncoding(javax.activation.DataSource source)
          Determine the what transfer encoding should be used for data retrieved from a DataSource.
static java.lang.String javaCharset(java.lang.String charset)
          Translate a MIME standard character set name into the Java equivalent.
static java.lang.String mimeCharset(java.lang.String charset)
          Map a Java character set name into the MIME equivalent.
static java.lang.String quote(java.lang.String word, java.lang.String specials)
          Quote a "word" value.
static java.lang.String unfold(java.lang.String s)
          Unfold a folded string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALL

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

decode

public static java.io.InputStream decode(java.io.InputStream in,
                                         java.lang.String encoding)
                                  throws MessagingException
Throws:
MessagingException

decodeText

public static java.lang.String decodeText(java.lang.String text)
                                   throws java.io.UnsupportedEncodingException
Decode a string of text obtained from a mail header into it's proper form. The text generally will consist of a string of tokens, some of which may be encoded using base64 encoding.

Parameters:
text - The text to decode.
Returns:
The decoded test string.
Throws:
java.io.UnsupportedEncodingException

decodeWord

public static java.lang.String decodeWord(java.lang.String word)
                                   throws ParseException,
                                          java.io.UnsupportedEncodingException
Parse a string using the RFC 2047 rules for an "encoded-word" type. This encoding has the syntax: encoded-word = "=?" charset "?" encoding "?" encoded-text "?="

Parameters:
word - The possibly encoded word value.
Returns:
The decoded word.
Throws:
ParseException
java.io.UnsupportedEncodingException

encode

public static java.io.OutputStream encode(java.io.OutputStream out,
                                          java.lang.String encoding)
                                   throws MessagingException
Wrap an encoder around a given output stream.

Parameters:
out - The output stream to wrap.
encoding - The name of the encoding.
Returns:
A instance of FilterOutputStream that manages on the fly encoding for the requested encoding type.
Throws:
MessagingException

encode

public static java.io.OutputStream encode(java.io.OutputStream out,
                                          java.lang.String encoding,
                                          java.lang.String filename)
                                   throws MessagingException
Wrap an encoder around a given output stream.

Parameters:
out - The output stream to wrap.
encoding - The name of the encoding.
filename - The filename of the data being sent (only used for UUEncode).
Returns:
A instance of FilterOutputStream that manages on the fly encoding for the requested encoding type.
Throws:
MessagingException

encodeText

public static java.lang.String encodeText(java.lang.String word)
                                   throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

encodeText

public static java.lang.String encodeText(java.lang.String word,
                                          java.lang.String charset,
                                          java.lang.String encoding)
                                   throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

encodeWord

public static java.lang.String encodeWord(java.lang.String word)
                                   throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

encodeWord

public static java.lang.String encodeWord(java.lang.String word,
                                          java.lang.String charset,
                                          java.lang.String encoding)
                                   throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

getEncoding

public static java.lang.String getEncoding(javax.activation.DataHandler handler)
Examine the content of a data source and decide what type of transfer encoding should be used. For text streams, we'll decided between 7bit, quoted-printable, and base64. For binary content types, we'll use either 7bit or base64.

Parameters:
handler - The DataHandler associated with the content.
Returns:
The string name of an encoding used to transfer the content.

getEncoding

public static java.lang.String getEncoding(javax.activation.DataSource source)
Determine the what transfer encoding should be used for data retrieved from a DataSource.

Parameters:
source - The DataSource for the transmitted data.
Returns:
The string name of the encoding form that should be used for the data.

quote

public static java.lang.String quote(java.lang.String word,
                                     java.lang.String specials)
Quote a "word" value. If the word contains any character from the specified "specials" list, this value is returned as a quoted strong. Otherwise, it is returned unchanged (an "atom").

Parameters:
word - The word requiring quoting.
specials - The set of special characters that can't appear in an unquoted string.
Returns:
The quoted value. This will be unchanged if the word doesn't contain any of the designated special characters.

javaCharset

public static java.lang.String javaCharset(java.lang.String charset)
Translate a MIME standard character set name into the Java equivalent.

Parameters:
charset - The MIME standard name.
Returns:
The Java equivalent for this name.

mimeCharset

public static java.lang.String mimeCharset(java.lang.String charset)
Map a Java character set name into the MIME equivalent.

Parameters:
charset - The java character set name.
Returns:
The MIME standard equivalent for this character set name.

getDefaultJavaCharset

public static java.lang.String getDefaultJavaCharset()
Get the default character set to use, in Java name format. This either be the value set with the mail.mime.charset system property or obtained from the file.encoding system property. If neither of these is set, we fall back to 8859_1 (basically US-ASCII).

Returns:
The character string value of the default character set.

fold

public static java.lang.String fold(int used,
                                    java.lang.String s)
Perform RFC 2047 text folding on a string of text.

Parameters:
used - The amount of text already "used up" on this line. This is typically the length of a message header that this text get getting added to.
s - The text to fold.
Returns:
The input text, with linebreaks inserted at appropriate fold points.

unfold

public static java.lang.String unfold(java.lang.String s)
Unfold a folded string. The unfolding process will remove any line breaks that are not escaped and which are also followed by whitespace characters.

Parameters:
s - The folded string.
Returns:
A new string with unfolding rules applied.


Copyright © 2009. All Rights Reserved.