Java Code Examples for org.apache.james.mime4j.parser.MimeStreamParser#setContentDecoding()

The following examples show how to use org.apache.james.mime4j.parser.MimeStreamParser#setContentDecoding() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MimeUtils.java    From holdmail with Apache License 2.0 6 votes vote down vote up
/**
 * Parse the provided inputstream into the message domain
 * @param rawContentStream The inputstream to the message RAW content
 * @return A {@link MessageContent} object representing the parsed content, or
 *          a {@link HoldMailException} if parsing failed.
 */
public static MessageContent parseMessageContent(final InputStream rawContentStream) {

    try {
        MessageContentExtractor bodyPartExtractor = new MessageContentExtractor();

        MimeStreamParser parser = new MimeStreamParser();
        parser.setContentDecoding(true);
        parser.setContentHandler(bodyPartExtractor);
        parser.parse(rawContentStream);
        return bodyPartExtractor.getParts();
    } catch (MimeException | IOException e) {
        throw new HoldMailException("Failed to parse body", e);
    }

}
 
Example 2
Source File: EmailParseManager.java    From email-mime-parser with Apache License 2.0 5 votes vote down vote up
public Email getParsedEmail() throws MimeException, IOException {
	
	MimeConfig mime4jParserConfig = MimeConfig.DEFAULT;
	BodyDescriptorBuilder bodyDescriptorBuilder = new DefaultBodyDescriptorBuilder();
	MimeStreamParser mime4jParser = new MimeStreamParser(mime4jParserConfig,DecodeMonitor.SILENT,bodyDescriptorBuilder);
	mime4jParser.setContentDecoding(true);
	mime4jParser.setContentHandler(contentHandler);		
	
	mime4jParser.parse(rawEmailFile);
	
	return ((CustomContentHandler)contentHandler).getEmail();
}
 
Example 3
Source File: ParserTest.java    From email-mime-parser with Apache License 2.0 5 votes vote down vote up
private void parseEmail(String messageFileName, ContentHandler contentHandler) throws FileNotFoundException,
		MimeException, IOException {

	MimeConfig mime4jParserConfig = MimeConfig.DEFAULT;
	BodyDescriptorBuilder bodyDescriptorBuilder = new DefaultBodyDescriptorBuilder();		
	MimeStreamParser mime4jParser = new MimeStreamParser(mime4jParserConfig,DecodeMonitor.SILENT,bodyDescriptorBuilder);
	mime4jParser.setContentDecoding(true);
	mime4jParser.setContentHandler(contentHandler);
	
	URL url = this.getClass().getClassLoader().getResource(messageFileName);
	
	InputStream mailIn = new FileInputStream(new File(url.getFile()));
	mime4jParser.parse(mailIn);
	
}
 
Example 4
Source File: EmailVerificationTest.java    From email-mime-parser with Apache License 2.0 4 votes vote down vote up
private void parseEmail(String messageFileName,
                        ContentHandler contentHandler) throws
        MimeException, IOException {

    MimeConfig mime4jParserConfig = MimeConfig.DEFAULT;

    BodyDescriptorBuilder bodyDescriptorBuilder = new DefaultBodyDescriptorBuilder();
    MimeStreamParser mime4jParser = new MimeStreamParser(mime4jParserConfig, DecodeMonitor.SILENT, bodyDescriptorBuilder);

    mime4jParser.setContentDecoding(true);
    mime4jParser.setContentHandler(contentHandler);

    URL url = this.getClass().getClassLoader().getResource(messageFileName);

    InputStream mailIn = new FileInputStream(new File(url.getFile()));
    mime4jParser.parse(mailIn);

}