use of org.apache.james.mime4j.parser.MimeStreamParser in project k-9 by k9mail.
the class MessageHeaderParser method getMimeStreamParser.
private static MimeStreamParser getMimeStreamParser() {
MimeConfig parserConfig = new MimeConfig();
parserConfig.setMaxHeaderLen(-1);
parserConfig.setMaxLineLen(-1);
parserConfig.setMaxHeaderCount(-1);
return new MimeStreamParser(parserConfig);
}
use of org.apache.james.mime4j.parser.MimeStreamParser in project k-9 by k9mail.
the class MimePartStreamParser method parse.
public static MimeBodyPart parse(FileFactory fileFactory, InputStream inputStream) throws MessagingException, IOException {
MimeBodyPart parsedRootPart = new MimeBodyPart();
MimeConfig parserConfig = new MimeConfig();
parserConfig.setMaxHeaderLen(-1);
parserConfig.setMaxLineLen(-1);
parserConfig.setMaxHeaderCount(-1);
MimeStreamParser parser = new MimeStreamParser(parserConfig);
parser.setContentHandler(new PartBuilder(fileFactory, parsedRootPart));
parser.setRecurse();
try {
parser.parse(new EOLConvertingInputStream(inputStream));
} catch (MimeException e) {
throw new MessagingException("Failed to parse decrypted content", e);
}
return parsedRootPart;
}
use of org.apache.james.mime4j.parser.MimeStreamParser in project tika by apache.
the class RFC822Parser method parse.
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
// Get the mime4j configuration, or use a default one
MimeConfig config = new MimeConfig();
config.setMaxLineLen(100000);
// max length of any individual header
config.setMaxHeaderLen(100000);
config = context.get(MimeConfig.class, config);
MimeStreamParser parser = new MimeStreamParser(config);
XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
MailContentHandler mch = new MailContentHandler(xhtml, metadata, context, config.isStrictParsing());
parser.setContentHandler(mch);
parser.setContentDecoding(true);
TikaInputStream tstream = TikaInputStream.get(stream);
try {
parser.parse(tstream);
} catch (IOException e) {
tstream.throwIfCauseOf(e);
throw new TikaException("Failed to parse an email message", e);
} catch (MimeException e) {
// Unwrap the exception in case it was not thrown by mime4j
Throwable cause = e.getCause();
if (cause instanceof TikaException) {
throw (TikaException) cause;
} else if (cause instanceof SAXException) {
throw (SAXException) cause;
} else {
throw new TikaException("Failed to parse an email message", e);
}
}
}
use of org.apache.james.mime4j.parser.MimeStreamParser in project k-9 by k9mail.
the class MessageHeaderParser method parse.
public static void parse(final Part part, InputStream headerInputStream) throws MessagingException {
MimeStreamParser parser = getMimeStreamParser();
parser.setContentHandler(new MessageHeaderParserContentHandler(part));
try {
parser.parse(headerInputStream);
} catch (MimeException me) {
throw new MessagingException("Error parsing headers", me);
} catch (IOException e) {
throw new MessagingException("I/O error parsing headers", e);
}
}
use of org.apache.james.mime4j.parser.MimeStreamParser in project k-9 by k9mail.
the class MimeMessage method parse.
private void parse(InputStream in, boolean recurse) throws IOException, MessagingException {
mHeader.clear();
mFrom = null;
mTo = null;
mCc = null;
mBcc = null;
mReplyTo = null;
mMessageId = null;
mReferences = null;
mInReplyTo = null;
mSentDate = null;
mBody = null;
MimeConfig parserConfig = new MimeConfig();
// The default is a mere 10k
parserConfig.setMaxHeaderLen(-1);
// The default is 1000 characters. Some MUAs generate
parserConfig.setMaxLineLen(-1);
// REALLY long References: headers
// Disable the check for header count.
parserConfig.setMaxHeaderCount(-1);
MimeStreamParser parser = new MimeStreamParser(parserConfig);
parser.setContentHandler(new MimeMessageBuilder());
if (recurse) {
parser.setRecurse();
}
try {
parser.parse(new EOLConvertingInputStream(in));
} catch (MimeException me) {
throw new MessagingException(me.getMessage(), me);
}
}
Aggregations