|
Oracle® Globalization Development Kit Java API Reference 10g Release 2 (10.2) Part No. B14224-01 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--oracle.i18n.net.MimeUtility
The MimeUtility
contains encoder and decoder information for MIME header and body text. This is an alternative to the javax.mail.internet.MimeUtility
class, but MimeUtillity
allows you to use Oracle or IANA character set names.
RFC 2047 specifies the MIME-safe header and body format. The mail header must be in the following US-ASCII character set encoding:
=? <charset> ? <encoding> ? <encoded-text> ?=
This output can be generated using the encodeHeader(String, String, String)
method. The receiver of the data is able to decode the data based on the included character set (for example, iso-8859-1
) and encoding ("B"
or "Q"
) information using decodeHeader(String)
.
Method Summary | |
static String |
decodeHeader(String instr) Decodes a MIME-safe form into a String object for MIME header as per RFC 2047. |
static String |
decodeText(String intext) Decode "unstructured" headers, that is, headers that are defined as '*text' as per RFC 822. |
static String |
decodeText(String intext, String charset) Decode "unstructured" headers, that is, headers that are defined as '*text' as per RFC 822. |
static String |
decodeWord(String eword) The string is parsed using the rules in RFC 2047 for parsing an "encoded-word". |
static String |
decodeWord(String eword, String charset) Same as decodeWord(String), except that the specified charset is used and the one declared in the string is ignored. |
static String |
encodeHeader(String srcstr, String charset, String encoding) Encodes a String object into a MIME-safe form for MIME header as per RFC 2047. |
static String |
encodeText(String text) Encode a RFC 822 "text" token into mail-safe form as per RFC 2047. |
static String |
encodeText(String text, String charset, String encoding) Encode a RFC 822 "text" token into mail-safe form as per RFC 2047. |
static String |
encodeWord(String word) Encode a RFC 822 "word" token into mail-safe form as per RFC 2047. |
static String |
encodeWord(String word, String charset, String encoding) Encode a RFC 822 "word" token into mail-safe form as per RFC 2047. |
static String |
getDefaultJavaCharset() Get the default charset corresponding to the system's current default locale. |
static String |
javaCharset(String charset) Convert a MIME charset name into a valid Java encoding name. |
static String |
mimeCharset(String encoding) Convert a java encoding into its MIME charset name. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static String encodeHeader(String srcstr, String charset, String encoding) throws UnsupportedEncodingException
String
object into a MIME-safe form for MIME header as per RFC 2047.
Currently, AL16UTF16 (also known as UTF-16BE) is not supported.
The output includes the character set and encoding (for example, base64 or quoted-printable) information in the following form:
=? <charset> ? <encoding> ? <encoded-text> ?=
srcstr
- a String
object to be encodedcharset
- an Oracle or IANA character set nameencoding
- base64 ("B") or quoted-printable ("Q")String
objectUnsupportedEncodingException
- if the character set name is invalid or not supportedpublic static String decodeHeader(String instr) throws UnsupportedEncodingException
String
object for MIME header as per RFC 2047.
The input is expected to include the character set and encoding (for example, base64 or quoted-printable) information in the following form:
=? <charset> ? <encoding> ? <encoded-text> ?=
String
objectUnsupportedEncodingException
- - if the character set name is invalid or not supportedpublic static String mimeCharset(String encoding)
encoding
- a Java encodingpublic static String javaCharset(String charset)
charset
- the MIME charset namepublic static String getDefaultJavaCharset()
mail.mime.charset
is set, a system charset corresponding to this MIME charset will be returned.public static String decodeWord(String eword, String charset) throws UnsupportedEncodingException
eword
- the possibly encoded valuecharset
- MIME charset nameParseException
- if the string is not an encoded-word as per RFC 2047.UnsupportedEncodingException
- if the charset conversion failed.public static String decodeWord(String eword) throws UnsupportedEncodingException
eword
- the possibly encoded valueParseException
- if the string is not an encoded-word as per RFC 2047.UnsupportedEncodingException
- if the charset conversion failed.public static String encodeText(String text) throws UnsupportedEncodingException
The given Unicode string is examined for non US-ASCII characters. If the string contains only US-ASCII characters, it is returned as-is. If the string contains non US-ASCII characters, it is first character-encoded using the platform's default charset, then transfer-encoded using either the B or Q encoding. The resulting bytes are then returned as a Unicode string containing only ASCII characters.
Note that this method should be used to encode only "unstructured" RFC 822 headers.
Example of usage:
MimePart part = ... String rawvalue = "FooBar Mailer, Japanese version 1.1" try { // If we know for sure that rawvalue contains only US-ASCII // characters, we can skip the encoding part part.setHeader("X-mailer", MimeUtility.encodeText(rawvalue)); } catch (UnsupportedEncodingException e) { // encoding failure } catch (MessagingException me) { // setHeader() failure }
text
- Unicode stringUnsupportedEncodingException
- if the encoding failspublic static String encodeText(String text, String charset, String encoding) throws UnsupportedEncodingException
The given Unicode string is examined for non US-ASCII characters. If the string contains only US-ASCII characters, it is returned as-is. If the string contains non US-ASCII characters, it is first character-encoded using the specified charset, then transfer-encoded using either the B or Q encoding. The resulting bytes are then returned as a Unicode string containing only ASCII characters.
Note that this method should be used to encode only "unstructured" RFC 822 headers.
text
- the header valuecharset
- the charset. If this parameter is null, the platform's default chatset is used.encoding
- the encoding to be used. Currently supported values are "B" and "Q". If this parameter is null, then the "Q" encoding is used if most of characters to be encoded are in the ASCII charset, otherwise "B" encoding is used.UnsupportedEncodingException
public static String decodeText(String intext) throws UnsupportedEncodingException
The string is decoded using the algorithm specified in RFC 2047, Section 6.1.1. If the charset-conversion fails for any sequence, an UnsupportedEncodingException is thrown. If the String is not an RFC 2047 style encoded header, it is returned as-is
Example of usage:
MimePart part = ... String rawvalue = null; String value = null; try { if ((rawvalue = part.getHeader("X-mailer")[0]) != null) value = MimeUtility.decodeText(rawvalue); } catch (UnsupportedEncodingException e) { // Don't care value = rawvalue; } catch (MessagingException me) { } return value;
UnsupportedEncodingException
- if the charset conversion failed.public static String decodeText(String intext, String charset) throws UnsupportedEncodingException
The string is decoded using the algorithm specified in RFC 2047, Section 6.1.1. If the charset-conversion fails for any sequence, an UnsupportedEncodingException is thrown. If the String is not an RFC 2047 style encoded header, it is returned as-is
Example of usage:
MimePart part = ... String rawvalue = null; String value = null; try { if ((rawvalue = part.getHeader("X-mailer")[0]) != null) value = MimeUtility.decodeText(rawvalue); } catch (UnsupportedEncodingException e) { // Don't care value = rawvalue; } catch (MessagingException me) { } return value;
UnsupportedEncodingException
- if the charset conversion failed.public static String encodeWord(String word) throws UnsupportedEncodingException
The given Unicode string is examined for non US-ASCII characters. If the string contains only US-ASCII characters, it is returned as-is. If the string contains non US-ASCII characters, it is first character-encoded using the platform's default charset, then transfer-encoded using either the B or Q encoding. The resulting bytes are then returned as a Unicode string containing only ASCII characters.
This method is meant to be used when creating RFC 822 "phrases". The InternetAddress class, for example, uses this to encode it's 'phrase' component.
word
- Unicode stringUnsupportedEncodingException
- if the encoding failspublic static String encodeWord(String word, String charset, String encoding) throws UnsupportedEncodingException
The given Unicode string is examined for non US-ASCII characters. If the string contains only US-ASCII characters, it is returned as-is. If the string contains non US-ASCII characters, it is first character-encoded using the specified charset, then transfer-encoded using either the B or Q encoding. The resulting bytes are then returned as a Unicode string containing only ASCII characters.
word
- Unicode stringcharset
- the MIME charsetencoding
- the encoding to be used. Currently supported values are "B" and "Q". If this parameter is null, then the "Q" encoding is used if most of characters to be encoded are in the ASCII charset, otherwise "B" encoding is used.UnsupportedEncodingException
- if the encoding fails
|
Oracle® Globalization Development Kit Java API Reference 10g Release 2 (10.2) Part No. B14224-01 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |