Package javax.mail

Examples of javax.mail.Part


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

        for (int i = 0; i < mp.getCount(); i++) {
            Part part = mp.getBodyPart(i);          
            if (part.isMimeType("multipart/*")) {
                extractFromMultipart((Multipart)part.getContent(), map);
            } else {
                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


                return multipart.getBodyPart(partNumber);
            }

            for (int i = 0; i<multipart.getCount(); i++)
            {
                Part childPart = multipart.getBodyPart(i);
                if (partName.equals(childPart.getFileName()))
                {
                    return childPart;
                }
            }
        }
View Full Code Here

            {
                Multipart multipart = (Multipart) container;

                for (int i = 0; i<multipart.getCount(); i++)
                {
                    Part part = multipart.getBodyPart(i);

                    String filename = UriParser.encode(part.getFileName());
                    if (filename == null)
                    {
                        filename = MimeFileSystem.NULL_BP_NAME + i;
                    }
View Full Code Here

public class MimeFileContentInfoFactory implements FileContentInfoFactory
{
    public FileContentInfo create(FileContent fileContent) throws FileSystemException
    {
        MimeFileObject mimeFile = (MimeFileObject) fileContent.getFile();
        Part part = mimeFile.getPart();

        String contentTypeString = null;
        String charset = null;

        try
        {
            // special handling for multipart
            if (mimeFile.isMultipart())
            {
                // get the original content type, but ...
                contentTypeString = part.getContentType();

                // .... we deliver the preamble instead of an inupt string
                // the preamble will be delivered in UTF-8 - fixed
                charset = MimeFileSystem.PREAMBLE_CHARSET;
            }
        }
        catch (MessagingException e)
        {
            throw new FileSystemException(e);
        }

        if (contentTypeString == null)
        {
            // normal message ... get the content type
            try
            {
                contentTypeString = part.getContentType();
            }
            catch (MessagingException e)
            {
                throw new FileSystemException(e);
            }
View Full Code Here

        if (message.getContent() instanceof Multipart) {
            // Look for the text part of the mail.
            final Multipart multipart = (Multipart) message.getContent();

            for (int i = 0, n = multipart.getCount(); i < n; i++) {
                final Part part = multipart.getBodyPart(i);

                final String disposition = part.getDisposition();
                if (disposition != null) {
                    if (disposition.equals(Part.ATTACHMENT)
                            || disposition.equals(Part.INLINE)) {
                        // create a representation from part.getInputStream()
                    }
View Full Code Here

            MailUtils.getAttachments(multipart, attachments);

            log.debug("Received Multipart message. Adding attachments");
            for (Map.Entry<String, Part> entry : attachments.entrySet())
            {
                Part part = entry.getValue();
                String name = entry.getKey();

                muleMessage.addInboundAttachment(name, part.getDataHandler());
                addAttachmentHeaders(name, part, muleMessage);
            }
        }
    }
View Full Code Here

    public static void getAttachments(Multipart content, Map<String, Part> attachments) throws MessagingException, IOException
    {
        int x = 0;
        for(int i = 0; i < content.getCount(); i++)
        {
            Part part = content.getBodyPart(i);
            if (part.getContentType().indexOf("multipart/mixed") > -1)
            {
                Multipart m = (Multipart) part.getContent();
                getAttachments(m, attachments);
            }
            else
            {
                String key;
                if (StringUtils.isNotEmpty(part.getDescription()))
                {
                    key = part.getDescription();
                }
                else if (StringUtils.isNotEmpty(part.getFileName()))
                {
                    try
                    {
                        key = MimeUtility.decodeText(part.getFileName());
                    }
                    catch (UnsupportedEncodingException e)
                    {
                        key = part.getFileName();
                    }
                }
                else if (StringUtils.isNotEmpty(part.getDisposition()))
                {
                    key = part.getDisposition();
                }
                else
                {
                    key = String.valueOf(x++);
                }
View Full Code Here

    expunge = Boolean.valueOf(properties.getProperty("expunge")).booleanValue();
  }

  private String getBody(javax.mail.Message message) throws Exception, MessagingException {

    Part messagePart = message;
    Object content = messagePart.getContent();
    if (content instanceof Multipart) {
      messagePart = ((Multipart) content).getBodyPart(0);
    }

    String contentType = messagePart.getContentType();
    StringBuffer sb = new StringBuffer();

    if (contentType.startsWith("text/plain") || contentType.startsWith("text/html")) {
      InputStream is = messagePart.getInputStream();
      BufferedReader reader = new BufferedReader(new InputStreamReader(is));

      String currentLine = reader.readLine();
      while (currentLine != null) {
        sb.append(currentLine);
        sb.append('\n');
        currentLine = reader.readLine();
      }
    }

    if (content instanceof Multipart) {
      int i = 1;
      while (i < ((Multipart) content).getCount()) {
        messagePart = ((Multipart) content).getBodyPart(i);

        if (logger.isLoggable(BasicLevel.DEBUG)) {
          logger.log(BasicLevel.DEBUG, "--- " + this + " Multipart : part=" + messagePart);
        }

        contentType = messagePart.getContentType();

        if (contentType.startsWith("text/plain") || contentType.startsWith("text/html")) {
          InputStream is = messagePart.getInputStream();
          BufferedReader reader = new BufferedReader(new InputStreamReader(is));

          String currentLine = reader.readLine();
          while (currentLine != null) {
            sb.append(currentLine);
View Full Code Here

            content = message.getContent();
            if (content instanceof Multipart) {
                Multipart multipart = (Multipart) content;
                for (int i = 0; i < multipart.getCount(); i++) {
                    try {
                        Part part = multipart.getBodyPart(i);
                        String fileName = part.getFileName();
                        if (fileName != null) {
                            return mail.getRecipients(); // file found
                        }
                    } catch (MessagingException e) {
                        anException = e;
View Full Code Here

       
        if (content instanceof Multipart) {
            Multipart multipart = (Multipart) content;
            for (int i = 0; i < multipart.getCount(); i++) {
                try {
                    Part bodyPart = multipart.getBodyPart(i);
                    if (matchFound(bodyPart)) {
                        return true; // matching file found
                    }
                } catch (MessagingException e) {
                    anException = e;
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.