Uploaded image for project: 'Commons Email'
  1. Commons Email
  2. EMAIL-204

Parsing multipart should not load content in to memory

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.6.0
    • None

    Description

      When parsing a MimeMessage and the message has attachments it is eagerly loading the content in to a memory via byteArray to create a DataSource. This is inefficient when all I need is a list of attachments which can be pulled from the content disposition for file name.

      If the attachments are large these lines load it in to memory when perhaps it should keep it as an input stream so as not to force loading in to memory until it's actually used by somewhere else in the code.

      MimeMessageParser.java

          protected DataSource createDataSource(final Multipart parent, final MimePart part)
              throws MessagingException, IOException
          {
              final DataHandler dataHandler = part.getDataHandler();
              final DataSource dataSource = dataHandler.getDataSource();
              final String contentType = getBaseMimeType(dataSource.getContentType());
      ---->final byte[] content = this.getContent(dataSource.getInputStream());
      ---->final ByteArrayDataSource result = new ByteArrayDataSource(content, contentType);
              final String dataSourceName = getDataSourceName(part, dataSource);
      
              result.setName(dataSourceName);
              return result;
          }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              dukethrash Deryl Spielman
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: