javax.mail.internet
Class MimeUtility

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

public class MimeUtility
extends Object

Version:
$Rev: 421852 $ $Date: 2006-07-14 03:02:19 -0700 (Fri, 14 Jul 2006) $

Field Summary
static int ALL
           
 
Method Summary
static InputStream decode(InputStream in, String encoding)
           
static String decodeText(String text)
          Decode a string of text obtained from a mail header into it's proper form.
static String decodeWord(String word)
          Parse a string using the RFC 2047 rules for an "encoded-word" type.
static OutputStream encode(OutputStream out, String encoding)
          Wrap an encoder around a given output stream.
static OutputStream encode(OutputStream out, String encoding, String filename)
          Wrap an encoder around a given output stream.
static String encodeText(String word)
           
static String encodeText(String word, String charset, String encoding)
           
static String encodeWord(String word)
           
static String encodeWord(String word, String charset, String encoding)
           
static String fold(int used, String s)
          Perform RFC 2047 text folding on a string of text.
static String getDefaultJavaCharset()
          Get the default character set to use, in Java name format.
static String getEncoding(DataHandler handler)
          Examine the content of a data source and decide what type of transfer encoding should be used.
static String getEncoding(DataSource source)
          Determine the what transfer encoding should be used for data retrieved from a DataSource.
static String javaCharset(String charset)
          Translate a MIME standard character set name into the Java equivalent.
static String mimeCharset(String charset)
          Map a Java character set name into the MIME equivalent.
static String quote(String word, String specials)
          Quote a "word" value.
static String unfold(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 InputStream decode(InputStream in,
                                 String encoding)
                          throws MessagingException
Throws:
MessagingException

decodeText

public static String decodeText(String text)
                         throws 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:
UnsupportedEncodingException

decodeWord

public static String decodeWord(String word)
                         throws ParseException,
                                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
UnsupportedEncodingException

encode

public static OutputStream encode(OutputStream out,
                                  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 OutputStream encode(OutputStream out,
                                  String encoding,
                                  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 String encodeText(String word)
                         throws UnsupportedEncodingException
Throws:
UnsupportedEncodingException

encodeText

public static String encodeText(String word,
                                String charset,
                                String encoding)
                         throws UnsupportedEncodingException
Throws:
UnsupportedEncodingException

encodeWord

public static String encodeWord(String word)
                         throws UnsupportedEncodingException
Throws:
UnsupportedEncodingException

encodeWord

public static String encodeWord(String word,
                                String charset,
                                String encoding)
                         throws UnsupportedEncodingException
Throws:
UnsupportedEncodingException

getEncoding

public static String getEncoding(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 String getEncoding(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 String quote(String word,
                           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 String javaCharset(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 String mimeCharset(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 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 String fold(int used,
                          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 String unfold(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 © 2006 Apache Software Foundation. All Rights Reserved.