Package javax.mail

Examples of javax.mail.Part


            try {
                Multipart multipart = (Multipart) part.getContent();
                boolean atLeastOneRemoved = false;
                int numParts = multipart.getCount();
                for (int i = 0; i < numParts; i++) {
                    Part p = multipart.getBodyPart(i);
                    if (p.isMimeType("multipart/*")) {
                        atLeastOneRemoved |= analyseMultipartPartMessage(p,
                                mail);
                    } else {
                        boolean removed = checkMessageRemoved(p, mail);
                        if (removed) {
View Full Code Here


                String message = "Cannot get message for id " + String.valueOf(msgId);
                getLogger().warn(message);
                return;
            }
            try {
                Part part = null;
                Object objRef = msg.getContent();
                if (!(objRef instanceof Multipart)) {
                    String message = "Message of id " + String.valueOf(msgId) + " is not a multipart message!";
                    getLogger().warn(message);
                    return;
View Full Code Here

            else if (content instanceof MimeMultipart) {
                // mail with attachment
                mp = (MimeMultipart)content;
                int nbMP = mp.getCount();
                for (int i=0; i < nbMP; i++) {
                    Part part = mp.getBodyPart(i);
                    String disposition = part.getDisposition();
                    if ((disposition != null) &&
                        ((disposition.equals(Part.ATTACHMENT) ||
                         (disposition.equals(Part.INLINE))))) {
                        //Parts marked with a disposition of Part.ATTACHMENT from part.getDisposition() are clearly attachments
                        DataHandler att = part.getDataHandler();
                        normalizedMessage.addAttachment(att.getName(), att);
                    } else {
                        MimeBodyPart mbp = (MimeBodyPart)part;
                        if (mbp.isMimeType("text/plain")) {
                          // Handle plain
View Full Code Here

        System.out.println("Created message: " + message);
        Object content = message.getContent();
        assertTrue(content instanceof MimeMultipart);
        MimeMultipart contentMP = (MimeMultipart) content;
        assertEquals(contentMP.getCount(), 3); // first attachement for text body and second for file attached
        Part part = contentMP.getBodyPart(0);
        assertTrue(part.isMimeType("text/plain"));
        part = contentMP.getBodyPart(1);
        String disposition = part.getDisposition();
        assertTrue(disposition.equalsIgnoreCase(Part.ATTACHMENT));
        DataHandler att = part.getDataHandler();
        assertEquals("example.xml", att.getName().toLowerCase());
        part = contentMP.getBodyPart(2);
        disposition = part.getDisposition();
        assertTrue(disposition.equalsIgnoreCase(Part.ATTACHMENT));
        att = part.getDataHandler();
        assertEquals("id", att.getName().toLowerCase());
        assertEquals("subject", "Drink a beer James", message.getSubject());
    }
View Full Code Here

        //TODO we assume for the time being that there is only one attachement and this attachement contains  the soap evelope
        try {
            Multipart mp = (Multipart) msg.getContent();
            if (mp != null) {
                for (int i = 0, n = mp.getCount(); i < n; i++) {
                    Part part = mp.getBodyPart(i);

                    String disposition = part.getDisposition();

                    if (disposition != null && disposition.equalsIgnoreCase(Part.ATTACHMENT)) {
                        String soapAction;

                        /* Set the Charactorset Encoding */
                        String contentType = part.getContentType();
                        String charSetEncoding = BuilderUtil.getCharSetEncoding(contentType);
                        if (charSetEncoding != null) {
                            msgContext.setProperty(
                                    org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING,
                                    charSetEncoding);
                        } else {
                            msgContext.setProperty(
                                    org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING,
                                    MessageContext.DEFAULT_CHAR_SET_ENCODING);
                        }

                        /* SOAP Action */
                        soapAction = getMailHeaderFromPart(part,
                                                           org.apache.axis2.transport.mail.Constants.HEADER_SOAP_ACTION);
                        msgContext.setSoapAction(soapAction);

                        String contentDescription =
                                getMailHeaderFromPart(part, "Content-Description");

                        /* As an input stream - using the getInputStream() method.
                        Any mail-specific encodings are decoded before this stream is returned.*/
                        if (contentDescription != null) {
                            msgContext.setTo(new EndpointReference(contentDescription));
                        }

                        if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
                            TransportUtils
                                    .processContentTypeForAction(contentType, msgContext);
                        } else {
                            // According to the mail sepec, mail transport should support only
                            // application/soap+xml;
                            String message = "According to the mail sepec, mail transport " +
                                             "should support only application/soap+xml";
                            log.error(message);
                            throw new AxisFault(message);
                        }

                        String cte = getMailHeaderFromPart(part, "Content-Transfer-Encoding");
                        if (!(cte != null && cte.equalsIgnoreCase("base64"))) {
                            String message = "Processing of Content-Transfer-Encoding faild.";
                            log.error(message);
                            throw new AxisFault(message);
                        }
                        InputStream inputStream = part.getInputStream();
                        SOAPEnvelope envelope = TransportUtils
                                .createSOAPMessage(msgContext, inputStream, contentType);
                        msgContext.setEnvelope(envelope);
                    }
                }
View Full Code Here

            Multipart mpart = (Multipart) obj;
            for (int i = 0, n = mpart.getCount(); i < n; i++)
            {
                Vector vAttachments = new Vector();

                Part part = mpart.getBodyPart(i);
                //get attachment
                String disposition = part.getDisposition();
                if ((disposition != null)
                        && ((disposition.equalsIgnoreCase(Part.ATTACHMENT)) || (disposition
                                .equals(Part.INLINE))))
                {
                    if (disposition.equals(Part.INLINE))
                    {
                        if (part.isMimeType("text/plain"))
                        {
                            cmessage = (String) part.getContent().toString();
                        } else
                        {// if content-type is Image/gif, get the filename and
                         // add to the vector that holds all attachments
                            getAttachments(message);
                        }
                    }

                    if (disposition.equalsIgnoreCase(Part.ATTACHMENT))
                    {
                        log.info("*** Attachment name: " + part.getFileName());
                        getAttachments(message);
                    }
                } else if (disposition == null)
                {
                    if (part.getContent() instanceof MimeMultipart)
                    { // multipart with attachment
                        MimeMultipart mm = (MimeMultipart) part.getContent();
                        cmessage = (mm.getBodyPart(1)).getContent().toString();
                    } else
                    {//multipart - w/o attachment
                        cmessage = (String) part.getContent().toString();
                    }
                }
            }//for
        }//else
        return cmessage;
View Full Code Here

        Object obj = message.getContent();
        Multipart mpart = (Multipart) obj;
        String name = null;
        for (int i = 0, n = mpart.getCount(); i < n; i++)
        {
            Part part = mpart.getBodyPart(i);
            if (part.getFileName() != null) name = part.getFileName();
        }
        return name;
    }
View Full Code Here

        String name = null;
        String id = null;

        for (int i = 0, n = mpart.getCount(); i < n; i++)
        {
            Part part = mpart.getBodyPart(i);
            name = part.getFileName();

            if (part.getFileName() != null) vAtt.add(part.getFileName());
            //attachmentIDs(message);
        }
        return vAtt;
    }
View Full Code Here

                Object obj = message.getContent();
                Multipart mpart = (Multipart) obj;

                for (int i = 0, n = mpart.getCount(); i < n; i++)
                {
                    Part part = mpart.getBodyPart(i);
                    //get attachment
                    String disposition = part.getDisposition();

                    if ((disposition != null)
                            && ((disposition.equalsIgnoreCase(Part.ATTACHMENT)) || (disposition
                                    .equals(Part.INLINE))))
                    {
                        hasattachment = true;
                    } else if (disposition == null)
                    {
                        if (part.getContent() instanceof MimeMultipart)
                        {
                            hasattachment = true;
                        }
                    } else
                        hasattachment = false;
View Full Code Here

                    Object obj = message.getContent();
                    Multipart mpart = (Multipart) obj;

                    for (int j = 0, n = mpart.getCount(); j < n; j++)
                    {
                        Part part = mpart.getBodyPart(j);
                        String disposition = part.getDisposition();
                        if ((disposition != null)
                                && ((disposition
                                        .equalsIgnoreCase(Part.ATTACHMENT)) || (disposition
                                        .equals(Part.INLINE))))
                        {
                            if (part.getFileName() != null)
                            {
                                log.info("*** Attachment name: "
                                        + part.getFileName());
                                if (part.getContent() instanceof String)
                                {
                                    byte[] b = ((String) part.getContent())
                                            .getBytes();
                                    is = new ByteArrayInputStream(b);
                                } else
                                {
                                    is = part.getInputStream();
                                }
                                filename = part.getFileName();
                                size = part.getSize();
                            }
                        }
                    } //for
                } // if with attachment

View Full Code Here

TOP

Related Classes of javax.mail.Part

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.