public class MimeUtility
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
ALL |
Modifier and Type | Method and Description |
---|---|
static java.io.InputStream |
decode(java.io.InputStream is,
java.lang.String encoding)
Decodes the given input stream.
|
static java.lang.String |
decodeText(java.lang.String etext)
Decodes headers that are defined as '*text' in RFC 822.
|
static java.lang.String |
decodeWord(java.lang.String text)
Decodes the specified string using the RFC 2047 rules for parsing an
"encoded-word".
|
static java.io.OutputStream |
encode(java.io.OutputStream os,
java.lang.String encoding)
Encodes the given output stream.
|
static java.io.OutputStream |
encode(java.io.OutputStream os,
java.lang.String encoding,
java.lang.String filename)
Encodes the given output stream.
|
static java.lang.String |
encodeText(java.lang.String text)
Encodes an RFC 822 "text" token into mail-safe form according to
RFC 2047.
|
static java.lang.String |
encodeText(java.lang.String text,
java.lang.String charset,
java.lang.String encoding)
Encodes an RFC 822 "text" token into mail-safe form according to
RFC 2047.
|
static java.lang.String |
encodeWord(java.lang.String text)
Encodes an RFC 822 "word" token into mail-safe form according to
RFC 2047.
|
static java.lang.String |
encodeWord(java.lang.String text,
java.lang.String charset,
java.lang.String encoding)
Encodes an RFC 822 "word" token into mail-safe form according to
RFC 2047.
|
static java.lang.String |
fold(int used,
java.lang.String s)
Folds the specified string such that each line is no longer than 76
characters, whitespace permitting.
|
static java.lang.String |
getDefaultJavaCharset()
Returns the default Java charset.
|
static java.lang.String |
getEncoding(javax.activation.DataHandler dh)
Returns the Content-Transfer-Encoding that needs to be applied to the
given content in order to make it mail safe.
|
static java.lang.String |
getEncoding(javax.activation.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 java.lang.String |
javaCharset(java.lang.String charset)
Converts a MIME charset name into a Java charset name.
|
static java.lang.String |
mimeCharset(java.lang.String charset)
Converts a Java charset name into a MIME charset name.
|
static java.lang.String |
quote(java.lang.String text,
java.lang.String specials)
Quotes the specified word, if it contains any characters from the
given "specials" list.
|
static java.lang.String |
unfold(java.lang.String s)
Unfolds a folded header.
|
public static final int ALL
public static java.lang.String getEncoding(javax.activation.DataSource ds)
ds
- the data sourcepublic static java.lang.String getEncoding(javax.activation.DataHandler dh)
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.public static java.io.InputStream decode(java.io.InputStream is, java.lang.String encoding) throws MessagingException
is
- the input streamencoding
- the encodingMessagingException
public static java.io.OutputStream encode(java.io.OutputStream os, java.lang.String encoding) throws MessagingException
os
- the output streamencoding
- the encodingMessagingException
public static java.io.OutputStream encode(java.io.OutputStream os, java.lang.String encoding, java.lang.String filename) throws MessagingException
os
- the output streamencoding
- the encodingfilename
- the name for the file being encoded (this is only used
with the uuencode encoding)MessagingException
public static java.lang.String encodeText(java.lang.String text) throws java.io.UnsupportedEncodingException
text
- the Unicode stringUnsupportedEncodingException
- if the encoding failsjava.io.UnsupportedEncodingException
public static java.lang.String encodeText(java.lang.String text, java.lang.String charset, java.lang.String encoding) throws java.io.UnsupportedEncodingException
text
- the Unicode stringcharset
- the charset, or null to use the platform default charsetencoding
- the encoding to be used ("B" or "Q")java.io.UnsupportedEncodingException
public static java.lang.String decodeText(java.lang.String etext) throws java.io.UnsupportedEncodingException
etext
- the possibly encoded valuejava.io.UnsupportedEncodingException
- if the charset conversion failedpublic static java.lang.String encodeWord(java.lang.String text) throws java.io.UnsupportedEncodingException
text
- the Unicode stringjava.io.UnsupportedEncodingException
- if the encoding failspublic static java.lang.String encodeWord(java.lang.String text, java.lang.String charset, java.lang.String encoding) throws java.io.UnsupportedEncodingException
text
- the Unicode stringcharset
- the charset, or null to use the platform default charsetencoding
- the encoding to be used ("B" or "Q")java.io.UnsupportedEncodingException
- if the encoding failspublic static java.lang.String decodeWord(java.lang.String text) throws ParseException, java.io.UnsupportedEncodingException
eword
- the possibly encoded valueParseException
- if the string is not an encoded-wordjava.io.UnsupportedEncodingException
- if the decoding failedpublic static java.lang.String quote(java.lang.String text, java.lang.String specials)
The HeaderTokenizer class defines two "specials" lists, MIME and RFC 822.
word
- the word to be quotedspecials
- the set of special characterspublic static java.lang.String javaCharset(java.lang.String charset)
charset
- the MIME charset namepublic static java.lang.String mimeCharset(java.lang.String charset)
charset
- the Java charset namepublic static java.lang.String getDefaultJavaCharset()
public static java.lang.String fold(int used, java.lang.String s)
used
- the number of characters used in the line alreadys
- the string to foldpublic static java.lang.String unfold(java.lang.String s)
s
- the header to unfold