public interface ContentHandler
Receives notifications of the content of a plain RFC822 or MIME message.
Implement this interface and register an instance of that implementation
with a MimeStreamParser
instance using its
MimeStreamParser.setContentHandler(ContentHandler)
method. The parser uses the ContentHandler
instance 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.
Modifier and Type | Method and Description |
---|---|
void |
body(BodyDescriptor bd,
InputStream is)
Called when the body of a discrete (non-multipart) entity is about to
be parsed.
|
void |
endBodyPart()
Called when a body part ends.
|
void |
endHeader()
Called when there are no more header fields in a message or body part.
|
void |
endMessage()
Called when a message ends.
|
void |
endMultipart()
Called when the body of an entity has been parsed.
|
void |
epilogue(InputStream is)
Called for the epilogue (whatever comes after the final body part)
of a
multipart/* entity. |
void |
field(Field rawField)
Called for each field of a header.
|
void |
preamble(InputStream is)
Called for the preamble (whatever comes before the first body part)
of a
multipart/* entity. |
void |
raw(InputStream is)
Called when a new entity (message or body part) starts and the
parser is in
raw mode. |
void |
startBodyPart()
Called when a new body part starts inside a
multipart/* entity. |
void |
startHeader()
Called when a header (of a message or body part) is about to be parsed.
|
void |
startMessage()
Called when a new message starts (a top level message or an embedded
rfc822 message).
|
void |
startMultipart(BodyDescriptor bd)
Called when the body of a multipart entity is about to be parsed.
|
void startMessage() throws MimeException
MimeException
- on processing errorsvoid endMessage() throws MimeException
MimeException
- on processing errorsvoid startBodyPart() throws MimeException
multipart/*
entity.MimeException
- on processing errorsvoid endBodyPart() throws MimeException
MimeException
- on processing errorsvoid startHeader() throws MimeException
MimeException
- on processing errorsvoid field(Field rawField) throws MimeException
rawField
- the MIME field.MimeException
- on processing errorsvoid endHeader() throws MimeException
MimeException
- on processing errorsvoid preamble(InputStream is) throws MimeException, IOException
multipart/*
entity.is
- used to get the contents of the preamble.MimeException
- on processing errorsIOException
- should be thrown on I/O errors.void epilogue(InputStream is) throws MimeException, IOException
multipart/*
entity.is
- used to get the contents of the epilogue.MimeException
- on processing errorsIOException
- should be thrown on I/O errors.void startMultipart(BodyDescriptor bd) throws MimeException
bd
- encapsulates the values (either read from the
message stream or, if not present, determined implictly
as described in the
MIME rfc:s) of the Content-Type
and
Content-Transfer-Encoding
header fields.MimeException
- on processing errorsvoid endMultipart() throws MimeException
MimeException
- on processing errorsvoid body(BodyDescriptor bd, InputStream is) throws MimeException, IOException
bd
- see startMultipart(BodyDescriptor)
is
- the contents of the body. NOTE: this is the raw body contents
- it will not be decoded if encoded. The bd
parameter should be used to determine how the stream data
should be decoded.MimeException
- on processing errorsIOException
- should be thrown on I/O errors.void raw(InputStream is) throws MimeException, IOException
raw
mode.is
- the raw contents of the entity.MimeException
- on processing errorsIOException
- should be thrown on I/O errors.MimeStreamParser.setRaw()
Copyright © 2004-2012 The Apache Software Foundation. All Rights Reserved.