org.opencrx.application.mail.importer
Class SimpleMimeMessage

java.lang.Object
  extended by org.opencrx.application.mail.importer.SimpleMimeMessage

public class SimpleMimeMessage
extends Object

Helper class to provide a more simple access to the regularly used attributes of a mime message for importing emails.


Field Summary
static String DISPOSITION_INLINE
           
static String OPENCRX_MESSAGE_ID
           
static String OPENCRX_MESSAGE_IDENTITY
           
static short PRIORITY_HIGH
           
static short PRIORITY_IMMEDIATE
           
static short PRIORITY_LOW
           
static short PRIORITY_NORMAL
           
static short PRIORITY_URGENT
           
static String UNSPECIFIED_ADDRESS
           
 
Constructor Summary
SimpleMimeMessage(javax.mail.internet.MimeMessage theMessage)
          Constructor
SimpleMimeMessage(javax.mail.internet.MimeMessage theMessage, boolean initAttributes)
          Constructor If initAttributes is true, the attributes are initialized immediately by parsing the underlying MimeMessage.
 
Method Summary
 boolean containsAttachments()
          Checks whether the message contains binary attachments.
 boolean containsNestedMessage()
          Checks whether the message contains binary attachments.
 String getAllHeaderLinesAsString()
          Extracts the complete content of all header elements of a MIME message and returns them as concatenated string using the system's line separator as separator between the elements.
 Collection getBinaryContents()
          Returns a collection of the binary attachments or null if the message does not contain any.
 String getBody()
          Extracts the body part of a MIME message, currently only message bodies of the following formats are supported:
String InputStream MultiPart In case of MultiParts only parts of the mime types "text/plain" and "text/html" are currently supported.
 Collection getContents()
          Returns a collection of the attachments or null if the message does not contain any.
 Date getDate()
          Extracts date of the message it was sent and cache it locally.
 String[] getFrom()
          Extracts the sender's email address from the message and cache it locally.
 String[] getHeader(String name)
          Get all the headers for this header_name.
 String getMessageID()
          Extracts the message ID of the message and cache it locally
 String getMessageIdentity()
           
 short getPriority()
          Extract the priority from the email message.
 String[] getRecipients()
          Extracts the recipients of type Message.RecipientType.TO ("To") of the message and cache it locally.
 String[] getRecipients(javax.mail.Message.RecipientType type)
          Extracts the recipients of the given type of the message and cache it locally.
 String getSubject()
          Extracts the subject of the message and cache it locally.
 Collection getTextContents()
          Returns a collection of the text attachments or null if the message does not contain any.
 boolean hasIdentity()
          Checks whether the message contains an openCRX identity.
 void markAsDeleted()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OPENCRX_MESSAGE_ID

public static final String OPENCRX_MESSAGE_ID
See Also:
Constant Field Values

OPENCRX_MESSAGE_IDENTITY

public static final String OPENCRX_MESSAGE_IDENTITY
See Also:
Constant Field Values

UNSPECIFIED_ADDRESS

public static final String UNSPECIFIED_ADDRESS
See Also:
Constant Field Values

DISPOSITION_INLINE

public static final String DISPOSITION_INLINE
See Also:
Constant Field Values

PRIORITY_LOW

public static final short PRIORITY_LOW
See Also:
Constant Field Values

PRIORITY_NORMAL

public static final short PRIORITY_NORMAL
See Also:
Constant Field Values

PRIORITY_HIGH

public static final short PRIORITY_HIGH
See Also:
Constant Field Values

PRIORITY_URGENT

public static final short PRIORITY_URGENT
See Also:
Constant Field Values

PRIORITY_IMMEDIATE

public static final short PRIORITY_IMMEDIATE
See Also:
Constant Field Values
Constructor Detail

SimpleMimeMessage

public SimpleMimeMessage(javax.mail.internet.MimeMessage theMessage)
                  throws javax.mail.MessagingException,
                         IOException
Constructor

Parameters:
theMessage - the MimeMessage which has to be wrapped
Throws:
javax.mail.MessagingException
IOException

SimpleMimeMessage

public SimpleMimeMessage(javax.mail.internet.MimeMessage theMessage,
                         boolean initAttributes)
                  throws javax.mail.MessagingException,
                         IOException
Constructor If initAttributes is true, the attributes are initialized immediately by parsing the underlying MimeMessage. Therefore although the folder containing the MimeMessage may already be closed, this instance already holds the derived values for the attributes.

Parameters:
theMessage - the MimeMessage which has to be wrapped
initAttributes - true if the attributes should be initialized immediately, false otherwise
Throws:
javax.mail.MessagingException
IOException
Method Detail

getHeader

public String[] getHeader(String name)
                   throws javax.mail.MessagingException
Get all the headers for this header_name. Note that certain headers may be encoded as per RFC 2047 if they contain non US-ASCII characters and these should be decoded.

This implementation obtains the headers from the headers InternetHeaders object.

Parameters:
name - name of header
Returns:
array of headers
Throws:
javax.mail.MessagingException
See Also:
MimeMessage

getAllHeaderLinesAsString

public String getAllHeaderLinesAsString()
                                 throws javax.mail.MessagingException
Extracts the complete content of all header elements of a MIME message and returns them as concatenated string using the system's line separator as separator between the elements.

Returns:
the concatenated header elements of the message
Throws:
javax.mail.MessagingException

getBody

public String getBody()
               throws javax.mail.MessagingException,
                      IOException
Extracts the body part of a MIME message, currently only message bodies of the following formats are supported:
In case of MultiParts only parts of the mime types "text/plain" and "text/html" are currently supported. The body is returned in string format.

Returns:
Throws:
javax.mail.MessagingException
IOException

getMessageIdentity

public String getMessageIdentity()
                          throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException

getMessageID

public String getMessageID()
                    throws javax.mail.MessagingException
Extracts the message ID of the message and cache it locally

Returns:
the message ID of the message
Throws:
javax.mail.MessagingException

getSubject

public String getSubject()
                  throws javax.mail.MessagingException
Extracts the subject of the message and cache it locally. If the message contains several subject entries, these entries are concatenated using the system's line separator.

Returns:
the subject of the message
Throws:
javax.mail.MessagingException

getDate

public Date getDate()
             throws javax.mail.MessagingException
Extracts date of the message it was sent and cache it locally. Returns null if no date is contained in the message.

Returns:
the subject of the message
Throws:
javax.mail.MessagingException

getFrom

public String[] getFrom()
                 throws javax.mail.internet.AddressException,
                        javax.mail.MessagingException
Extracts the sender's email address from the message and cache it locally. If no address is found UNSPECIFIED_ADDRESS is used.

Returns:
the sender's email addresses
Throws:
javax.mail.internet.AddressException
javax.mail.MessagingException

getRecipients

public String[] getRecipients()
                       throws javax.mail.MessagingException
Extracts the recipients of type Message.RecipientType.TO ("To") of the message and cache it locally.

Returns:
the recipients' email addresses
Throws:
javax.mail.MessagingException

getRecipients

public String[] getRecipients(javax.mail.Message.RecipientType type)
                       throws javax.mail.MessagingException
Extracts the recipients of the given type of the message and cache it locally.

Parameters:
type - the type for which the addresses are needed, i.e. either "To", "Cc" or "Bcc"
Returns:
the recipients' email addresses
Throws:
javax.mail.MessagingException

getPriority

public short getPriority()
                  throws javax.mail.MessagingException
Extract the priority from the email message. Note that if no header element is found this indicates a "normal" priority. Note that rfc822 does not define a standard header field for priority. The name of the "priority" header field depends on your mail client used. "Importance" with values high, normal and low "Priority" with values Urgent and Non-Urgent "X-Priority" with values 1=high and 5=low These values are mapped to: respectively.

Returns:
the subject of the message
Throws:
javax.mail.MessagingException

containsAttachments

public boolean containsAttachments()
Checks whether the message contains binary attachments.

Returns:
true, if the message contains some binary attachments

containsNestedMessage

public boolean containsNestedMessage()
Checks whether the message contains binary attachments.

Returns:
true, if the message contains some binary attachments

hasIdentity

public boolean hasIdentity()
Checks whether the message contains an openCRX identity.

Returns:
true if the message contains an openCRX identity, false otherwise

getContents

public Collection getContents()
Returns a collection of the attachments or null if the message does not contain any.

Returns:
collection of the attachments or null otherwise

getTextContents

public Collection getTextContents()
Returns a collection of the text attachments or null if the message does not contain any.

Returns:
collection of the text attachments or null otherwise

getBinaryContents

public Collection getBinaryContents()
Returns a collection of the binary attachments or null if the message does not contain any.

Returns:
collection of the binary attachments or null otherwise

toString

public String toString()
Overrides:
toString in class Object

markAsDeleted

public void markAsDeleted()


This software is published under the BSD license. Copyright © 2003-2008, CRIXP AG, Switzerland, All rights reserved. Use is subject to license terms.