com.openexchange.mail.mime.dataobjects
Class MIMEMailPart

java.lang.Object
  extended by com.openexchange.mail.dataobjects.MailPart
      extended by com.openexchange.mail.mime.dataobjects.MIMEMailPart
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public final class MIMEMailPart
extends MailPart

MIMEMailPart - Represents a MIME part as per RFC 822.

Author:
Thorben Betten
See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.openexchange.mail.dataobjects.MailPart
NO_ENCLOSED_PARTS
 
Constructor Summary
MIMEMailPart(javax.mail.Part part)
          Constructor - Only applies specified part, but does not set any attributes.
 
Method Summary
 java.lang.Object getContent()
          Returns the part's content as a Java object dependent on underlying implementation.
 javax.activation.DataHandler getDataHandler()
          Returns an appropriate DataHandler for this mail part.
 int getEnclosedCount()
          Gets the number of enclosed mail parts.
 MailPart getEnclosedMailPart(int index)
          Gets the mail part located at given index.
 java.io.InputStream getInputStream()
          Returns an input stream for this part.
 javax.mail.Part getPart()
          Gets the part.
 void loadContent()
          Ensures that the part's content is loaded, thus this part is independent of the original.
 void prepareForCaching()
          Prepares this mail part to be put into cache; meaning to release all kept resources
 void setContent(javax.mail.Part part)
          Sets this mail part's content.
 void setHandleMissingStartBoundary(boolean handleMissingStartBoundary)
          Set whether to handle "Missing start boundary" javax.mail.MessagingException.
 void writeTo(java.io.OutputStream out)
          Writes complete part's data into given output stream
 
Methods inherited from class com.openexchange.mail.dataobjects.MailPart
addHeader, addHeaders, clone, containsContentDisposition, containsContentId, containsContentType, containsFileName, containsHeader, containsHeaders, containsMsgref, containsSequenceId, containsSize, getContentDisposition, getContentId, getContentType, getFileName, getFirstHeader, getHeader, getHeader, getHeader, getHeaders, getHeadersIterator, getHeadersSize, getMatchingHeaders, getMsgref, getNonMatchingHeaders, getSequenceId, getSize, getSource, getSourceBytes, hasEnclosedParts, hasHeaders, removeContentDisposition, removeContentId, removeContentType, removeFileName, removeHeader, removeHeaders, removeMsgref, removeSequenceId, removeSize, setContentDisposition, setContentDisposition, setContentId, setContentType, setContentType, setFileName, setMsgref, setSequenceId, setSize
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MIMEMailPart

public MIMEMailPart(javax.mail.Part part)
Constructor - Only applies specified part, but does not set any attributes.

Method Detail

setHandleMissingStartBoundary

public void setHandleMissingStartBoundary(boolean handleMissingStartBoundary)
Set whether to handle "Missing start boundary" javax.mail.MessagingException.

Note: Set only to true if JavaMail property "mail.mime.multipart.allowempty" is set to "false".

Parameters:
handleMissingStartBoundary - true to handle "Missing start boundary" error; otherwise false

setContent

public void setContent(javax.mail.Part part)
Sets this mail part's content.

Parameters:
part - The part

getPart

public javax.mail.Part getPart()
Gets the part.

Returns:
The part or null

getContent

public java.lang.Object getContent()
                            throws MailException
Description copied from class: MailPart
Returns the part's content as a Java object dependent on underlying implementation.
This method is not applicable if part's MIME type is multipart/*

Specified by:
getContent in class MailPart
Returns:
The content as a Java object or null if not applicable
Throws:
MailException - If content cannot be returned as a Java object

getDataHandler

public javax.activation.DataHandler getDataHandler()
                                            throws MailException
Description copied from class: MailPart
Returns an appropriate DataHandler for this mail part.
This method is not applicable if part's MIME type is multipart/*

Specified by:
getDataHandler in class MailPart
Returns:
an appropriate DataHandler or null if not applicable
Throws:
MailException - If an appropriate DataHandler cannot be returned

getInputStream

public java.io.InputStream getInputStream()
                                   throws MailException
Description copied from class: MailPart
Returns an input stream for this part.
This method is not applicable if part's MIME type is multipart/*

Specified by:
getInputStream in class MailPart
Returns:
An input stream for this part or null if not applicable
Throws:
MailException - If no input stream could be returned

getEnclosedMailPart

public MailPart getEnclosedMailPart(int index)
                             throws MailException
Description copied from class: MailPart
Gets the mail part located at given index.
This method is only applicable if part's MIME type is multipart/*

Specified by:
getEnclosedMailPart in class MailPart
Parameters:
index - The index of desired mail part or null if not applicable
Returns:
The mail part
Throws:
MailException

getEnclosedCount

public int getEnclosedCount()
                     throws MailException
Description copied from class: MailPart
Gets the number of enclosed mail parts.
This method is only applicable if part's MIME type is multipart/*

Specified by:
getEnclosedCount in class MailPart
Returns:
The number of enclosed mail parts or MailPart.NO_ENCLOSED_PARTS if not applicable
Throws:
MailException
See Also:
MailPart.NO_ENCLOSED_PARTS

writeTo

public void writeTo(java.io.OutputStream out)
             throws MailException
Description copied from class: MailPart
Writes complete part's data into given output stream

Overrides:
writeTo in class MailPart
Parameters:
out - The output stream to write to
Throws:
MailException - If writing to output stream fails

prepareForCaching

public void prepareForCaching()
Description copied from class: MailPart
Prepares this mail part to be put into cache; meaning to release all kept resources

Specified by:
prepareForCaching in class MailPart

loadContent

public void loadContent()
                 throws MailException
Description copied from class: MailPart
Ensures that the part's content is loaded, thus this part is independent of the original.

This method is intended for mailing systems that read the contents stepwise on demand. If dealing with such a mail part with its underlying connection closed, the part's content is no more accessible. Otherwise this method may be implemented with an empty body.

Moreover the loaded content is no more discarded when MailPart.prepareForCaching() is invoked.

Specified by:
loadContent in class MailPart
Throws:
MailException - If loading part's content fails