Search in sources :

Example 1 with StorageBodyFactory

use of org.apache.james.mime4j.storage.StorageBodyFactory 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 2 with StorageBodyFactory

use of org.apache.james.mime4j.storage.StorageBodyFactory 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

TextBody (org.apache.james.mime4j.dom.TextBody)2 BodyPart (org.apache.james.mime4j.message.BodyPart)2 StorageBodyFactory (org.apache.james.mime4j.storage.StorageBodyFactory)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Random (java.util.Random)1 BinaryBody (org.apache.james.mime4j.dom.BinaryBody)1 Body (org.apache.james.mime4j.dom.Body)1