public abstract class MailPart
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable
MailPart
- Abstract super class for all MailPart
subclasses.
It's main purpose is to provide access to common part headers and part's content.
Modifier and Type | Field and Description |
---|---|
static int |
NO_ENCLOSED_PARTS
The integer constant returned by
getEnclosedCount() if mail part's content type does not match multipart/* and
therefore does not hold any enclosed parts. |
Modifier and Type | Method and Description |
---|---|
void |
addHeader(java.lang.String name,
java.lang.String value)
Adds a header
|
void |
addHeaders(HeaderCollection headers)
Adds a header collection
|
java.lang.Object |
clone() |
boolean |
containsContentDisposition() |
boolean |
containsContentId() |
boolean |
containsContentType() |
boolean |
containsFileName() |
boolean |
containsHeader(java.lang.String name)
Checks for a header entry for specified header
|
boolean |
containsHeaders() |
boolean |
containsMsgref() |
boolean |
containsSequenceId() |
boolean |
containsSize() |
abstract java.lang.Object |
getContent()
Returns the part's content as a Java object dependent on underlying implementation.
|
ContentDisposition |
getContentDisposition()
Gets the disposition
|
java.lang.String |
getContentId()
Gets the contentId
|
ContentType |
getContentType()
Gets the content type
|
abstract javax.activation.DataHandler |
getDataHandler()
Returns an appropriate
DataHandler for this mail part. |
abstract int |
getEnclosedCount()
Gets the number of enclosed mail parts.
|
abstract MailPart |
getEnclosedMailPart(int index)
Gets the mail part located at given index.
|
java.lang.String |
getFileName()
Gets the fileName
|
java.lang.String |
getFirstHeader(java.lang.String name)
Gets the first header for specified header name.
|
java.lang.String[] |
getHeader(java.lang.String name)
Gets all the values for the specified header.
|
java.lang.String |
getHeader(java.lang.String name,
char delimiter)
Gets all the headers for this header name, returned as a single String, with headers separated by the delimiter.
|
java.lang.String |
getHeader(java.lang.String name,
java.lang.String delimiter)
Gets all the headers for this header name, returned as a single String, with headers separated by the delimiter.
|
HeaderCollection |
getHeaders()
Gets a read-only version of this part's headers
|
java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> |
getHeadersIterator()
Gets an instance of
Iterator to iterate all headers |
int |
getHeadersSize()
Gets the number of headers
|
abstract java.io.InputStream |
getInputStream()
Returns an input stream for this part.
|
java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> |
getMatchingHeaders(java.lang.String[] matchingHeaders)
Gets an iterator for matching headers
|
MailPath |
getMsgref()
Gets the message reference
|
java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> |
getNonMatchingHeaders(java.lang.String[] nonMatchingHeaders)
Gets an iterator for non-matching headers
|
java.lang.String |
getSequenceId()
Gets the sequenceId
|
long |
getSize()
Gets the size
|
java.lang.String |
getSource()
Gets the mail part's source
|
byte[] |
getSourceBytes()
Gets a newly allocated byte array containing the mail part's source bytes
|
boolean |
hasEnclosedParts()
Checks if part's MIME type is
multipart/* |
boolean |
hasHeaders(java.lang.String... names)
Checks if this part contains all of specified headers.
|
abstract void |
loadContent()
Ensures that the part's content is loaded, thus this part is independent of the original.
|
abstract void |
prepareForCaching()
Prepares this mail part to be put into cache; meaning to release all kept resources
|
void |
removeContentDisposition()
Removes the disposition
|
void |
removeContentId()
Removes the contentId
|
void |
removeContentType()
Removes the content type
|
void |
removeFileName()
Removes the fileName
|
void |
removeHeader(java.lang.String name)
Removes the header if present
|
void |
removeHeaders()
Removes the headers
|
void |
removeMsgref()
Removes the message reference
|
void |
removeSequenceId()
Removes the sequenceId
|
void |
removeSize()
Removes the size
|
void |
setContentDisposition(ContentDisposition disposition)
Sets the disposition
|
void |
setContentDisposition(java.lang.String disposition)
Sets the disposition
|
void |
setContentId(java.lang.String contentId)
Sets the contentId
|
void |
setContentType(ContentType contentType)
Sets the content type
|
void |
setContentType(java.lang.String contentType)
Parses and sets the content type
|
void |
setFileName(java.lang.String fileName)
Sets the fileName
|
void |
setHeader(java.lang.String name,
java.lang.String value)
Sets a header
|
void |
setMsgref(MailPath msgref)
Sets the message reference
|
void |
setSequenceId(java.lang.String sequenceId)
Sets the sequenceId
|
void |
setSize(long size)
Sets the size
|
void |
writeTo(java.io.OutputStream out)
Writes complete part's data into given output stream
|
public static final int NO_ENCLOSED_PARTS
getEnclosedCount()
if mail part's content type does not match multipart/*
and
therefore does not hold any enclosed parts.public ContentType getContentType()
public boolean containsContentType()
true
if content type is set; otherwise false
public void removeContentType()
public void setContentType(ContentType contentType)
contentType
- the contentType to setpublic void setContentType(java.lang.String contentType) throws com.openexchange.exception.OXException
contentType
- the content type to parsecom.openexchange.exception.OXException
- If content type is invalid or could not be parsedpublic ContentDisposition getContentDisposition()
public boolean containsContentDisposition()
true
if disposition is set; otherwise false
public void removeContentDisposition()
public void setContentDisposition(java.lang.String disposition) throws com.openexchange.exception.OXException
disposition
- the disposition to setcom.openexchange.exception.OXException
- If content disposition is invalid or could not be parsedpublic void setContentDisposition(ContentDisposition disposition)
disposition
- the disposition to setpublic java.lang.String getFileName()
public boolean containsFileName()
true
if fileName is set; otherwise false
public void removeFileName()
public void setFileName(java.lang.String fileName)
fileName
- the fileName to setpublic void addHeader(java.lang.String name, java.lang.String value)
name
- The header namevalue
- The header valuepublic void setHeader(java.lang.String name, java.lang.String value)
name
- The header namevalue
- The header valuepublic void addHeaders(HeaderCollection headers)
headers
- The header collectionpublic boolean containsHeaders()
true
if headers is set; otherwise false
public void removeHeaders()
public int getHeadersSize()
public java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> getHeadersIterator()
Iterator
to iterate all headersIterator
to iterate all headersgetHeadersSize()
public boolean containsHeader(java.lang.String name)
name
- The header nametrue
if a header entry exists for specified header; otherwise false
public java.lang.String[] getHeader(java.lang.String name)
name
- The header namenull
public java.lang.String getFirstHeader(java.lang.String name)
This is a convenience method that invokes getHeader(String, String)
with the latter parameter set to null
.
name
- The header namenull
public java.lang.String getHeader(java.lang.String name, java.lang.String delimiter)
null
, only the first header is returned. Returns null if no headers with the specified name exist.name
- The header namedelimiter
- The delimiternull
public java.lang.String getHeader(java.lang.String name, char delimiter)
'\0'
, only the first header is returned. Returns null if no headers with the specified name exist.name
- The header namedelimiter
- The delimiter characternull
public HeaderCollection getHeaders()
public java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> getNonMatchingHeaders(java.lang.String[] nonMatchingHeaders)
nonMatchingHeaders
- The non-matching headerspublic java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> getMatchingHeaders(java.lang.String[] matchingHeaders)
matchingHeaders
- The matching headersnull
if not existspublic void removeHeader(java.lang.String name)
name
- The header namepublic boolean hasHeaders(java.lang.String... names)
names
- The names of the headers to checktrue
if this part contains all of specified headers; otherwise false
public long getSize()
public boolean containsSize()
true
if size is set; otherwise false
public void removeSize()
public void setSize(long size)
size
- the size to setpublic java.lang.String getContentId()
public boolean containsContentId()
true
if contentId is set; otherwise false
public void removeContentId()
public void setContentId(java.lang.String contentId)
contentId
- the contentId to setpublic java.lang.String getSequenceId()
public boolean containsSequenceId()
true
if sequenceId is set; otherwise false
public void removeSequenceId()
public void setSequenceId(java.lang.String sequenceId)
sequenceId
- the sequenceId to setpublic MailPath getMsgref()
public boolean containsMsgref()
true
if message reference is set; otherwise false
public void removeMsgref()
public void setMsgref(MailPath msgref)
msgref
- the message reference to setpublic java.lang.Object clone()
clone
in class java.lang.Object
public boolean hasEnclosedParts() throws com.openexchange.exception.OXException
multipart/*
true
if part holds enclosed parts; otherwise false
com.openexchange.exception.OXException
- If check failspublic abstract java.lang.Object getContent() throws com.openexchange.exception.OXException
multipart/*
null
if not applicablecom.openexchange.exception.OXException
- If content cannot be returned as a Java objectpublic abstract javax.activation.DataHandler getDataHandler() throws com.openexchange.exception.OXException
DataHandler
for this mail part. multipart/*
DataHandler
or null
if not applicablecom.openexchange.exception.OXException
- If an appropriate DataHandler
cannot be returnedpublic abstract java.io.InputStream getInputStream() throws com.openexchange.exception.OXException
multipart/*
null
if not applicablecom.openexchange.exception.OXException
- If no input stream could be returnedpublic abstract int getEnclosedCount() throws com.openexchange.exception.OXException
multipart/*
NO_ENCLOSED_PARTS
if not applicablecom.openexchange.exception.OXException
NO_ENCLOSED_PARTS
public abstract MailPart getEnclosedMailPart(int index) throws com.openexchange.exception.OXException
multipart/*
index
- The index of desired mail part or null
if not applicablecom.openexchange.exception.OXException
public abstract void loadContent() throws com.openexchange.exception.OXException
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 prepareForCaching()
is invoked.
com.openexchange.exception.OXException
- If loading part's content failspublic void writeTo(java.io.OutputStream out) throws com.openexchange.exception.OXException
out
- The output stream to write tocom.openexchange.exception.OXException
- If writing to output stream failspublic java.lang.String getSource() throws com.openexchange.exception.OXException
com.openexchange.exception.OXException
- If mail part's source cannot be returnedpublic byte[] getSourceBytes() throws com.openexchange.exception.OXException
com.openexchange.exception.OXException
- If mail part's source cannot be returnedpublic abstract void prepareForCaching()