List of usage examples for org.apache.poi.hsmf MAPIMessage MAPIMessage
public MAPIMessage(DirectoryNode poifsDir) throws IOException
From source file:org.exoplatform.services.document.impl.MSOutlookDocumentReader.java
License:Open Source License
public String getContentAsText(InputStream is) throws IOException, DocumentReadException { if (is == null) { throw new IllegalArgumentException("InputStream is null."); }/* www .ja v a2 s . co m*/ try { if (is.available() == 0) { return ""; } MAPIMessage message; try { message = new MAPIMessage(is); } catch (IOException e) { throw new DocumentReadException("Can't open message.", e); } StringBuilder builder = new StringBuilder(); try { builder.append(message.getDisplayFrom()).append('\n'); } catch (ChunkNotFoundException e) { // "from" is empty if (LOG.isTraceEnabled()) { LOG.trace("An exception occurred: " + e.getMessage()); } } try { builder.append(message.getDisplayTo()).append('\n'); } catch (ChunkNotFoundException e) { // "to" is empty if (LOG.isTraceEnabled()) { LOG.trace("An exception occurred: " + e.getMessage()); } } try { builder.append(message.getSubject()).append('\n'); } catch (ChunkNotFoundException e) { // "subject" is empty if (LOG.isTraceEnabled()) { LOG.trace("An exception occurred: " + e.getMessage()); } } try { builder.append(message.getTextBody()); } catch (ChunkNotFoundException e) { // "textBody" is empty if (LOG.isTraceEnabled()) { LOG.trace("An exception occurred: " + e.getMessage()); } } return builder.toString(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { if (LOG.isTraceEnabled()) { LOG.trace("An exception occurred: " + e.getMessage()); } } } } }
From source file:org.silverpeas.core.mail.extractor.MSGExtractor.java
License:Open Source License
public MSGExtractor(File file) throws ExtractorException { try {//www .j av a2 s . co m message = new MAPIMessage(file.getPath()); } catch (IOException e) { throw new ExtractorException(e); } message.setReturnNullOnMissingChunk(true); }
From source file:org.silverpeas.core.mail.extractor.MSGExtractor.java
License:Open Source License
private void init(InputStream file) throws ExtractorException { try {//from www.j a v a 2 s. c o m message = new MAPIMessage(file); } catch (IOException e) { throw new ExtractorException(e); } message.setReturnNullOnMissingChunk(true); }
From source file:org.silverpeas.core.mail.MsgMailExtractorIntegrationTest.java
License:Open Source License
/** * This unit test is support for MSG exploration solution testing. * * @throws Exception//from w w w. j ava2 s.c om */ @Test public void readMailWithAttachmentsMSG() throws Exception { MAPIMessage msg = new MAPIMessage(getDocumentFromName(FILENAME_MAIL_WITH_ATTACHMENTS).getPath()); msg.setReturnNullOnMissingChunk(true); assertThat(msg.getDisplayFrom(), is("Nicolas Eysseric")); assertThat(msg.getRecipientDetailsChunks(), is(notNullValue())); assertThat(msg.getRecipientDetailsChunks().length, is(2)); assertThat(msg.getRecipientDetailsChunks()[0].getRecipientName(), is("Aurore ADR. DELISSNYDER")); assertThat(msg.getRecipientDetailsChunks()[0].getRecipientEmailAddress(), is("Aurore.DELISSNYDER@hydrostadium.fr")); assertThat(msg.getRecipientDetailsChunks()[1].getRecipientName(), is("Ludovic BERTIN")); assertThat(msg.getRecipientDetailsChunks()[1].getRecipientEmailAddress(), is("ludovic.bertin@oosphere.com")); AttachmentChunks[] attachments = msg.getAttachmentFiles(); assertThat(attachments, is(notNullValue())); assertThat(attachments.length, is(2)); if (attachments != null && attachments.length > 0) { System.out.print("\n"); for (AttachmentChunks attachmentChunks : attachments) { System.out.println(attachmentChunks.attachFileName.getValue()); } } else { System.out.println("None."); } System.out.println("DATE : " + DateUtil.getOutputDateAndHour(getMessageDate(msg), "fr")); System.out.println("BODY : "); System.out.println(">>>"); System.out.println(getMessageBody(msg)); System.out.println("<<<"); }
From source file:org.silverpeas.core.mail.MsgMailExtractorIT.java
License:Open Source License
/** * This unit test is support for MSG exploration solution testing. * * @throws Exception//from w w w . jav a2s. co m */ @Test public void readMailWithAttachmentsMSG() throws Exception { MAPIMessage msg = new MAPIMessage(getDocumentFromName(FILENAME_MAIL_WITH_ATTACHMENTS).getPath()); msg.setReturnNullOnMissingChunk(true); assertThat(msg.getDisplayFrom(), is("Nicolas Eysseric")); assertThat(msg.getRecipientDetailsChunks(), is(notNullValue())); assertThat(msg.getRecipientDetailsChunks().length, is(2)); assertThat(msg.getRecipientDetailsChunks()[0].getRecipientName(), is("Aurore ADR. DELISSNYDER")); assertThat(msg.getRecipientDetailsChunks()[0].getRecipientEmailAddress(), is("Aurore.DELISSNYDER@hydrostadium.fr")); assertThat(msg.getRecipientDetailsChunks()[1].getRecipientName(), is("Ludovic BERTIN")); assertThat(msg.getRecipientDetailsChunks()[1].getRecipientEmailAddress(), is("ludovic.bertin@oosphere.com")); AttachmentChunks[] attachments = msg.getAttachmentFiles(); assertThat(attachments, is(notNullValue())); assertThat(attachments.length, is(2)); if (attachments != null && attachments.length > 0) { System.out.print("\n"); for (AttachmentChunks attachmentChunks : attachments) { System.out.println(attachmentChunks.getAttachFileName().getValue()); } } else { System.out.println("None."); } System.out.println("DATE : " + DateUtil.getOutputDateAndHour(getMessageDate(msg), "fr")); System.out.println("BODY : "); System.out.println(">>>"); System.out.println(getMessageBody(msg)); System.out.println("<<<"); }
From source file:org.silverpeas.util.mail.MSGExtractor.java
License:Open Source License
public MSGExtractor(File file) throws ExtractorException { try {/*from w w w.j ava2 s . c om*/ message = new MAPIMessage(file.getPath()); } catch (IOException e) { throw new ExtractorException("MSGExtractor.constructor", SilverpeasException.ERROR, "", e); } message.setReturnNullOnMissingChunk(true); }
From source file:org.silverpeas.util.mail.MSGExtractor.java
License:Open Source License
private void init(InputStream file) throws ExtractorException { try {//from w ww . j av a 2 s . c om message = new MAPIMessage(file); } catch (IOException e) { throw new ExtractorException("MSGExtractor.init", SilverpeasException.ERROR, "", e); } message.setReturnNullOnMissingChunk(true); }