com.openexchange.mail.utils
Class MessageUtility

java.lang.Object
  extended by com.openexchange.mail.utils.MessageUtility

public final class MessageUtility
extends java.lang.Object

MessageUtility - Provides various helper methods for message processing.

Author:
Thorben Betten

Method Summary
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 java.io.InputStream getPartInputStream(javax.mail.Part p)
          Gets the input stream of specified part.
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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

checkCharset

public static java.lang.String checkCharset(MailPart p,
                                            ContentType ct)
                                     throws MailException
Gets a valid charset-encoding for specified textual part; meaning its content type matches text/*.

Parameters:
p - The part to detect a charset for
ct - The part's content type
Returns:
A valid charset-encoding for specified textual part.
Throws:
MailException - If part's input stream cannot be obtained

checkCharset

public 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/*.

Parameters:
p - The part to detect a charset for
ct - The part's content type
Returns:
A valid charset-encoding for specified textual part.

getPartInputStream

public static java.io.InputStream getPartInputStream(javax.mail.Part p)
Gets the input stream of specified part.

Parameters:
p - The part whose input stream shall be returned
Returns:
The part's input stream.

readMimePart

public static java.lang.String readMimePart(javax.mail.Part p,
                                            ContentType ct)
                                     throws javax.mail.MessagingException
Reads the string out of MIME part's input stream. On first try the input stream retrieved by 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.

Parameters:
p - The javax.mail.Part object
ct - The part's content type
Returns:
The string read from part's input stream or the empty string "" if everything failed
Throws:
javax.mail.MessagingException - If an error occurs in part's getter methods

readMimePart

public static java.lang.String readMimePart(javax.mail.Part p,
                                            java.lang.String charset)
                                     throws javax.mail.MessagingException
Reads the string out of MIME part's input stream. On first try the input stream retrieved by 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.

Parameters:
p - The javax.mail.Part object
charset - The charset
Returns:
The string read from part's input stream or the empty string "" if everything failed
Throws:
javax.mail.MessagingException - If an error occurs in part's getter methods

readMailPart

public static java.lang.String readMailPart(MailPart mailPart,
                                            java.lang.String charset)
                                     throws java.io.IOException,
                                            MailException
Reads the stream content from given mail part.

Parameters:
mailPart - The mail part
charset - The charset encoding used to generate a String object from raw bytes
Returns:
the String read from mail part's stream
Throws:
java.io.IOException
MailException

readStream

public static java.lang.String readStream(java.io.InputStream inStream,
                                          java.lang.String charset)
                                   throws java.io.IOException
Reads a string from given input stream using direct buffering.

Parameters:
inStream - The input stream
charset - The charset
Returns:
The String read from input stream
Throws:
java.io.IOException - If an I/O error occurs