Package org.apache.james.mime4j.dom

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


        Boolean hasBody = false;

        if (!msg.isMultipart()) {
            plainBody = new StringBuilder(getTextPart(msg));
        } else {
            Multipart multipart = (Multipart) msg.getBody();
            recursiveMultipartProcessing(multipart, plainBody, htmlBody, hasBody, attachments);
        }

        msgProps.put(PLAIN_BODY, plainBody.toString().replaceAll("\r\n", "\n"));
        if (htmlBody.length() > 0) {
View Full Code Here


        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

     */
    private static String getPlainBody(Message msg) throws IOException {
        if (!msg.isMultipart()) {
            return getTextPart(msg);
        } else {
            Multipart multipart = (Multipart) msg.getBody();
            for (Entity enitiy : multipart.getBodyParts()) {
                BodyPart part = (BodyPart) enitiy;
                if (part.isMimeType("text/plain")) {
                    return getTextPart(part);
                }
            }
View Full Code Here

        MessageBuilder builder = new DefaultMessageBuilder();
        Message message = builder.newMessage(original);

        // In this example we know we have a multipart message. Use
        // Message#isMultipart() if uncertain.
        Multipart multipart = (Multipart) message.getBody();

        // 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).
        Entity removed = multipart.removeBodyPart(4);

        // The removed body part no longer has a parent entity it belongs to so
        // it should be disposed of.
        removed.dispose();

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

    public void startMultipart(final BodyDescriptor bd) throws MimeException {
        expect(Entity.class);

        final Entity e = (Entity) stack.peek();
        final String subType = bd.getSubType();
        final Multipart multiPart = new MultipartImpl(subType);
        e.setBody(multiPart);
        stack.push(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

    }

    public void testMultipartAlternative() throws Exception {
        Message message = createMessage(ExampleMail.MIME_MULTIPART_ALTERNATIVE_BYTES);
        assertTrue("Should be a multipart/alternative mail", message.isMultipart());
        Multipart part = (Multipart)message.getBody();
        assertEquals("alternative", part.getSubType());
    }
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.