Package org.apache.james.mime4j.dom

Examples of org.apache.james.mime4j.dom.Multipart


    }

    public void testMultipartMixed() throws Exception {
        Message message = createMessage(ExampleMail.MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_BYTES);
        assertTrue("Should be a multipart/mixed mail", message.isMultipart());
        Multipart part = (Multipart)message.getBody();
        assertEquals("mixed", part.getSubType());
    }
View Full Code Here


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

        assertSame(parent, bodyPart.getParent());
        assertNull(bodyPartCopy.getParent());
    }
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);

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

        Multipart multipartCopy = (Multipart) copy.getBody();
        List<Entity> bodyParts = multipartCopy.getBodyParts();
        Entity bodyPartCopy1 = bodyParts.get(0);
        Entity bodyPartCopy2 = bodyParts.get(1);

        assertNotSame(bodyPart1, bodyPartCopy1);
        assertEquals(original, bodyPart1.getParent());
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

        sb.append("</header>\r\n");

        if (e.getBody() instanceof Multipart) {
            sb.append("<multipart>\r\n");

            Multipart multipart =(Multipart) e.getBody();
            List<Entity> parts = multipart.getBodyParts();

            if (multipart.getPreamble() != null) {
                sb.append("<preamble>\r\n");
                sb.append(escape(multipart.getPreamble()));
                sb.append("</preamble>\r\n");
            }

            int i = 1;
            for (Entity bodyPart : parts) {
                sb.append(getStructure(bodyPart, prefix, id + "_" + (i++)));
            }

            if (multipart.getEpilogue() != null) {
                sb.append("<epilogue>\r\n");
                sb.append(escape(multipart.getEpilogue()));
                sb.append("</epilogue>\r\n");
            }

            sb.append("</multipart>\r\n");
View Full Code Here

        assertEquals("multipart/form-data", message.getMimeType());
        assertEquals(1, message.getHeader().getFields().size());
        ContentTypeField contentTypeField = ((ContentTypeField) message
                .getHeader().getField(FieldName.CONTENT_TYPE));
        assertEquals("foo", contentTypeField.getBoundary());
        Multipart multipart = (Multipart) message.getBody();
        assertEquals(3, multipart.getCount());
    }
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

        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

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

        assertSame(parent, bodyPart.getParent());
        assertNull(bodyPartCopy.getParent());
    }
View Full Code Here

TOP

Related Classes of org.apache.james.mime4j.dom.Multipart

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.