Search in sources :

Example 96 with MimeBodyPart

use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.

the class MIMETestUtils method createLargeDataSource.

private static final MimeBodyPart createLargeDataSource() {
    try {
        //Large body. Something bigger then the size of the boundary with folded headers.
        final String body = "Has at possim tritani laoreet, vis te meis verear. Vel no vero quando oblique, eu blandit placerat nec, vide facilisi recusabo nec te. Veri labitur sensibus eum id. Quo omnis " + "putant erroribus ad, nonumes copiosae percipit in qui, id cibo meis clita pri. An brute mundi quaerendum duo, eu aliquip facilisis sea, eruditi invidunt dissentiunt eos ea.";
        final MimeBodyPart dataPart = new MimeBodyPart();
        final ContentType contentType = new ContentType(TEXT_PLAIN_CONTENT_TYPE);
        dataPart.setContent(body, contentType.getBaseType());
        //Modify the content type header to use folding. We will also use multiple headers that use folding to verify
        //the integrity of the reader. Note that the Content-Type header uses parameters which are key/value pairs
        //separated by '='. Note that we do not use two consecutive CRLFs anywhere since our implementation
        //does not support this.
        final StringBuffer contentTypeBuffer = new StringBuffer(contentType.toString());
        contentTypeBuffer.append(";\r\n\t\t\t");
        contentTypeBuffer.append("parameter1= value1");
        contentTypeBuffer.append(";\r\n   \t");
        contentTypeBuffer.append("parameter2= value2");
        //This is a custom header which is folded. It does not use parameters so it's values are separated by commas.
        final StringBuffer customHeaderBuffer = new StringBuffer();
        customHeaderBuffer.append("CustomValue1");
        customHeaderBuffer.append(",\r\n\t  \t");
        customHeaderBuffer.append("CustomValue2");
        customHeaderBuffer.append(",\r\n ");
        customHeaderBuffer.append("CustomValue3");
        dataPart.setHeader(HEADER_CONTENT_TYPE, contentTypeBuffer.toString());
        dataPart.setHeader("AnotherCustomHeader", "AnotherCustomValue");
        dataPart.setHeader("FoldedHeader", customHeaderBuffer.toString());
        return dataPart;
    } catch (Exception exception) {
        Assert.fail();
    }
    return null;
}
Also used : ContentType(javax.mail.internet.ContentType) ByteString(com.linkedin.data.ByteString) MimeBodyPart(javax.mail.internet.MimeBodyPart) IOException(java.io.IOException)

Example 97 with MimeBodyPart

use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.

the class MIMETestUtils method createHeaderLessBody.

private static final MimeBodyPart createHeaderLessBody() {
    try {
        //Header-less body. This has a body but no headers.
        final String body = "A body without any headers.";
        final MimeBodyPart dataPart = new MimeBodyPart();
        final ContentType contentType = new ContentType(TEXT_PLAIN_CONTENT_TYPE);
        dataPart.setContent(body, contentType.getBaseType());
        return dataPart;
    } catch (Exception exception) {
        Assert.fail();
    }
    return null;
}
Also used : ContentType(javax.mail.internet.ContentType) ByteString(com.linkedin.data.ByteString) MimeBodyPart(javax.mail.internet.MimeBodyPart) IOException(java.io.IOException)

Example 98 with MimeBodyPart

use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.

the class TestMIMEReader method testMultipleNormalBodiesDataSource.

@Test(dataProvider = "multipleNormalBodiesDataSource")
public void testMultipleNormalBodiesDataSource(final int chunkSize, final List<MimeBodyPart> bodyPartList) throws Exception {
    MimeMultipart multiPartMimeBody = new MimeMultipart();
    //Add your body parts
    for (final MimeBodyPart bodyPart : bodyPartList) {
        multiPartMimeBody.addBodyPart(bodyPart);
    }
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    multiPartMimeBody.writeTo(byteArrayOutputStream);
    final ByteString requestPayload = ByteString.copy(byteArrayOutputStream.toByteArray());
    executeRequestAndAssert(trimTrailingCRLF(requestPayload), chunkSize, multiPartMimeBody);
}
Also used : MimeMultipart(javax.mail.internet.MimeMultipart) ByteString(com.linkedin.data.ByteString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MimeBodyPart(javax.mail.internet.MimeBodyPart) Test(org.testng.annotations.Test)

Example 99 with MimeBodyPart

use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.

the class TestMIMEReader method testPreambleAndEpilogue.

//Just test the preamble and epilogue here
@Test(dataProvider = "preambleEpilogueDataSource")
public void testPreambleAndEpilogue(final int chunkSize, final List<MimeBodyPart> bodyPartList, final String preamble, final String epilogue) throws Exception {
    MimeMultipart multiPartMimeBody = new MimeMultipart();
    //Add your body parts
    for (final MimeBodyPart bodyPart : bodyPartList) {
        multiPartMimeBody.addBodyPart(bodyPart);
    }
    if (preamble != null) {
        multiPartMimeBody.setPreamble(preamble);
    }
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    multiPartMimeBody.writeTo(byteArrayOutputStream);
    final ByteString requestPayload;
    if (epilogue != null) {
        //Javax mail does not support epilogue so we add it ourselves (other then the CRLF following the final
        //boundary).
        byteArrayOutputStream.write(epilogue.getBytes());
        requestPayload = ByteString.copy(byteArrayOutputStream.toByteArray());
    } else {
        //Our test desired no epilogue.
        //Remove the CRLF introduced by javax mail at the end. We won't want a fake epilogue.
        requestPayload = trimTrailingCRLF(ByteString.copy(byteArrayOutputStream.toByteArray()));
    }
    executeRequestAndAssert(requestPayload, chunkSize, multiPartMimeBody);
}
Also used : MimeMultipart(javax.mail.internet.MimeMultipart) ByteString(com.linkedin.data.ByteString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MimeBodyPart(javax.mail.internet.MimeBodyPart) Test(org.testng.annotations.Test)

Example 100 with MimeBodyPart

use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.

the class TestMIMEReader method testAllTypesOfBodiesDataSource.

@Test(dataProvider = "allTypesOfBodiesDataSource")
public void testAllTypesOfBodiesDataSource(final int chunkSize, final List<MimeBodyPart> bodyPartList) throws Exception {
    MimeMultipart multiPartMimeBody = new MimeMultipart();
    //Add your body parts
    for (final MimeBodyPart bodyPart : bodyPartList) {
        multiPartMimeBody.addBodyPart(bodyPart);
    }
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    multiPartMimeBody.writeTo(byteArrayOutputStream);
    final ByteString requestPayload = ByteString.copy(byteArrayOutputStream.toByteArray());
    executeRequestAndAssert(trimTrailingCRLF(requestPayload), chunkSize, multiPartMimeBody);
}
Also used : MimeMultipart(javax.mail.internet.MimeMultipart) ByteString(com.linkedin.data.ByteString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MimeBodyPart(javax.mail.internet.MimeBodyPart) Test(org.testng.annotations.Test)

Aggregations

MimeBodyPart (javax.mail.internet.MimeBodyPart)172 MimeMultipart (javax.mail.internet.MimeMultipart)111 MimeMessage (javax.mail.internet.MimeMessage)65 MessagingException (javax.mail.MessagingException)64 IOException (java.io.IOException)49 DataHandler (javax.activation.DataHandler)39 ByteString (com.linkedin.data.ByteString)38 ByteArrayOutputStream (java.io.ByteArrayOutputStream)37 BodyPart (javax.mail.BodyPart)35 InternetAddress (javax.mail.internet.InternetAddress)31 ZMimeBodyPart (com.zimbra.common.zmime.ZMimeBodyPart)30 Test (org.testng.annotations.Test)28 ZMimeMultipart (com.zimbra.common.zmime.ZMimeMultipart)23 Multipart (javax.mail.Multipart)20 InputStream (java.io.InputStream)18 ArrayList (java.util.ArrayList)17 HashMap (java.util.HashMap)16 Session (javax.mail.Session)16 Date (java.util.Date)15 Properties (java.util.Properties)15