Examples of BodyPart


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

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

        MessageImpl message = new MessageImpl();
        message.setMultipart(multipart);
        message.setSubject("Template message");
View Full Code Here

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

       
        final Resource r = resolver.getResource(getResourcePath(msg, store));
        assertNotNull("Expecting non-null Resource", r);
        for (Resource aRes : r.getChildren()) {
            final ModifiableValueMap aMap = aRes.adaptTo(ModifiableValueMap.class);
            BodyPart aMsg = attachmentsMsg.poll();
            assertNotNull("JCR contains more attachments", aMsg);

            for (Field f : aMsg.getHeader().getFields()) {
                String name = f.getName();
                assertEquals("Field "+name+" is different", (aMap.get(name, String.class)), f.getBody());
            }
           
            if (aMsg.getBody() instanceof TextBody) {
                assertEquals("Content is not the same", MessageStoreImpl.getTextPart(aMsg), aMap.get(CONTENT, String.class));
            } else if (aMsg.getBody() instanceof BinaryBody) {
                assertEquals("Content is not the same", getBinPart(aMsg), aMap.get(CONTENT, String.class));
            } else {
                fail("Unknown type of attachment body");
            }
        }
View Full Code Here

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

     * 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;
    }
View Full Code Here

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

        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;
    }
View Full Code Here

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

        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

Examples of org.glassfish.jersey.media.multipart.BodyPart

            String userAgent = headers.getFirst(HttpHeaders.USER_AGENT);
            fileNameFix = userAgent != null && userAgent.contains(" MSIE ");
        }

        for (MIMEPart mimePart : mimeMessage.getAttachments()) {
            BodyPart bodyPart = formData ? new FormDataBodyPart(fileNameFix) : new BodyPart();

            // Configure providers.
            bodyPart.setMessageBodyWorkers(workers);

            // Copy headers.
            for (Header header : mimePart.getAllHeaders()) {
                bodyPart.getHeaders().add(header.getName(), header.getValue());
            }

            try {
                String contentType = bodyPart.getHeaders().getFirst("Content-Type");
                if (contentType != null)
                    bodyPart.setMediaType(MediaType.valueOf(contentType));

                bodyPart.getContentDisposition();
            } catch (IllegalArgumentException ex) {
                throw new BadRequestException(ex);
            }

            // Copy data into a BodyPartEntity structure.
            bodyPart.setEntity(new BodyPartEntity(mimePart));

            // Add this BodyPart to our MultiPart.
            multiPart.getBodyParts().add(bodyPart);
        }
View Full Code Here

Examples of org.latexlab.docs.client.parts.BodyPart

    headerPanel.add(header);
    headerPanel.add(menu);
    headerPanel.add(toolbar);
    output = new OutputPart();
    output.setOutput("Initializing...");
    body = new BodyPart();
    body.setWidth("100%");
    body.setHeight("100%");
    body.setTopLeftWidget(this.editor);
    body.setTopRightWidget(this.previewer);
    body.setBottomWidget(this.output);
View Full Code Here

Examples of org.mime4j.message.BodyPart

                new ObjectWrapper("Multipart", multipart));

        node.add(new DefaultMutableTreeNode(
                       new ObjectWrapper("Preamble", multipart.getPreamble())));
        for (Iterator it = multipart.getBodyParts().iterator(); it.hasNext();) {
            BodyPart part = (BodyPart) it.next();
            node.add(createNode(part));
        }
        node.add(new DefaultMutableTreeNode(
                       new ObjectWrapper("Epilogue", multipart.getEpilogue())));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.