public final class MessageUtility
extends java.lang.Object
MessageUtility - Provides various helper methods for message processing.| Modifier and Type | Field and Description |
|---|---|
static char |
UNKNOWN
The unknown character:
'�' |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
checkCharset(MailPart p,
ContentType ct)
Gets a valid charset-encoding for specified textual part; meaning its content type matches
text/*. |
static java.lang.String |
checkCharset(javax.mail.Part p,
ContentType ct)
Gets a valid charset-encoding for specified textual part; meaning its content type matches
text/*. |
static javax.activation.DataHandler |
dhFor(javax.activation.DataSource dataSource,
javax.activation.DataContentHandler dch,
java.lang.Object object,
java.lang.String objectMimeType)
Creates a new
DataHandler with specified DataSource, DataContentHandler, object and MIME type set. |
static byte[] |
getBytesFrom(java.io.InputStream in)
Gets the byte content from specified input stream.
|
static java.io.InputStream |
getPartInputStream(javax.mail.Part p)
Gets the input stream of specified part.
|
static boolean |
isAscii(byte[] bytes)
Check if specified bytes contain ascii-only content.
|
static boolean |
isBig5(java.lang.String charset)
Checks if specified charset name can be considered as BIG5.
|
static boolean |
isGB2312(java.lang.String charset)
Checks if specified charset name can be considered as GB2312.
|
static boolean |
isShiftJis(java.lang.String charset)
Checks if specified charset name can be considered as Shift-JIS.
|
static boolean |
isSpecialCharset(java.lang.String charset)
Checks if passed character encoding experienced some special handling when reading text content.
|
static java.lang.String |
readBytes(byte[] bytes,
java.lang.String charset)
Reads a string from given input stream using direct buffering.
|
static java.lang.String |
readMailPart(MailPart mailPart,
java.lang.String charset)
Reads the stream content from given mail part.
|
static java.lang.String |
readMimePart(javax.mail.Part p,
ContentType ct)
Reads the string out of MIME part's input stream.
|
static java.lang.String |
readMimePart(javax.mail.Part p,
java.lang.String charset)
Reads the string out of MIME part's input stream.
|
static java.lang.String |
readStream(java.io.InputStream inStream,
java.lang.String charset)
Reads a string from given input stream using direct buffering.
|
static java.lang.String |
readStream(StreamDataSource.InputStreamProvider streamProvider,
java.lang.String charset)
Reads a string from given input stream using direct buffering.
|
static void |
setContent(javax.mail.Message message,
javax.mail.Part part)
Sets the message content
|
static void |
setContent(javax.mail.Multipart multipart,
javax.mail.Part part)
Sets the multipart content
|
static void |
setContent(javax.mail.Multipart multipart,
java.lang.String contentType,
javax.mail.Part part)
Sets the multipart content
|
static void |
setText(java.lang.String text,
javax.mail.Part part)
Convenience method that sets the given String as this part's content, with a primary MIME type of "text/plain; charset=us-ascii".
|
static void |
setText(java.lang.String text,
java.lang.String charset,
javax.mail.Part part)
Convenience method that sets the given String as this part's content, with a primary MIME type of "text/plain".
|
static void |
setText(java.lang.String text,
java.lang.String charset,
java.lang.String subtype,
javax.mail.Part part)
Convenience method that sets the given String as this part's content, with a primary MIME type of "text" and the specified MIME
subtype.
|
static java.lang.String |
simpleHtmlDuplicateRemoval(java.lang.String html)
Detects possible duplicate <html> tags and removes all but last.
|
public static final char UNKNOWN
'�'public static java.lang.String checkCharset(MailPart p, ContentType ct) throws com.openexchange.exception.OXException
text/*.p - The part to detect a charset forct - The part's content typecom.openexchange.exception.OXException - If part's input stream cannot be obtainedpublic static java.lang.String checkCharset(javax.mail.Part p,
ContentType ct)
text/*.p - The part to detect a charset forct - The part's content typepublic static java.io.InputStream getPartInputStream(javax.mail.Part p)
p - The part whose input stream shall be returnedpublic static java.lang.String readMimePart(javax.mail.Part p,
ContentType ct)
throws javax.mail.MessagingException
javax.mail.Part.getInputStream() is used. If an I/O error occurs (java.io.IOException) then the next try is
with part's raw input stream. If everything fails an empty string is returned.p - The javax.mail.Part objectct - The part's content typejavax.mail.MessagingException - If an error occurs in part's getter methodspublic static java.lang.String readMimePart(javax.mail.Part p,
java.lang.String charset)
throws javax.mail.MessagingException
javax.mail.Part.getInputStream() is used. If an I/O error occurs (java.io.IOException) then the next try is
with part's raw input stream. If everything fails an empty string is returned.p - The javax.mail.Part objectcharset - The charsetjavax.mail.MessagingException - If an error occurs in part's getter methodspublic static java.lang.String readMailPart(MailPart mailPart, java.lang.String charset) throws java.io.IOException, com.openexchange.exception.OXException
mailPart - The mail partcharset - The charset encoding used to generate a String object from raw bytesString read from mail part's streamjava.io.IOExceptioncom.openexchange.exception.OXExceptionpublic static java.lang.String readBytes(byte[] bytes,
java.lang.String charset)
throws java.io.IOException
bytes - The bytes to readcharset - The charsetString read from input streamjava.io.IOException - If an I/O error occurspublic static java.lang.String readStream(StreamDataSource.InputStreamProvider streamProvider, java.lang.String charset) throws java.io.IOException
streamProvider - The input stream providercharset - The charsetString read from input streamjava.io.IOException - If an I/O error occurspublic static java.lang.String readStream(java.io.InputStream inStream,
java.lang.String charset)
throws java.io.IOException
inStream - The input streamcharset - The charsetString read from input streamjava.io.IOException - If an I/O error occurspublic static boolean isSpecialCharset(java.lang.String charset)
charset - The character encoding to checktrue if passed character encoding experienced some special handling; otherwise falsepublic static boolean isBig5(java.lang.String charset)
charset - The charset name to checktrue if charset name can be considered as BIG5; otherwise falsepublic static boolean isGB2312(java.lang.String charset)
charset - The charset name to checktrue if charset name can be considered as GB2312; otherwise falsepublic static boolean isShiftJis(java.lang.String charset)
charset - The charset name to checktrue if charset name can be considered as Shift-JIS; otherwise falsepublic static byte[] getBytesFrom(java.io.InputStream in)
throws java.io.IOException
in - The input stream to get the byte content fromjava.io.IOException - If an I/O error occurspublic static boolean isAscii(byte[] bytes)
bytes - The bytes to checktrue if bytes are ascii-only; otherwise falsepublic static java.lang.String simpleHtmlDuplicateRemoval(java.lang.String html)
html - The HTML contentpublic static javax.activation.DataHandler dhFor(javax.activation.DataSource dataSource,
javax.activation.DataContentHandler dch,
java.lang.Object object,
java.lang.String objectMimeType)
throws javax.mail.MessagingException
DataHandler with specified DataSource, DataContentHandler, object and MIME type set.dataSource - The data sourcedch - The data content handler (optional; null is accepted)object - The object (optional; null is accepted)objectMimeType - The MIME type (optional; null is accepted)javax.mail.MessagingException - If creating such a data handler failpublic static void setContent(javax.mail.Message message,
javax.mail.Part part)
throws javax.mail.MessagingException
message - The message to setpart - The partjavax.mail.MessagingException - If setting content failspublic static void setContent(javax.mail.Multipart multipart,
javax.mail.Part part)
throws javax.mail.MessagingException
multipart - The multipart to setpart - The partjavax.mail.MessagingException - If setting content failspublic static void setContent(javax.mail.Multipart multipart,
java.lang.String contentType,
javax.mail.Part part)
throws javax.mail.MessagingException
multipart - The multipart to setcontentType - The content typepart - The partjavax.mail.MessagingException - If setting content failspublic static void setText(java.lang.String text,
javax.mail.Part part)
throws javax.mail.MessagingException
text - The text content to setcharset - The charset to use for the textjavax.mail.MessagingException - If an error occurspublic static void setText(java.lang.String text,
java.lang.String charset,
javax.mail.Part part)
throws javax.mail.MessagingException
The given Unicode string will be charset-encoded using the specified charset. The charset is also used to set the "charset" parameter.
text - The text content to setcharset - The charset to use for the textjavax.mail.MessagingException - If an error occurspublic static void setText(java.lang.String text,
java.lang.String charset,
java.lang.String subtype,
javax.mail.Part part)
throws javax.mail.MessagingException
The given Unicode string will be charset-encoded using the specified charset. The charset is also used to set the "charset" parameter.
text - The text content to setcharset - The charset to use for the textsubtype - The MIME subtype to use (e.g., "html")javax.mail.MessagingException - If an error occurs