Deryl Spielman created EMAIL-204:
------------------------------------

             Summary: Lazy load multipart content
                 Key: EMAIL-204
                 URL: https://issues.apache.org/jira/browse/EMAIL-204
             Project: Commons Email
          Issue Type: Improvement
            Reporter: Deryl Spielman


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*
{code: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;
    }
{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to