View | Details | Raw Unified | Return to bug 54021
Collapse All | Expand All

(-)src/scratchpad/testcases/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java (-1 / +39 lines)
Lines 30-35 Link Here
30
30
31
import org.apache.poi.POIDataSamples;
31
import org.apache.poi.POIDataSamples;
32
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
32
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
33
import org.apache.poi.hsmf.datatypes.DirectoryChunk;
33
import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
34
import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
34
35
35
/**
36
/**
Lines 36-41 Link Here
36
 * Tests to verify that we can read attachments from msg file
37
 * Tests to verify that we can read attachments from msg file
37
 */
38
 */
38
public class TestFileWithAttachmentsRead {
39
public class TestFileWithAttachmentsRead {
40
    private static final POIDataSamples samples = POIDataSamples.getHSMFInstance();
39
    private static MAPIMessage twoSimpleAttachments;
41
    private static MAPIMessage twoSimpleAttachments;
40
    private static MAPIMessage pdfMsgAttachments;
42
    private static MAPIMessage pdfMsgAttachments;
41
    private static MAPIMessage inlineImgMsgAttachments;
43
    private static MAPIMessage inlineImgMsgAttachments;
Lines 47-53 Link Here
47
     */
49
     */
48
    @BeforeClass
50
    @BeforeClass
49
    public static void setUp() throws IOException {
51
    public static void setUp() throws IOException {
50
        POIDataSamples samples = POIDataSamples.getHSMFInstance();
51
        twoSimpleAttachments = new MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg"));
52
        twoSimpleAttachments = new MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg"));
52
        pdfMsgAttachments = new MAPIMessage(samples.openResourceAsStream("attachment_msg_pdf.msg"));
53
        pdfMsgAttachments = new MAPIMessage(samples.openResourceAsStream("attachment_msg_pdf.msg"));
53
        inlineImgMsgAttachments = new MAPIMessage(samples.openResourceAsStream("attachment_msg_inlineImg.msg"));
54
        inlineImgMsgAttachments = new MAPIMessage(samples.openResourceAsStream("attachment_msg_inlineImg.msg"));
Lines 178-181 Link Here
178
        assertEquals("Nick Booth", nested.getRecipientNames());
179
        assertEquals("Nick Booth", nested.getRecipientNames());
179
        assertEquals("Test Attachment", nested.getConversationTopic());
180
        assertEquals("Test Attachment", nested.getConversationTopic());
180
    }
181
    }
182
183
    @Test
184
    public void test54021_read_text_body() throws Exception {
185
        MAPIMessage msg = new MAPIMessage(samples.openResourceAsStream("54021.msg"));
186
187
        for (AttachmentChunks attachment : msg.getAttachmentFiles()) {
188
            DirectoryChunk chunkDirectory = attachment.getAttachmentDirectory();
189
            if (chunkDirectory == null) continue;
190
            MAPIMessage attachmentMSG = chunkDirectory.getAsEmbededMessage();
191
192
            // The message body is saved either as plain text, html, or rtf
193
            int bodyCount = 0;
194
            String body;
195
            try {
196
                body = attachmentMSG.getTextBody();
197
                assertNotNull(body);
198
                assertTrue(body.length() > 0);
199
                bodyCount++;
200
            } catch (ChunkNotFoundException e) { }
201
            try {
202
                body = attachmentMSG.getHtmlBody();
203
                assertNotNull(body);
204
                assertTrue(body.length() > 0);
205
                bodyCount++;
206
            } catch (ChunkNotFoundException e) { }
207
            try {
208
                body = attachmentMSG.getRtfBody();
209
                assertNotNull(body);
210
                assertTrue(body.length() > 0);
211
                bodyCount++;
212
            } catch (ChunkNotFoundException e) { }
213
            
214
            assertEquals("expected exactly 1 text, html, or rtf body for message " + attachmentMSG.getSubject(), 1, bodyCount);
215
        }
216
217
        msg.close();
218
    }
181
}
219
}

Return to bug 54021