Search in sources :

Example 6 with DefaultMessageBuilder

use of org.apache.james.mime4j.message.DefaultMessageBuilder in project sling by apache.

the class MessageStoreImplRepositoryTest method assertSaveMessage.

private void assertSaveMessage(String messageFile) throws MimeException, IOException, FileNotFoundException {
    MessageBuilder builder = new DefaultMessageBuilder();
    Message msg = builder.parseMessage(new FileInputStream(new File(TU.TEST_FOLDER, messageFile)));
    store.save(msg);
    final Resource r = resolver.getResource(getResourcePath(msg, store));
    assertNotNull("Expecting non-null Resource", r);
    final ModifiableValueMap m = r.adaptTo(ModifiableValueMap.class);
    File bodyFile = new File(TU.TEST_FOLDER, specialPathFromFilePath(messageFile, BODY_SUFFIX));
    if (bodyFile.exists()) {
        String expectedBody = readTextFile(bodyFile);
        assertValueMap(m, "Body", expectedBody);
    }
    File headersFile = new File(TU.TEST_FOLDER, specialPathFromFilePath(messageFile, HEADERS_SUFFIX));
    if (headersFile.exists()) {
        MessageStoreImplRepositoryTestUtil.assertHeaders(headersFile, m);
    }
    // test at least something 
    assertTrue(headersFile.exists() || bodyFile.exists());
}
Also used : MessageBuilder(org.apache.james.mime4j.dom.MessageBuilder) DefaultMessageBuilder(org.apache.james.mime4j.message.DefaultMessageBuilder) Message(org.apache.james.mime4j.dom.Message) DefaultMessageBuilder(org.apache.james.mime4j.message.DefaultMessageBuilder) Resource(org.apache.sling.api.resource.Resource) MessageStoreImplRepositoryTestUtil.readTextFile(org.apache.sling.mailarchiveserver.impl.MessageStoreImplRepositoryTestUtil.readTextFile) File(java.io.File) FileInputStream(java.io.FileInputStream) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap)

Aggregations

Message (org.apache.james.mime4j.dom.Message)6 MessageBuilder (org.apache.james.mime4j.dom.MessageBuilder)6 DefaultMessageBuilder (org.apache.james.mime4j.message.DefaultMessageBuilder)6 Entity (org.apache.james.mime4j.dom.Entity)5 TextBody (org.apache.james.mime4j.dom.TextBody)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 MimeException (org.apache.james.mime4j.MimeException)4 BinaryBody (org.apache.james.mime4j.dom.BinaryBody)3 Body (org.apache.james.mime4j.dom.Body)3 Strings (com.google.common.base.Strings)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 CharStreams (com.google.common.io.CharStreams)2 Ints (com.google.common.primitives.Ints)2 InputStreamReader (java.io.InputStreamReader)2 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)2 Multipart (org.apache.james.mime4j.dom.Multipart)2 Mailbox (org.apache.james.mime4j.dom.address.Mailbox)2 StringBuilder (scala.collection.mutable.StringBuilder)2