Package org.apache.james.mime4j.message

Examples of org.apache.james.mime4j.message.BodyPart


        // Insert a new text/plain body part after every body part of the
        // template.
        final int count = multipart.getCount();
        for (int i = 0; i < count; i++) {
            String text = "Text inserted after part " + (i + 1);
            BodyPart bodyPart = createTextPart(text);
            multipart.addBodyPart(bodyPart, 2 * i + 1);
        }

        // For no particular reason remove the second binary body part (now
        // at index four).
View Full Code Here


     * two binary).
     */
    private static Message createTemplate() throws IOException {
        Multipart multipart = new MultipartImpl("mixed");

        BodyPart part1 = createTextPart("This is the first part of the template..");
        multipart.addBodyPart(part1);

        BodyPart part2 = createRandomBinaryPart(200);
        multipart.addBodyPart(part2);

        BodyPart part3 = createRandomBinaryPart(300);
        multipart.addBodyPart(part3);

        MessageImpl message = new MessageImpl();
        message.setMultipart(multipart);

View Full Code Here

     * Creates a text part from the specified string.
     */
    private static BodyPart createTextPart(String text) {
        TextBody body = new StorageBodyFactory().textBody(text, "UTF-8");

        BodyPart bodyPart = new BodyPart();
        bodyPart.setText(body);
        bodyPart.setContentTransferEncoding("quoted-printable");

        return bodyPart;
    }
View Full Code Here

        new Random().nextBytes(data);

        Body body = new StorageBodyFactory()
                .binaryBody(new ByteArrayInputStream(data));

        BodyPart bodyPart = new BodyPart();
        bodyPart.setBody(body, "application/octet-stream");
        bodyPart.setContentTransferEncoding("base64");

        return bodyPart;
    }
View Full Code Here

        // a multipart may have a preamble
        multipart.setPreamble("This is a multi-part message in MIME format.");

        // first part is text/plain
        StorageBodyFactory bodyFactory = new StorageBodyFactory();
        BodyPart textPart = createTextPart(bodyFactory, "Why so serious?");
        multipart.addBodyPart(textPart);

        // second part is image/png (image is created on the fly)
        BufferedImage image = renderSampleImage();
        BodyPart imagePart = createImagePart(bodyFactory, image);
        multipart.addBodyPart(imagePart);

        // setMultipart also sets the Content-Type header field
        message.setMultipart(multipart);
View Full Code Here

    private static BodyPart createTextPart(StorageBodyFactory bodyFactory, String text) {
        // Use UTF-8 to encode the specified text
        TextBody body = bodyFactory.textBody(text, "UTF-8");

        // Create a text/plain body part
        BodyPart bodyPart = new BodyPart();
        bodyPart.setText(body);
        bodyPart.setContentTransferEncoding("quoted-printable");

        return bodyPart;
    }
View Full Code Here

        StorageProvider storageProvider = bodyFactory.getStorageProvider();
        Storage storage = storeImage(storageProvider, image, "png");
        BinaryBody body = bodyFactory.binaryBody(storage);

        // Create a body part with the correct MIME-type and transfer encoding
        BodyPart bodyPart = new BodyPart();
        bodyPart.setBody(body, "image/png");
        bodyPart.setContentTransferEncoding("base64");

        // Specify a filename in the Content-Disposition header (implicitly sets
        // the disposition type to "attachment")
        bodyPart.setFilename("smiley.png");

        return bodyPart;
    }
View Full Code Here

        assertNull(m.getHeader().getField("Reply-To"));
    }

    public void testDisposeGetsPropagatedToBody() throws Exception {
        DummyBody body1 = new DummyBody();
        BodyPart part1 = new BodyPart();
        part1.setHeader(headerEmpty);
        part1.setBody(body1);

        DummyBody body2 = new DummyBody();
        BodyPart part2 = new BodyPart();
        part2.setHeader(headerEmpty);
        part2.setBody(body2);

        Multipart mp = new MultipartImpl("mixed");
        mp.addBodyPart(part1);
        mp.addBodyPart(part2);
View Full Code Here

                DefaultFieldParser.parse("Content-Type: multipart/form-data; boundary=foo"));
        message.setHeader(header);

        Multipart multipart = new MultipartImpl("alternative");
        multipart.setParent(message);
        BodyPart p1 = new BodyPart();
        Header h1 = new HeaderImpl();
        h1.addField(DefaultFieldParser.parse("Content-Type: text/plain"));
        p1.setHeader(h1);
        p1.setBody(bodyFactory.textBody("this stuff"));
        BodyPart p2 = new BodyPart();
        Header h2 = new HeaderImpl();
        h2.addField(DefaultFieldParser.parse("Content-Type: text/plain"));
        p2.setHeader(h2);
        p2.setBody(bodyFactory.textBody("that stuff"));
        BodyPart p3 = new BodyPart();
        Header h3 = new HeaderImpl();
        h3.addField(DefaultFieldParser.parse("Content-Type: text/plain"));
        p3.setHeader(h3);
        p3.setBody(bodyFactory.textBody("all kind of stuff"));

        multipart.addBodyPart(p1);
        multipart.addBodyPart(p2);
        multipart.addBodyPart(p3);
View Full Code Here

import junit.framework.TestCase;

public class EntityTest extends TestCase {

    public void testSetBody() throws Exception {
        Entity entity = new BodyPart();
        assertNull(entity.getBody());

        Body body = new BasicBodyFactory().textBody("test");
        assertNull(body.getParent());

        entity.setBody(body);
        assertSame(body, entity.getBody());
        assertSame(entity, body.getParent());
    }
View Full Code Here

TOP

Related Classes of org.apache.james.mime4j.message.BodyPart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.