com.openexchange.mail.mime
Class RFC2231Tools

java.lang.Object
  extended by com.openexchange.mail.mime.RFC2231Tools

public final class RFC2231Tools
extends java.lang.Object

RFC2231Tools - A collection of RFC2231 related utility methods

Author:
Thorben Betten

Method Summary
static boolean isAscii(char c)
          Checks whether the character is ASCII 7 bit
static boolean isAscii(java.lang.String s)
          Checks whether the specified string's characters are ASCII 7 bit
static java.lang.String[] parseRFC2231Value(java.lang.String rfc2231Value)
          Parses given RFC2231 value into its charset, language and rfc2231-encoded value.
static java.lang.String rfc2231Decode(java.lang.String encoded)
          Decodes specified string according to mail-safe encoding introduced in RFC2231 This method assumes that encoding information are contained in given string; e.g.
static java.lang.String rfc2231Decode(java.lang.String encoded, java.lang.String charset)
          Decodes specified string according to mail-safe encoding introduced in RFC2231
static java.lang.String rfc2231Encode(java.lang.String toEncode, java.lang.String charset, java.lang.String language, boolean prepend)
          Encodes given string according to mechanism provided in RFC2231.
static java.lang.String rfc2231Encode(java.lang.String toEncode, java.lang.String charset, java.lang.String language, boolean prepend, boolean force)
          Encodes given string according to mechanism provided in RFC2231.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parseRFC2231Value

public static java.lang.String[] parseRFC2231Value(java.lang.String rfc2231Value)
Parses given RFC2231 value into its charset, language and rfc2231-encoded value. Therefore RFC2231 value should match pattern:
 <charset-name> + "'" + <language-code> + "'" + <encoded-data>
 

Parameters:
rfc2231Value - The rfc2231 value
Returns:
An array of String containing charset, language, and rfc2231-encoded value or null if value does not match pattern.

rfc2231Decode

public static java.lang.String rfc2231Decode(java.lang.String encoded)
Decodes specified string according to mail-safe encoding introduced in RFC2231

This method assumes that encoding information are contained in given string; e.g.

 utf-8'EN'%C2%A4%20txt
 

Parameters:
encoded - The encoded string
Returns:
The decoded string

rfc2231Decode

public static java.lang.String rfc2231Decode(java.lang.String encoded,
                                             java.lang.String charset)
Decodes specified string according to mail-safe encoding introduced in RFC2231

Parameters:
encoded - The encoded string
charset - The charset name
Returns:
The decoded string

rfc2231Encode

public static java.lang.String rfc2231Encode(java.lang.String toEncode,
                                             java.lang.String charset,
                                             java.lang.String language,
                                             boolean prepend)
Encodes given string according to mechanism provided in RFC2231.

Parameters:
toEncode - The string to encode
charset - The charset encoding
language - The language to append
prepend - true to prepend charset and language information; otherwise false
Returns:
The encoded string

rfc2231Encode

public static java.lang.String rfc2231Encode(java.lang.String toEncode,
                                             java.lang.String charset,
                                             java.lang.String language,
                                             boolean prepend,
                                             boolean force)
Encodes given string according to mechanism provided in RFC2231.

Parameters:
toEncode - The string to encode
charset - The charset encoding
language - The language to append
prepend - true to prepend charset and language information; otherwise false
force - true to force encoding even if string to encode only consists of ASCII characters; otherwise false
Returns:
The encoded string

isAscii

public static boolean isAscii(java.lang.String s)
Checks whether the specified string's characters are ASCII 7 bit

Parameters:
s - The string to check
Returns:
true if string's characters are ASCII 7 bit; otherwise false

isAscii

public static boolean isAscii(char c)
Checks whether the character is ASCII 7 bit

Parameters:
c - The character to check
Returns:
true if character is ASCII 7 bit; otherwise false