Hello,
wonder if anyone could suggest how to resolve this.
Environment:
windows 7
Jre 1.7.0_13
javamail 1.5
I'm having problem with a message "part". When I execute a simple java class in Eclipse , and cast "part" to multipart
Multipart mp = (Multipart) p.getContent();
but when I run the same class (same jars) from a database event (starts the same jvm) it reports :
Exception in thread "main" java.lang.classCastException: com.sun.mail.imap.IMAPInputStream cannot be cast to javax.mail.Multipart at
So, when I was debugging this , I can see that when running with Eclipse , instanceof "part" is reported as Multipart, but when running from a database as InputStream.
I've read that this might be related to DataHandler ?? but I couldn't figure out how ? and what should I do to resolve it. Wonder if anyone would have some suggestions?
some snippet:
...
// Get system properties
Properties properties = System.getProperties();
// Get the default Session object.
Session session = Session.getDefaultInstance(properties);
session.setDebug(debug);
// Get a Store object that implements the specified protocol.
Store store = session.getStore(protocol); // gmail setting
//Connect to the current host using the specified username and password.
store.connect(host, user, password);
//Create a Folder object corresponding to the given name.
Folder folder = store.getFolder(mbox);
// Open the Folder.//
folder.open(Folder.READ_WRITE);
FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
Message[] message = folder.search(ft);
for (i = 0; i < message.length; i++) {
alert_sent = null;
java.util.Date msg_sent_date = message[i].getSentDate();
alert_sent = new java.sql.Timestamp(msg_sent_date.getTime());
alert_from = "";
alert_from = InternetAddress.toString(message[i].getFrom());
alert_subject = "";
alert_subject = message[i].getSubject();
content_type = "";
content_type = message[i].getContentType();
alert_text = "";
alert_html = "";
if ( content_type.startsWith("text/") || content_type.startsWith("TEXT/") )
{ alert_text = message[i].getContent().toString();}
else
{
alert_html = getMessageText(message[i]);
}
.........
and in getMessageText(Part p);
...
Multipart mp = (Multipart) p.getContent();
...