Search in sources :

Example 6 with BodyPart

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

the class MessageStoreImplAttachmentsTest method createTextBody.

/*
     * taken from http://svn.apache.org/repos/asf/james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
     */
private static BodyPart createTextBody(String text, String subtype, boolean isAttachment) {
    TextBody body = new StorageBodyFactory().textBody(text, MailArchiveServerConstants.DEFAULT_ENCODER.charset().name());
    BodyPart bodyPart = new BodyPart();
    if (isAttachment) {
        bodyPart.setContentDisposition("attachment", "file" + Math.random());
    }
    bodyPart.setText(body, subtype);
    return bodyPart;
}
Also used : TextBody(org.apache.james.mime4j.dom.TextBody) StorageBodyFactory(org.apache.james.mime4j.storage.StorageBodyFactory) BodyPart(org.apache.james.mime4j.message.BodyPart)

Example 7 with BodyPart

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

the class MessageStoreImplAttachmentsTest method createRandomBinaryAttachment.

/*
     * taken from http://svn.apache.org/repos/asf/james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
     */
private static BodyPart createRandomBinaryAttachment(int numberOfBytes) throws IOException {
    byte[] data = new byte[numberOfBytes];
    new Random().nextBytes(data);
    Body body = new StorageBodyFactory().binaryBody(new ByteArrayInputStream(data));
    BodyPart bodyPart = new BodyPart();
    bodyPart.setContentDisposition("attachment", "file" + Math.random());
    bodyPart.setBody(body, "application/octet-stream");
    return bodyPart;
}
Also used : StorageBodyFactory(org.apache.james.mime4j.storage.StorageBodyFactory) BodyPart(org.apache.james.mime4j.message.BodyPart) Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) Body(org.apache.james.mime4j.dom.Body) TextBody(org.apache.james.mime4j.dom.TextBody) BinaryBody(org.apache.james.mime4j.dom.BinaryBody)

Aggregations

BodyPart (org.apache.james.mime4j.message.BodyPart)7 TextBody (org.apache.james.mime4j.dom.TextBody)4 BinaryBody (org.apache.james.mime4j.dom.BinaryBody)3 Multipart (org.apache.james.mime4j.dom.Multipart)3 RawField (org.apache.james.mime4j.stream.RawField)3 Date (java.util.Date)2 Body (org.apache.james.mime4j.dom.Body)2 MessageImpl (org.apache.james.mime4j.message.MessageImpl)2 MultipartImpl (org.apache.james.mime4j.message.MultipartImpl)2 StorageBodyFactory (org.apache.james.mime4j.storage.StorageBodyFactory)2 Resource (org.apache.sling.api.resource.Resource)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Queue (java.util.Queue)1 Random (java.util.Random)1 Entity (org.apache.james.mime4j.dom.Entity)1