commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Neidhart (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (EMAIL-155) Not Able To Parse Attachments
Date Wed, 24 Jun 2015 13:08:05 GMT

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

Thomas Neidhart commented on EMAIL-155:
---------------------------------------

That's strange, according to the JavaMail specification (see https://javamail.java.net/nonav/docs/api/javax/mail/Part.html#getContent--),
the object as returned by Part#getContent() is always a subclass of Multipart if the content
type is multipart.

> Not Able To Parse Attachments
> -----------------------------
>
>                 Key: EMAIL-155
>                 URL: https://issues.apache.org/jira/browse/EMAIL-155
>             Project: Commons Email
>          Issue Type: Bug
>         Environment: org.apache.commons:commons-email:1.4
>            Reporter: Petr Osipov
>            Priority: Critical
>
> h4. Scenario
> # Sent an email from Microsoft Web UI,
> # When code tries to parse
> {code}
>     public DataSource getAttachment(String username, MimeMessage mimeMessage) throws
Exception {
>         MimeMessageParser messageParser = new MimeMessageParser(mimeMessage);
>         messageParser.parse();
>         // further code
> }
> {code}
> An exception is thrown
> {noformat}
> java.lang.ClassCastException: javax.mail.util.SharedByteArrayInputStream cannot be cast
to javax.mail.Multipart
> 	at org.apache.commons.mail.util.MimeMessageParser.parse(MimeMessageParser.java:195)
> 	at org.apache.commons.mail.util.MimeMessageParser.parse(MimeMessageParser.java:96)
> {noformat}
> Probably int the wild casting to javax.mail.Multipart in MimeMessageParser is a too brave
step
> {code}
>                 if (isMimeType(part, "multipart/*"))
>                 {
>                     this.isMultiPart = true;
>                     final Multipart mp = (Multipart) part.getContent();
>                     final int count = mp.getCount();
>                     // iterate over all MimeBodyPart
>                     for (int i = 0; i < count; i++)
>                     {
>                         parse(mp, (MimeBodyPart) mp.getBodyPart(i));
>                     }
>                 }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message