OK I think the real problem is that although you have to check the type of object you're returning with ... it can still be IMAPInputStream when it shouldn't.
I beat this for more than two days.
The main problem is that the Java Mail API does something very dumb, it tries to read in the mailcap file, which is not always available if the class switch has been switched. This is especially difficult in my case because I am dealing with OSGi packages and do not seem to have direct control over which bootloader I use .... but I'm distracted.
I found a “fix” ... maybe THE FIX after sifting the Java Mail API source code as a last resort.
// Set up our Mailcap entries. This will allow the JAF // to locate our viewers. File capfile = new File("/path/to/mailcap"); if (!capfile.isFile()) { System.out.println( "Cannot locate the \"simple.mailcap\" file."); System.exit(1); } CommandMap.setDefaultCommandMap( new MailcapCommandMap( new FileInputStream(capfile)));
I worked for several days and found dozens of people with the same problem and different sentences classpath, thread, classloader. But this is the only thing that worked for me, and it is relatively simple. Therefore, post this to what appears to be the closest related issue with some momentum. Phew
Brendan
source share