Interface ContentHandler
-
- All Known Implementing Classes:
AbstractContentHandler,ParserStreamContentHandler,SimpleContentHandler
public interface ContentHandlerReceives notifications of the content of a plain RFC822 or MIME message. Implement this interface and register an instance of that implementation with a
MimeStreamParserinstance using itsMimeStreamParser.setContentHandler(ContentHandler)method. The parser uses theContentHandlerinstance to report basic message-related events like the start and end of the body of a part in a multipart MIME entity.Throwing an exception from an event method will terminate the message processing, i.e. no new events will be generated for that message.
Events will be generated in the order the corresponding elements occur in the message stream parsed by the parser. E.g.:
startMessage() startHeader() field(...) field(...) ... endHeader() startMultipart() preamble(...) startBodyPart() startHeader() field(...) field(...) ... endHeader() body() endBodyPart() startBodyPart() startHeader() field(...) field(...) ... endHeader() body() endBodyPart() epilogue(...) endMultipart() endMessage()The above shows an example of a MIME message consisting of a multipart body containing two body parts.
See MIME RFCs 2045-2049 for more information on the structure of MIME messages and RFC 822 and 2822 for the general structure of Internet mail messages.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidbody(BodyDescriptor bd, java.io.InputStream is)Called when the body of a discrete (non-multipart) entity is about to be parsed.voidendBodyPart()Called when a body part ends.voidendHeader()Called when there are no more header fields in a message or body part.voidendMessage()Called when a message ends.voidendMultipart()Called when the body of an entity has been parsed.voidepilogue(java.io.InputStream is)Called for the epilogue (whatever comes after the final body part) of amultipart/*entity.voidfield(Field rawField)Called for each field of a header.voidpreamble(java.io.InputStream is)Called for the preamble (whatever comes before the first body part) of amultipart/*entity.voidraw(java.io.InputStream is)Called when a new entity (message or body part) starts and the parser is inrawmode.voidstartBodyPart()Called when a new body part starts inside amultipart/*entity.voidstartHeader()Called when a header (of a message or body part) is about to be parsed.voidstartMessage()Called when a new message starts (a top level message or an embedded rfc822 message).voidstartMultipart(BodyDescriptor bd)Called when the body of a multipart entity is about to be parsed.
-
-
-
Method Detail
-
startMessage
void startMessage() throws MimeExceptionCalled when a new message starts (a top level message or an embedded rfc822 message).- Throws:
MimeException- on processing errors
-
endMessage
void endMessage() throws MimeExceptionCalled when a message ends.- Throws:
MimeException- on processing errors
-
startBodyPart
void startBodyPart() throws MimeExceptionCalled when a new body part starts inside amultipart/*entity.- Throws:
MimeException- on processing errors
-
endBodyPart
void endBodyPart() throws MimeExceptionCalled when a body part ends.- Throws:
MimeException- on processing errors
-
startHeader
void startHeader() throws MimeExceptionCalled when a header (of a message or body part) is about to be parsed.- Throws:
MimeException- on processing errors
-
field
void field(Field rawField) throws MimeException
Called for each field of a header.- Parameters:
rawField- the MIME field.- Throws:
MimeException- on processing errors
-
endHeader
void endHeader() throws MimeExceptionCalled when there are no more header fields in a message or body part.- Throws:
MimeException- on processing errors
-
preamble
void preamble(java.io.InputStream is) throws MimeException, java.io.IOExceptionCalled for the preamble (whatever comes before the first body part) of amultipart/*entity.- Parameters:
is- used to get the contents of the preamble.- Throws:
MimeException- on processing errorsjava.io.IOException- should be thrown on I/O errors.
-
epilogue
void epilogue(java.io.InputStream is) throws MimeException, java.io.IOExceptionCalled for the epilogue (whatever comes after the final body part) of amultipart/*entity.- Parameters:
is- used to get the contents of the epilogue.- Throws:
MimeException- on processing errorsjava.io.IOException- should be thrown on I/O errors.
-
startMultipart
void startMultipart(BodyDescriptor bd) throws MimeException
Called when the body of a multipart entity is about to be parsed.- Parameters:
bd- encapsulates the values (either read from the message stream or, if not present, determined implictly as described in the MIME rfc:s) of theContent-TypeandContent-Transfer-Encodingheader fields.- Throws:
MimeException- on processing errors
-
endMultipart
void endMultipart() throws MimeExceptionCalled when the body of an entity has been parsed.- Throws:
MimeException- on processing errors
-
body
void body(BodyDescriptor bd, java.io.InputStream is) throws MimeException, java.io.IOException
Called when the body of a discrete (non-multipart) entity is about to be parsed.- Parameters:
bd- seestartMultipart(BodyDescriptor)is- the contents of the body. NOTE: this is the raw body contents - it will not be decoded if encoded. Thebdparameter should be used to determine how the stream data should be decoded.- Throws:
MimeException- on processing errorsjava.io.IOException- should be thrown on I/O errors.
-
raw
void raw(java.io.InputStream is) throws MimeException, java.io.IOException
Called when a new entity (message or body part) starts and the parser is inrawmode.- Parameters:
is- the raw contents of the entity.- Throws:
MimeException- on processing errorsjava.io.IOException- should be thrown on I/O errors.- See Also:
MimeStreamParser.setRaw()
-
-