Package javax.mail.internet

Examples of javax.mail.internet.MimeMultipart


     * @throws EmailException EmailException
     * @throws MessagingException MessagingException
     */
    private void build() throws MessagingException, EmailException
    {
        MimeMultipart rootContainer = this.getContainer();
        MimeMultipart bodyEmbedsContainer = rootContainer;
        MimeMultipart bodyContainer = rootContainer;
        BodyPart msgHtml = null;
        BodyPart msgText = null;

        rootContainer.setSubType("mixed");

        // determine how to form multiparts of email

        if (EmailUtils.isNotEmpty(this.html) && this.inlineEmbeds.size() > 0)
        {
            //If HTML body and embeds are used, create a related container and add it to the root container
            bodyEmbedsContainer = new MimeMultipart("related");
            bodyContainer = bodyEmbedsContainer;
            this.addPart(bodyEmbedsContainer, 0);

            //If TEXT body was specified, create a alternative container and add it to the embeds container
            if (EmailUtils.isNotEmpty(this.text))
            {
                bodyContainer = new MimeMultipart("alternative");
                BodyPart bodyPart = createBodyPart();
                try
                {
                    bodyPart.setContent(bodyContainer);
                    bodyEmbedsContainer.addBodyPart(bodyPart, 0);
                }
                catch (MessagingException me)
                {
                    throw new EmailException(me);
                }
            }
        }
        else if (EmailUtils.isNotEmpty(this.text) && EmailUtils.isNotEmpty(this.html))
        {
            //If both HTML and TEXT bodies are provided, create a alternative container and add it to the root container
            bodyContainer = new MimeMultipart("alternative");
            this.addPart(bodyContainer, 0);
        }

        if (EmailUtils.isNotEmpty(this.html))
        {
            msgHtml = new MimeBodyPart();
            bodyContainer.addBodyPart(msgHtml, 0);

            // apply default charset if one has been set
            if (EmailUtils.isNotEmpty(this.charset))
            {
                msgHtml.setContent(
                    this.html,
                    Email.TEXT_HTML + "; charset=" + this.charset);
            }
            else
            {
                msgHtml.setContent(this.html, Email.TEXT_HTML);
            }

            Iterator iter = this.inlineEmbeds.values().iterator();
            while (iter.hasNext())
            {
                InlineImage ii = (InlineImage) iter.next();
                bodyEmbedsContainer.addBodyPart(ii.getMbp());
            }
        }

        if (EmailUtils.isNotEmpty(this.text))
        {
            msgText = new MimeBodyPart();
            bodyContainer.addBodyPart(msgText, 0);

            // apply default charset if one has been set
            if (EmailUtils.isNotEmpty(this.charset))
            {
                msgText.setContent(
View Full Code Here


     *
     * @return the created mime part
     */
    protected MimeMultipart createMimeMultipart()
    {
        MimeMultipart mmp = new MimeMultipart();
        return mmp;
    }
View Full Code Here

        DispositionModifier modifiers[] = {new ModifierError()};
        Disposition disposition = new Disposition(new ActionModeAutomatic(),
                new SendingModeAutomatic(), new TypeDeleted(), modifiers);

        MimeMultipart multiPart = MDNFactory.create(humanText.toString(),
                reporting_UA_name, reporting_UA_product, original_recipient,
                final_recipient, original_message_id, disposition);

        // Send the message
        MimeMessage reply = (MimeMessage) aMail.getMessage().reply(false);
View Full Code Here

       
        Message msg = mbox.get(0);
        assertTrue("Message should be multipart", msg instanceof MimeMessage);
        assertTrue("Content should be a MimeMultipart", msg.getContent() instanceof MimeMultipart);
       
        MimeMultipart part = (MimeMultipart)msg.getContent();
       
        assertEquals("Should have two body items (message + attachment)", 2, part.getCount());
       
        BodyPart attach = part.getBodyPart(1);
        assertTrue("There should be a PDF named \"test.pdf\" attached", "test.pdf".equalsIgnoreCase(attach.getFileName()));       
    }
View Full Code Here

       
        Message msg = mbox.get(0);
        assertTrue("Message should be multipart", msg instanceof MimeMessage);
        assertTrue("Content should be a MimeMultipart", msg.getContent() instanceof MimeMultipart);
       
        MimeMultipart part = (MimeMultipart)msg.getContent();
       
        assertEquals("Should have two body items (message + attachment)", 2, part.getCount());
       
        BodyPart attach = part.getBodyPart(1);
        assertTrue("There should be a PDF named \"test.pdf\" attached", "test.pdf".equalsIgnoreCase(attach.getFileName()));       
    }
View Full Code Here

        // TODO: add more tests for getting the multipart information.
        if (MimeMessage.class.isInstance(msg)) {
            MimeMessage mimeMsg = (MimeMessage) msg;
            assertEquals("Message content should be a MimeMultipart instance",
                    MimeMultipart.class, mimeMsg.getContent().getClass());
            MimeMultipart multipart = (MimeMultipart) mimeMsg.getContent();
            assertTrue("There should be at least one part in the email",
                    multipart.getCount() >= 1);
            MimeBodyPart bodyPart = (MimeBodyPart) multipart.getBodyPart(0);
            assertThat("UTF-8 charset should be used.", bodyPart.getContentType(),
                    containsString("charset=UTF-8"));
        } else {
            assertThat("UTF-8 charset should be used.", mailbox.get(0).getContentType(),
                    containsString("charset=UTF-8"));
View Full Code Here

            msg.addHeader("X-Jenkins-Result", context.getBuild().getResult().toString());
        }
        msg.setSentDate(new Date());
        setSubject(context, msg, charset);

        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(getContent(context, charset));

        AttachmentUtils attachments = new AttachmentUtils(attachmentsPattern);
        attachments.attach(multipart, context);

        // add attachments from the email type if they are setup
View Full Code Here

            }

            // Buffer the result into a string
            ByteArrayDataSource ds = new ByteArrayDataSource(conn.getInputStream(),
                                                             "multipart/mixed");
            MimeMultipart mp = new MimeMultipart(ds);
            assertEquals("The number of body parts expected is not 1", 1, mp.getCount());

            MimeBodyPart part = (MimeBodyPart) mp.getBodyPart(0);
            VectorClock vc = RestUtils.deserializeVectorClock(part.getHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK)[0]);
            int contentLength = Integer.parseInt(part.getHeader(RestMessageHeaders.CONTENT_LENGTH)[0]);
            byte[] bodyPartBytes = new byte[contentLength];

            part.getInputStream().read(bodyPartBytes);
View Full Code Here

            // Build the multipart object
            byte[] bytes = new byte[entity.length()];
            entity.copyBytes(bytes, 0);

            ByteArrayDataSource ds = new ByteArrayDataSource(bytes, "multipart/mixed");
            MimeMultipart mp = new MimeMultipart(ds);
            for(int i = 0; i < mp.getCount(); i++) {
                MimeBodyPart part = (MimeBodyPart) mp.getBodyPart(i);
                String serializedVC = part.getHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK)[0];
                int contentLength = Integer.parseInt(part.getHeader(RestMessageHeaders.CONTENT_LENGTH)[0]);

                if(logger.isDebugEnabled()) {
                    logger.debug("Received VC : " + serializedVC);
View Full Code Here

            byte[] bytes = new byte[entity.length()];
            entity.copyBytes(bytes, 0);

            // Get the outer multipart object
            ByteArrayDataSource ds = new ByteArrayDataSource(bytes, "multipart/mixed");
            MimeMultipart mp = new MimeMultipart(ds);
            for(int i = 0; i < mp.getCount(); i++) {

                // Get an individual part. This contains all the versioned
                // values for a particular key referenced by content-location
                MimeBodyPart part = (MimeBodyPart) mp.getBodyPart(i);

                // Get the key
                String contentLocation = part.getHeader("Content-Location")[0];
                String base64Key = contentLocation.split("/")[2];
                ByteArray key = new ByteArray(RestUtils.decodeVoldemortKey(base64Key));

                if(logger.isDebugEnabled()) {
                    logger.debug("Content-Location : " + contentLocation);
                    logger.debug("Base 64 key : " + base64Key);
                }

                // Create an array list for holding all the (versioned values)
                List<Versioned<byte[]>> valueResultList = new ArrayList<Versioned<byte[]>>();

                /*
                 * Get the nested Multi-part object. This contains one part for each unique versioned value.
                 *
                 * GetContent method can corrupt the embedded data, for example 0x8c be converted to 0xc2, 0x8c,
                 * hence use getInputStream.
                 *
                 * This thread tracks this question
                 * http://stackoverflow.com/questions/23023583/mimebodypart-getcontent-corrupts-binary-data
                 *
                 * getInputStream() : Return a decoded input stream for this Message's "content.
                 *
                 * getRawInputStream() : Return an InputStream to the raw data with any Content-Transfer-Encoding
                 * intact. This method is useful if the "Content-Transfer-Encoding" header is incorrect or corrupt,
                 * which would prevent the getInputStream method from returning the correct data. In such a case
                 * the application may use this method and attempt to decode the raw data itself.
                 *
                 */

                ByteArrayDataSource nestedDS = new ByteArrayDataSource(part.getInputStream(),
                                                                       "multipart/mixed");
                MimeMultipart valueParts = new MimeMultipart(nestedDS);

                for(int valueId = 0; valueId < valueParts.getCount(); valueId++) {

                    MimeBodyPart valuePart = (MimeBodyPart) valueParts.getBodyPart(valueId);
                    String serializedVC = valuePart.getHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK)[0];
                    int contentLength = Integer.parseInt(valuePart.getHeader(RestMessageHeaders.CONTENT_LENGTH)[0]);

                    if(logger.isDebugEnabled()) {
                        logger.debug("Received serialized Vector Clock : " + serializedVC);
View Full Code Here

TOP

Related Classes of javax.mail.internet.MimeMultipart

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.