Package org.apache.james.mime4j.message

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


        store = null;
    }

    @Test
    public void simpleMultipartMessageTest() throws IOException {
        Multipart multipart = new MultipartImpl("mixed");
        BodyPart att0 = createTextBody("This is the first part of the template..", "plain", true);
        multipart.addBodyPart(att0);
        BodyPart att1 = createRandomBinaryAttachment(200);
        multipart.addBodyPart(att1);
        BodyPart att2 = createRandomBinaryAttachment(300);
        multipart.addBodyPart(att2);
        BodyPart att3 = createTextBody("Some sample text here...?!", "html", true);
        multipart.addBodyPart(att3);
        BodyPart att4 = createRandomBinaryAttachment(100);
        multipart.addBodyPart(att4);
        BodyPart att5 = createTextBody("Some other text here...?!", "plain", true);
        multipart.addBodyPart(att5);
       
        MessageImpl message = new MessageImpl();
        message.setMultipart(multipart);
        message.setSubject("Template message");
        message.setDate(new Date());
View Full Code Here


        assertSaveMessageWithAttachments(message, 6);
    }
   
    @Test
    public void recursiveMultipartMessageTest() throws IOException {
        Multipart multipart = new MultipartImpl("mixed");
        BodyPart att1 = createRandomBinaryAttachment(100);
        multipart.addBodyPart(att1);
        BodyPart att2 = createRandomBinaryAttachment(133);
        multipart.addBodyPart(att2);
       
        Multipart nestedMultipart = new MultipartImpl("mixed");
        BodyPart nBody = createTextBody("Some sample text here...?!", "plain", false);
        nestedMultipart.addBodyPart(nBody);
        BodyPart nAtt1 = createRandomBinaryAttachment(300);
        nestedMultipart.addBodyPart(nAtt1);
        BodyPart NAtt2 = createRandomBinaryAttachment(100);
        nestedMultipart.addBodyPart(NAtt2);
        BodyPart nAtt3 = createTextBody("Some other text here...<br>?!", "html", true);
        nestedMultipart.addBodyPart(nAtt3);
       
        BodyPart nestedMessage = new BodyPart();
        nestedMessage.setMultipart(nestedMultipart);
        multipart.addBodyPart(nestedMessage);
View Full Code Here

    /**
     * Creates a multipart/mixed message that consists of three parts (one text,
     * 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);

        message.setSubject("Template message");
View Full Code Here

        message.setTo(AddressBuilder.DEFAULT.parseMailbox("Mary Smith <mary@example.net>"));
        message.setSubject("An image for you");

        // 3) set a multipart body

        Multipart multipart = new MultipartImpl("mixed");

        // 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);

        // 4) print message to standard output
View Full Code Here

        Header header = new HeaderImpl();
        header.addField(
                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);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DefaultMessageWriter writer = new DefaultMessageWriter();
        writer.writeMultipart(multipart, out);
        out.close();
View Full Code Here

        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);

        MessageImpl m = new MessageImpl();
        m.setHeader(headerMultipartMixed);
        m.setBody(mp);
View Full Code Here

        assertNull(copy.getParent());
    }

    public void testCopyEmptyMultipart() throws Exception {
        Multipart original = new MultipartImpl("mixed");

        DefaultMessageBuilder builder = new DefaultMessageBuilder();
        Multipart copy = builder.copy(original);

        assertSame(original.getPreamble(), copy.getPreamble());
        assertSame(original.getEpilogue(), copy.getEpilogue());
        assertSame(original.getSubType(), copy.getSubType());
        assertTrue(copy.getBodyParts().isEmpty());
        assertNull(copy.getParent());
    }
View Full Code Here

    public void testCopyMultipart() throws Exception {
        MessageImpl parent = new MessageImpl();
        BodyPart bodyPart = new BodyPart();

        MultipartImpl original = new MultipartImpl("mixed");
        original.setPreamble("preamble");
        original.setEpilogue("epilogue");
        original.setParent(parent);
        original.addBodyPart(bodyPart);

        DefaultMessageBuilder builder = new DefaultMessageBuilder();
        Multipart copy = builder.copy(original);

        assertSame(original.getPreamble(), copy.getPreamble());
        assertSame(original.getEpilogue(), copy.getEpilogue());
        assertSame(original.getSubType(), copy.getSubType());
        assertEquals(1, copy.getBodyParts().size());
        assertNull(copy.getParent());

        Entity bodyPartCopy = copy.getBodyParts().iterator().next();
        assertNotSame(bodyPart, bodyPartCopy);
View Full Code Here

    public void testCopyMultipartMessage() throws Exception {
        BodyPart bodyPart1 = new BodyPart();
        BodyPart bodyPart2 = new BodyPart();

        Multipart multipart = new MultipartImpl("mixed");
        multipart.addBodyPart(bodyPart1);
        multipart.addBodyPart(bodyPart2);

        MessageImpl original = new MessageImpl();
        original.setHeader(new HeaderImpl());
        original.setBody(multipart);
View Full Code Here

        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);

        MessageImpl m = new MessageImpl();
        m.setHeader(headerMultipartMixed);
        m.setBody(mp);
View Full Code Here

TOP

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

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.