org.apache.james.mime4j.parser.MimeStreamParser Java Examples
The following examples show how to use
org.apache.james.mime4j.parser.MimeStreamParser.
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 |
/** * 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: MimeUtilsTest.java From holdmail with Apache License 2.0 | 6 votes |
@Test public void shouldFindAllBodyPartsOnParse() throws Exception { MessageContent expectedParts = mock(MessageContent.class); whenNew(MimeStreamParser.class).withAnyArguments().thenReturn(mimeStreamParserMock); whenNew(MessageContentExtractor.class).withNoArguments().thenReturn(messageContentExtractorMock); when(messageContentExtractorMock.getParts()).thenReturn(expectedParts); MessageContent actualParts = MimeUtils.parseMessageContent(inputStreamMock); InOrder inOrder = inOrder(mimeStreamParserMock); inOrder.verify(mimeStreamParserMock).setContentDecoding(true); inOrder.verify(mimeStreamParserMock).setContentHandler(messageContentExtractorMock); inOrder.verify(mimeStreamParserMock).parse(inputStreamMock); assertThat(actualParts).isEqualTo(expectedParts); }
Example #3
Source File: MailListExtractor.java From SnowGraph with Apache License 2.0 | 6 votes |
public void run(GraphDatabaseService db) { this.db = db; MboxHandler myHandler = new MboxHandler(); myHandler.setDb(db); MimeConfig config=new MimeConfig(); config.setMaxLineLen(-1); parser = new MimeStreamParser(config); parser.setContentHandler(myHandler); parse(new File(mboxPath)); try (Transaction tx = db.beginTx()) { for (String address : myHandler.getMailUserNameMap().keySet()) { Node node = myHandler.getMailUserMap().get(address); node.setProperty(MAILUSER_NAMES, String.join(", ", myHandler.getMailUserNameMap().get(address))); } tx.success(); } try (Transaction tx = db.beginTx()) { for (String mailId : myHandler.getMailReplyMap().keySet()) { Node mailNode = myHandler.getMailMap().get(mailId); Node replyNode = myHandler.getMailMap().get(myHandler.getMailReplyMap().get(mailId)); if (mailNode != null & replyNode != null) mailNode.createRelationshipTo(replyNode, RelationshipType.withName(MailListExtractor.MAIL_IN_REPLY_TO)); } tx.success(); } }
Example #4
Source File: EmailParseManager.java From email-mime-parser with Apache License 2.0 | 5 votes |
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 #5
Source File: ParserTest.java From email-mime-parser with Apache License 2.0 | 5 votes |
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 #6
Source File: EmailVerificationTest.java From email-mime-parser with Apache License 2.0 | 4 votes |
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); }