javax.mail.internet

Class MimeUtility

public class MimeUtility extends Object

This is a utility class providing micellaneous MIME-related functionality.

Version: 1.4

Author: Chris Burdess

Field Summary
static intALL
Method Summary
static InputStreamdecode(InputStream is, String encoding)
Decodes the given input stream.
static StringdecodeText(String etext)
Decodes headers that are defined as '*text' in RFC 822.
static StringdecodeWord(String text)
Decodes the specified string using the RFC 2047 rules for parsing an "encoded-word".
static OutputStreamencode(OutputStream os, String encoding)
Encodes the given output stream.
static OutputStreamencode(OutputStream os, String encoding, String filename)
Encodes the given output stream.
static StringencodeText(String text)
Encodes an RFC 822 "text" token into mail-safe form according to RFC 2047.
static StringencodeText(String text, String charset, String encoding)
Encodes an RFC 822 "text" token into mail-safe form according to RFC 2047.
static StringencodeWord(String text)
Encodes an RFC 822 "word" token into mail-safe form according to RFC 2047.
static StringencodeWord(String text, String charset, String encoding)
Encodes an RFC 822 "word" token into mail-safe form according to RFC 2047.
static Stringfold(int used, String s)
Folds the specified string such that each line is no longer than 76 characters, whitespace permitting.
static StringgetDefaultJavaCharset()
Returns the default Java charset.
static StringgetEncoding(DataSource ds)
Returns the Content-Transfer-Encoding that should be applied to the input stream of this data source, to make it mail safe.
static StringgetEncoding(DataHandler dh)
Returns the Content-Transfer-Encoding that needs to be applied to the given content in order to make it mail safe.
static StringjavaCharset(String charset)
Converts a MIME charset name into a Java charset name.
static StringmimeCharset(String charset)
Converts a Java charset name into a MIME charset name.
static Stringquote(String text, String specials)
Quotes the specified word, if it contains any characters from the given "specials" list.
static Stringunfold(String s)
Unfolds a folded header.

Field Detail

ALL

public static final int ALL

Method Detail

decode

public static InputStream decode(InputStream is, String encoding)
Decodes the given input stream. All the encodings defined in RFC 2045 are supported here, including "base64", "quoted-printable", "7bit", "8bit", and "binary". "uuencode" is also supported.

Parameters: is the input stream encoding the encoding

Returns: the decoded input stream

decodeText

public static String decodeText(String etext)
Decodes headers that are defined as '*text' in RFC 822.

Parameters: etext the possibly encoded value

Throws: UnsupportedEncodingException if the charset conversion failed

decodeWord

public static String decodeWord(String text)
Decodes the specified string using the RFC 2047 rules for parsing an "encoded-word".

Parameters: eword the possibly encoded value

Throws: ParseException if the string is not an encoded-word UnsupportedEncodingException if the decoding failed

encode

public static OutputStream encode(OutputStream os, String encoding)
Encodes the given output stream. All the encodings defined in RFC 2045 are supported here, including "base64", "quoted-printable", "7bit", "8bit" and "binary". "uuencode" is also supported.

Parameters: os the output stream encoding the encoding

Returns: an output stream that applies the specified encoding

encode

public static OutputStream encode(OutputStream os, String encoding, String filename)
Encodes the given output stream. All the encodings defined in RFC 2045 are supported here, including "base64", "quoted-printable", "7bit", "8bit" and "binary". "uuencode" is also supported.

Parameters: os the output stream encoding the encoding filename the name for the file being encoded (this is only used with the uuencode encoding)

Returns: an output stream that applies the specified encoding

encodeText

public static String encodeText(String text)
Encodes an RFC 822 "text" token into mail-safe form according to RFC 2047.

Parameters: text the Unicode string UnsupportedEncodingException if the encoding fails

encodeText

public static String encodeText(String text, String charset, String encoding)
Encodes an RFC 822 "text" token into mail-safe form according to RFC 2047.

Parameters: text the Unicode string charset the charset, or null to use the platform default charset encoding the encoding to be used ("B" or "Q")

encodeWord

public static String encodeWord(String text)
Encodes an RFC 822 "word" token into mail-safe form according to RFC 2047.

Parameters: text the Unicode string

Throws: UnsupportedEncodingException if the encoding fails

encodeWord

public static String encodeWord(String text, String charset, String encoding)
Encodes an RFC 822 "word" token into mail-safe form according to RFC 2047.

Parameters: text the Unicode string charset the charset, or null to use the platform default charset encoding the encoding to be used ("B" or "Q")

Throws: UnsupportedEncodingException if the encoding fails

fold

public static String fold(int used, String s)
Folds the specified string such that each line is no longer than 76 characters, whitespace permitting.

Parameters: used the number of characters used in the line already s the string to fold

Since: JavaMail 1.4

getDefaultJavaCharset

public static String getDefaultJavaCharset()
Returns the default Java charset.

getEncoding

public static String getEncoding(DataSource ds)
Returns the Content-Transfer-Encoding that should be applied to the input stream of this data source, to make it mail safe.

getEncoding

public static String getEncoding(DataHandler dh)
Returns the Content-Transfer-Encoding that needs to be applied to the given content in order to make it mail safe. This is the same as the getEncoding(DataSource) method except that instead of reading the data from an input stream it uses the writeTo method to examine the data, which can be more efficient.

javaCharset

public static String javaCharset(String charset)
Converts a MIME charset name into a Java charset name.

Parameters: charset the MIME charset name

mimeCharset

public static String mimeCharset(String charset)
Converts a Java charset name into a MIME charset name.

Parameters: charset the Java charset name

quote

public static String quote(String text, String specials)
Quotes the specified word, if it contains any characters from the given "specials" list.

The HeaderTokenizer class defines two "specials" lists, MIME and RFC 822.

Parameters: word the word to be quoted specials the set of special characters

unfold

public static String unfold(String s)
Unfolds a folded header.

Parameters: s the header to unfold

Since: JavaMail 1.4

© Copyright 2003, 2004 The Free Software Foundation, All rights reserved