Search in sources :

Example 16 with MAPIMessage

use of org.apache.poi.hsmf.MAPIMessage in project poi by apache.

the class TestOutlookTextExtractor method testSimple.

@Test
public void testSimple() throws Exception {
    NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("simple_test_msg.msg"), true);
    MAPIMessage msg = new MAPIMessage(poifs);
    OutlookTextExtactor ext = new OutlookTextExtactor(msg);
    String text = ext.getText();
    assertContains(text, "From: Travis Ferguson\n");
    assertContains(text, "To: travis@overwrittenstack.com\n");
    assertNotContained(text, "CC:");
    assertNotContained(text, "BCC:");
    assertContains(text, "Subject: test message\n");
    assertContains(text, "Date: Fri, 6 Jul 2007 05:27:17 +0000\n");
    assertContains(text, "This is a test message.");
    ext.close();
    poifs.close();
}
Also used : MAPIMessage(org.apache.poi.hsmf.MAPIMessage) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) Test(org.junit.Test)

Example 17 with MAPIMessage

use of org.apache.poi.hsmf.MAPIMessage in project poi by apache.

the class TestOutlookTextExtractor method testReceivedWithMultipleRecipients.

/**
    * Test that we correctly handle multiple To+CC
    *  recipients in an email we received.
    */
@Test
public void testReceivedWithMultipleRecipients() throws Exception {
    // To: 'Ashutosh Dandavate' <ashutosh.dandavate@alfresco.com>,
    //   'Paul Holmes-Higgin' <paul.hh@alfresco.com>,
    //   'Mike Farman' <mikef@alfresco.com>
    // Cc: nickb@alfresco.com, nick.burch@alfresco.com,
    //   'Roy Wetherall' <roy.wetherall@alfresco.com>
    // (No BCC shown) 
    String[] files = new String[] { "example_received_regular.msg", "example_received_unicode.msg" };
    for (String file : files) {
        NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile(file), true);
        MAPIMessage msg = new MAPIMessage(poifs);
        OutlookTextExtactor ext = new OutlookTextExtactor(msg);
        String text = ext.getText();
        assertContains(text, "From: Mike Farman\n");
        assertContains(text, "To: 'Ashutosh Dandavate' <ashutosh.dandavate@alfresco.com>; " + "'Paul Holmes-Higgin' <paul.hh@alfresco.com>; 'Mike Farman' <mikef@alfresco.com>\n");
        assertContains(text, "CC: nickb@alfresco.com; " + "nick.burch@alfresco.com; 'Roy Wetherall' <roy.wetherall@alfresco.com>\n");
        assertNotContained(text, "BCC:");
        assertContains(text, "Subject: This is a test message please ignore\n");
        // Exact times differ slightly
        assertContains(text, "Date: Mon, 11 Jan 2010 16:2");
        assertContains(text, "The quick brown fox jumps over the lazy dog");
        ext.close();
        poifs.close();
    }
}
Also used : MAPIMessage(org.apache.poi.hsmf.MAPIMessage) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) Test(org.junit.Test)

Example 18 with MAPIMessage

use of org.apache.poi.hsmf.MAPIMessage in project poi by apache.

the class TestOutlookTextExtractor method testSentWithMulipleRecipients.

/**
    * Test that we correctly handle multiple To+CC+BCC
    *  recipients in an email we sent.
    */
@Test
public void testSentWithMulipleRecipients() throws Exception {
    // To: 'Ashutosh Dandavate' <ashutosh.dandavate@alfresco.com>,
    //   'Paul Holmes-Higgin' <paul.hh@alfresco.com>,
    //   'Mike Farman' <mikef@alfresco.com>
    // Cc: nickb@alfresco.com, nick.burch@alfresco.com,
    //   'Roy Wetherall' <roy.wetherall@alfresco.com>
    // Bcc: 'David Caruana' <dave.caruana@alfresco.com>,
    //   'Vonka Jan' <roy.wetherall@alfresco.com>
    String[] files = new String[] { "example_sent_regular.msg", "example_sent_unicode.msg" };
    for (String file : files) {
        NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile(file), true);
        MAPIMessage msg = new MAPIMessage(poifs);
        OutlookTextExtactor ext = new OutlookTextExtactor(msg);
        String text = ext.getText();
        assertContains(text, "From: Mike Farman\n");
        assertContains(text, "To: 'Ashutosh Dandavate' <ashutosh.dandavate@alfresco.com>; " + "'Paul Holmes-Higgin' <paul.hh@alfresco.com>; 'Mike Farman' <mikef@alfresco.com>\n");
        assertContains(text, "CC: 'nickb@alfresco.com' <nickb@alfresco.com>; " + "'nick.burch@alfresco.com' <nick.burch@alfresco.com>; 'Roy Wetherall' <roy.wetherall@alfresco.com>\n");
        assertContains(text, "BCC: 'David Caruana' <dave.caruana@alfresco.com>; " + "'Vonka Jan' <jan.vonka@alfresco.com>\n");
        assertContains(text, "Subject: This is a test message please ignore\n");
        assertContains(text, "Date:");
        assertContains(text, "The quick brown fox jumps over the lazy dog");
        ext.close();
        poifs.close();
    }
}
Also used : MAPIMessage(org.apache.poi.hsmf.MAPIMessage) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) Test(org.junit.Test)

Example 19 with MAPIMessage

use of org.apache.poi.hsmf.MAPIMessage in project poi by apache.

the class TestOutlookTextExtractor method testWithAttachments.

/**
    * See also {@link org.apache.poi.extractor.TestExtractorFactory#testEmbeded()}
    */
public void testWithAttachments() throws Exception {
    NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("attachment_test_msg.msg"), true);
    MAPIMessage msg = new MAPIMessage(poifs);
    OutlookTextExtactor ext = new OutlookTextExtactor(msg);
    // Check the normal bits
    String text = ext.getText();
    assertContains(text, "From: Nicolas1");
    assertContains(text, "To: 'nicolas1.23456@free.fr'");
    assertNotContained(text, "CC:");
    assertNotContained(text, "BCC:");
    assertContains(text, "Subject: test");
    assertContains(text, "Date: Wed, 22 Apr");
    assertContains(text, "Attachment: test-unicode.doc\n");
    assertContains(text, "Attachment: pj1.txt\n");
    assertContains(text, "contenu");
    // Embeded bits are checked in
    //  TestExtractorFactory
    ext.close();
    poifs.close();
}
Also used : MAPIMessage(org.apache.poi.hsmf.MAPIMessage) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem)

Aggregations

MAPIMessage (org.apache.poi.hsmf.MAPIMessage)19 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)14 Test (org.junit.Test)11 AttachmentChunks (org.apache.poi.hsmf.datatypes.AttachmentChunks)9 ChunkGroup (org.apache.poi.hsmf.datatypes.ChunkGroup)4 Chunks (org.apache.poi.hsmf.datatypes.Chunks)4 NameIdChunks (org.apache.poi.hsmf.datatypes.NameIdChunks)4 RecipientChunks (org.apache.poi.hsmf.datatypes.RecipientChunks)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Calendar (java.util.Calendar)2 StringChunk (org.apache.poi.hsmf.datatypes.StringChunk)2 ChunkNotFoundException (org.apache.poi.hsmf.exceptions.ChunkNotFoundException)2 OutlookTextExtactor (org.apache.poi.hsmf.extractor.OutlookTextExtactor)2 WordExtractor (org.apache.poi.hwpf.extractor.WordExtractor)2 DirectoryEntry (org.apache.poi.poifs.filesystem.DirectoryEntry)2 Entry (org.apache.poi.poifs.filesystem.Entry)2 FileInputStream (java.io.FileInputStream)1