Package javax.mail

Examples of javax.mail.Part


        {
          Multipart multipart = (Multipart)content;

          for (int j = 0, n = multipart.getCount(); j < n; j++)
          {
            Part part = (Part)multipart.getBodyPart(j);
            String contentType = part.getContentType();
            String disposition = part.getDisposition();

            if (disposition == null)
            {
              if (((contentType.length() >= 10) && (contentType.toLowerCase().substring(0, 10).equals("text/plain")))
                || ((contentType.length() >= 9) && (contentType.toLowerCase().substring(0, 9).equals("text/html"))))
              {
                body = (String) (part.getContent()).toString();
              }
            } // end if (disposition == nul)
          } // end for loop
        }else{
          body = (String) (mesage[i].getContent()).toString();
View Full Code Here


    protected void extractAttachmentsFromMultipart(Multipart mp, Map<String, DataHandler> map)
        throws MessagingException, IOException {

        for (int i = 0; i < mp.getCount(); i++) {
            Part part = mp.getBodyPart(i);
            LOG.trace("Part #" + i + ": " + part);

            if (part.isMimeType("multipart/*")) {
                LOG.trace("Part #" + i + ": is mimetype: multipart/*");
                extractAttachmentsFromMultipart((Multipart) part.getContent(), map);
            } else {
                String disposition = part.getDisposition();
                String fileName = part.getFileName();

                if (LOG.isTraceEnabled()) {
                    LOG.trace("Part #{}: Disposition: {}", i, disposition);
                    LOG.trace("Part #{}: Description: {}", i, part.getDescription());
                    LOG.trace("Part #{}: ContentType: {}", i, part.getContentType());
                    LOG.trace("Part #{}: FileName: {}", i, fileName);
                    LOG.trace("Part #{}: Size: {}", i, part.getSize());
                    LOG.trace("Part #{}: LineCount: {}", i, part.getLineCount());
                }

                if (validDisposition(disposition, fileName)
                        || fileName != null) {
                    LOG.debug("Mail contains file attachment: {}", fileName);
                    if (!map.containsKey(fileName)) {
                        // Parts marked with a disposition of Part.ATTACHMENT are clearly attachments
                        map.put(fileName, part.getDataHandler());
                    } else {
                        LOG.warn("Cannot extract duplicate file attachment: {}.", fileName);
                    }
                }
            }
View Full Code Here

          nextPartId.append(".");

        int localPartId = i+1; // IMAPv4 MIME part counter starts from 1
        nextPartId.append(localPartId);

        Part nextPart = multipart.getBodyPart(i);
        parseMessagePart(nextPart, nextPartId.toString());
      }
    } else if ((content instanceof InputStream)
        || (content instanceof MimeMessage)) {
      // binary, message/rfc822 or text attachment
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

        Object content = message.getContent();
        if (content instanceof Multipart) {
            // mail with attachment
            Multipart mp = (Multipart)content;
            for (int i = 0; i < mp.getCount(); i++) {
                Part part = mp.getBodyPart(i);
                String disposition = part.getDisposition();
                if (disposition != null) {
                    if (disposition.equalsIgnoreCase(Part.ATTACHMENT) || disposition.equalsIgnoreCase(Part.INLINE)) {
                        // only add named attachments
                        if (part.getFileName() != null) {
                            // Parts marked with a disposition of Part.ATTACHMENT are clearly attachments
                            CollectionHelper.appendValue(map, part.getFileName(), part.getDataHandler());
                        }
                    }
                }
            }
        }
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

    protected void extractAttachmentsFromMultipart(Multipart mp, Map<String, DataHandler> map)
        throws javax.mail.MessagingException, IOException {

        for (int i = 0; i < mp.getCount(); i++) {
            Part part = mp.getBodyPart(i);
            LOG.trace("Part #" + i + ": " + part);

            if (part.isMimeType("multipart/*")) {
                LOG.trace("Part #" + i + ": is mimetype: multipart/*");
                extractAttachmentsFromMultipart((Multipart)part.getContent(), map);
            } else {
                String disposition = part.getDisposition();
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Part #" + i + ": Disposition: " + part.getDisposition());
                    LOG.trace("Part #" + i + ": Description: " + part.getDescription());
                    LOG.trace("Part #" + i + ": ContentType: " + part.getContentType());
                    LOG.trace("Part #" + i + ": FileName: " + part.getFileName());
                    LOG.trace("Part #" + i + ": Size: " + part.getSize());
                    LOG.trace("Part #" + i + ": LineCount: " + part.getLineCount());
                }

                if (disposition != null && (disposition.equalsIgnoreCase(Part.ATTACHMENT) || disposition.equalsIgnoreCase(Part.INLINE))) {
                    // only add named attachments
                    String fileName = part.getFileName();
                    if (fileName != null) {
                        LOG.debug("Mail contains file attachment: " + fileName);
                        // Parts marked with a disposition of Part.ATTACHMENT are clearly attachments
                        CollectionHelper.appendValue(map, fileName, part.getDataHandler());
                    }
                }
            }
        }
    }
View Full Code Here

    public static String contentIndex = "";
    private static Map addMessageBody( Map commEventMap, Multipart multipart) throws MessagingException, IOException {
        try {
            int multipartCount = multipart.getCount();
            for (int i=0; i < multipartCount  && i < 10; i++) {
                Part part = multipart.getBodyPart(i);
                String thisContentTypeRaw = part.getContentType();
                String content = null;
                int idx2 = thisContentTypeRaw.indexOf(";");
                if (idx2 == -1) {
                    idx2 = thisContentTypeRaw.length();
                }
                String thisContentType = thisContentTypeRaw.substring(0, idx2);
                if (thisContentType == null || thisContentType.equals("")) thisContentType = "text/html";
                thisContentType = thisContentType.toLowerCase();
                String disposition = part.getDisposition();

                if (thisContentType.startsWith("multipart") || thisContentType.startsWith("Multipart")) {
                    contentIndex = contentIndex.concat("." + i);
                    return addMessageBody(commEventMap, (Multipart) part.getContent());
                }
                // See this case where the disposition of the inline text is null
                else if ((disposition == null) && (i == 0) && thisContentType.startsWith("text")) {
                    content = (String)part.getContent();
                    if (UtilValidate.isNotEmpty(content)) {
                        contentIndex = contentIndex.concat("." + i);
                        commEventMap.put("content", content);
                        commEventMap.put("contentMimeTypeId", thisContentType);
                        return commEventMap;
                    }
                } else if ((disposition != null)
                        && (disposition.equals(Part.ATTACHMENT) || disposition.equals(Part.INLINE))
                        && thisContentType.startsWith("text")) {
                    contentIndex = contentIndex.concat("." + i);
                    commEventMap.put("content", part.getContent());
                    commEventMap.put("contentMimeTypeId", thisContentType);
                    return commEventMap;
                }
            }
            return commEventMap;
View Full Code Here

        try {
            int multipartCount = multipart.getCount();
            // Debug.logInfo(currentIndex + "====number of attachments: " + multipartCount, module);
            for (int i=0; i < multipartCount; i++) {
                // Debug.logInfo(currentIndex + "====processing attachment: " + i, module);
                Part part = multipart.getBodyPart(i);
                String thisContentTypeRaw = part.getContentType();
                // Debug.logInfo("====thisContentTypeRaw: " + thisContentTypeRaw, module);
                int idx2 = thisContentTypeRaw.indexOf(";");
                if (idx2 == -1) idx2 = thisContentTypeRaw.length();
                String thisContentType = thisContentTypeRaw.substring(0, idx2);
                String disposition = part.getDisposition();
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                if (part instanceof Multipart) {
                    currentIndex = currentIndex.concat("." + i);
                    // Debug.logInfo("=====attachment contain attachment, index:" + currentIndex, module);
                    return addMultipartAttachementToComm((Multipart) part.getContent(), commEventMap, subject, dispatcher, userLogin);
                }
                // Debug.logInfo("=====attachment not contains attachment, index:" + currentIndex, module);
                // Debug.logInfo("=====check for currentIndex(" + currentIndex  + ") against master contentIndex(" + EmailServices.contentIndex + ")", module);
                if (currentIndex.concat("." + i).equals(CommunicationEventServices.contentIndex)) continue;

                // The first test should not pass, because if it exists, it should be the bodyContentIndex part
                // Debug.logInfo("====check for disposition: " + disposition + " contentType: '" + thisContentType + "' variable i:" + i, module);
                if ((disposition == null && thisContentType.startsWith("text"))
                        || ((disposition != null)
                                && (disposition.equals(Part.ATTACHMENT) || disposition.equals(Part.INLINE))
                                ) )
                {
                    String attFileName = part.getFileName();
                    Debug.logInfo("===processing attachment: " + attFileName, module);
                    if (!UtilValidate.isEmpty(attFileName)) {
                           commEventMap.put("contentName", attFileName);
                           commEventMap.put("description", subject + "-" + attachmentCount);
                    } else {
                        commEventMap.put("contentName", subject + "-" + attachmentCount);
                    }
                    commEventMap.put("drMimeTypeId", thisContentType);
                    if (thisContentType.startsWith("text")) {
                        String content = (String)part.getContent();
                        commEventMap.put("drDataResourceTypeId", "ELECTRONIC_TEXT");
                        commEventMap.put("textData", content);
                    } else {
                        InputStream is = part.getInputStream();
                        int c;
                        while ((c = is.read()) > -1) {
                            baos.write(c);
                        }
                        ByteBuffer imageData = ByteBuffer.wrap(baos.toByteArray());
                        int len = imageData.limit();
                        if (Debug.infoOn()) Debug.logInfo("imageData length: " + len, module);
                        commEventMap.put("drDataResourceName", part.getFileName());
                        commEventMap.put("imageData", imageData);
                        commEventMap.put("drDataResourceTypeId", "IMAGE_OBJECT");
                        commEventMap.put("_imageData_contentType", thisContentType);
                    }
                    dispatcher.runSync("createCommContentDataResource", commEventMap);
View Full Code Here

    protected void extractAttachmentsFromMultipart(Multipart mp, Map<String, DataHandler> map)
        throws javax.mail.MessagingException, IOException {

        for (int i = 0; i < mp.getCount(); i++) {
            Part part = mp.getBodyPart(i);
            LOG.trace("Part #" + i + ": " + part);

            if (part.isMimeType("multipart/*")) {
                LOG.trace("Part #" + i + ": is mimetype: multipart/*");
                extractAttachmentsFromMultipart((Multipart)part.getContent(), map);
            } else {
                String disposition = part.getDisposition();
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Part #" + i + ": Disposition: " + part.getDisposition());
                    LOG.trace("Part #" + i + ": Description: " + part.getDescription());
                    LOG.trace("Part #" + i + ": ContentType: " + part.getContentType());
                    LOG.trace("Part #" + i + ": FileName: " + part.getFileName());
                    LOG.trace("Part #" + i + ": Size: " + part.getSize());
                    LOG.trace("Part #" + i + ": LineCount: " + part.getLineCount());
                }

                if (disposition != null && (disposition.equalsIgnoreCase(Part.ATTACHMENT) || disposition.equalsIgnoreCase(Part.INLINE))) {
                    // only add named attachments
                    String fileName = part.getFileName();
                    if (fileName != null) {
                        LOG.debug("Mail contains file attachment: " + fileName);
                        if (!map.containsKey(fileName)) {
                            // Parts marked with a disposition of Part.ATTACHMENT are clearly attachments
                            map.put(fileName, part.getDataHandler());
                        } else {
                            LOG.warn("Cannot extract duplicate attachment: " + fileName);
                        }
                    }
                }
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.