You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2022/08/28 16:08:00 UTC

[jira] [Commented] (EMAIL-204) Parsing multipart should not load content in to memory

    [ https://issues.apache.org/jira/browse/EMAIL-204?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17595725#comment-17595725 ] 

Gary D. Gregory commented on EMAIL-204:
---------------------------------------

Hello [~dukethrash] 

Feel free to propose a PR on GitHub.

> Parsing multipart should not load content in to memory
> ------------------------------------------------------
>
>                 Key: EMAIL-204
>                 URL: https://issues.apache.org/jira/browse/EMAIL-204
>             Project: Commons Email
>          Issue Type: Improvement
>            Reporter: Deryl Spielman
>            Priority: Major
>
> 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)