In a Java project, I can receive mail from a gmail server. But I want to get a body part package. And in this code example, my last message(messages.length - 1) is compound / mixed.
Debug is passed to the if block but gets into the catch block and gives me the following message:
An exception in the "main" thread java.lang.ClassCastException: com.sun.mail.imap.IMAPInputStream cannot be cast to javax.mail.Multipart
How can I deal with this problem?
Message[] messages = folder.getMessages(); ArrayList<String> attachments = new ArrayList<String>(); for (int i = messages.length - 1; i >= 0; i--) { Part p = messages[i]; if (messages[i].isMimeType("multipart/*")) { ***Multipart multipart = (Multipart) messages[i].getContent();*** for (int j = 0, m = multipart.getCount(); j < m; j++) { Part part = multipart.getBodyPart(j); String disposition = part.getDisposition();
edit
I fixed the problem using mail.jar, Additional.jar and .jar activation, which are used only for Java Project .
(I downloaded these cans before for my Android project. That was the source of the problem.)
Meerve
source share