Class MimeStreamParser
java.lang.Object
org.apache.james.mime4j.parser.MimeStreamParser
Parses MIME (or RFC822) message streams of bytes or characters and reports
parsing events to a ContentHandler instance.
Typical usage:
ContentHandler handler = new MyHandler();
MimeConfig config = new MimeConfig();
MimeStreamParser parser = new MimeStreamParser(config);
parser.setContentHandler(handler);
InputStream instream = new FileInputStream("mime.msg");
try {
parser.parse(instream);
} finally {
instream.close();
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate ContentHandlerprivate final MimeTokenStream -
Constructor Summary
ConstructorsConstructorDescriptionMimeStreamParser(MimeConfig config) MimeStreamParser(MimeConfig config, DecodeMonitor monitor, BodyDescriptorBuilder bodyDescBuilder) MimeStreamParser(MimeTokenStream tokenStream) -
Method Summary
Modifier and TypeMethodDescriptionbooleanDetermines whether this parser automatically decodes body content based on the on the MIME fields with the standard defaults.booleanisRaw()Determines if this parser is currently in raw mode.voidparse(InputStream instream) Parses a stream of bytes containing a MIME message.voidsetContentDecoding(boolean b) Defines whether parser should automatically decode body content based on the on the MIME fields with the standard defaults.voidSets theContentHandlerto use when reporting parsing events.voidsetFlat()Enables flat mode.voidDisables recursive mode.voidsetRaw()Enables raw mode.voidEnables recursive mode.voidstop()Finishes the parsing and stops reading lines.
-
Field Details
-
handler
-
contentDecoding
private boolean contentDecoding -
mimeTokenStream
-
-
Constructor Details
-
MimeStreamParser
-
MimeStreamParser
public MimeStreamParser(MimeConfig config, DecodeMonitor monitor, BodyDescriptorBuilder bodyDescBuilder) -
MimeStreamParser
-
MimeStreamParser
public MimeStreamParser()
-
-
Method Details
-
isContentDecoding
public boolean isContentDecoding()Determines whether this parser automatically decodes body content based on the on the MIME fields with the standard defaults. -
setContentDecoding
public void setContentDecoding(boolean b) Defines whether parser should automatically decode body content based on the on the MIME fields with the standard defaults. -
parse
Parses a stream of bytes containing a MIME message. Please note that if theMimeConfigassociated with the mime stream returns a not null Content-Type value from itsMimeConfig.getHeadlessParsing()method, the message is assumed to have no head section and the headless parsing mode will be used.- Parameters:
instream- the stream to parse.- Throws:
MimeException- if the message can not be processedIOException- on I/O errors.
-
isRaw
public boolean isRaw()Determines if this parser is currently in raw mode.- Returns:
trueif in raw mode,falseotherwise.- See Also:
-
setRaw
public void setRaw()Enables raw mode. In raw mode all future entities (messages or body parts) in the stream will be reported to theContentHandler.raw(InputStream)handler method only. The stream will contain the entire unparsed entity contents including header fields and whatever is in the body. -
setFlat
public void setFlat()Enables flat mode. In flat mode rfc822 parts are not recursively parsed and multipart content is handled as a single "simple" stream. -
setRecurse
public void setRecurse()Enables recursive mode. In this mode rfc822 parts are recursively parsed. -
setNoRecurse
public void setNoRecurse()Disables recursive mode. In this mode rfc822 parts are not recursively parsed. -
stop
public void stop()Finishes the parsing and stops reading lines. NOTE: No more lines will be parsed but the parser will still callContentHandler.endMultipart(),ContentHandler.endBodyPart(),ContentHandler.endMessage(), etc to match previous calls toContentHandler.startMultipart(BodyDescriptor),ContentHandler.startBodyPart(),ContentHandler.startMessage(), etc. -
setContentHandler
Sets theContentHandlerto use when reporting parsing events.- Parameters:
h- theContentHandler.
-