JavaMail - Nid help with processing file attachments
I'm using javamail to acquire my gmail messages... and i have encountered a problem with my algorithm for processing the mail's content.. the problem came to a message where it contains 2 file attachments.. a picture and a pdf file.. while my servlet was running getting the content of the message... this error came up...
javax.mail.MessagingException: No inputstream from datasource
at javax.mail.internet.MimeMultipart.parsebm(MimeMultipart.java:646)
at javax.mail.internet.MimeMultipart.parse(MimeMultipart.java:383)
at javax.mail.internet.MimeMultipart.getCount(MimeMultipart.java:229)
at edu.sti.gmail.servlet.MailProcessing.processMailContent(MailProcessing.java:382)
at edu.sti.gmail.servlet.MailProcessing.run(MailProcessing.java:242)
at edu.sti.gmail.servlet.InboxSubjectsServlet.processRequest(InboxSubjectsServlet.java:45)
at edu.sti.gmail.servlet.InboxSubjectsServlet.doPost(InboxSubjectsServlet.java:95)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
and by the way this is my algorithm to process the mail...
public String processMailContent(Object o, String mimeType)throws Exception{
String messageBody =new String();
if (oinstanceof String){
//System.out.println("**This is a String Message**");
//System.out.println((String)o);
if(mimeType.contains("plain")){
messageBody= (String)o;
}
}elseif (oinstanceof Multipart){
//System.out.print("**This is a Multipart Message. ");
Multipart mp = (Multipart)o;
int count3 = mp.getCount();//the error pointed at this line of code
//System.out.println("It has " + count3 +
//" BodyParts in it**");
for (int j = 0; j < count3; j++){
// Part are numbered starting at 0
BodyPart b = mp.getBodyPart(j);
String mimeType2 = b.getContentType();
//System.out.println( "BodyPart " + (j + 1) +
//" is of MimeType " + mimeType2);
Object o2 = b.getContent();
if (o2instanceof String){
//System.out.println("**This is a String BodyPart**");
//System.out.println((String)o2);
if(mimeType2.contains("plain")){
messageBody = (String)o2;
}
}elseif (o2instanceof Multipart){
//System.out.print(
//"**This BodyPart is a nested Multipart. ");
Multipart mp2 = (Multipart)o2;
int count2 = mp2.getCount();
//System.out.println("It has " + count2 +
//"further BodyParts in it**");
for(int k = 0; k<count2; k++){
BodyPart b2 = mp2.getBodyPart(k);
Object o3 = b2.getContent();
String mimeType3 = b2.getContentType();
//System.out.println("SubBodyPart "+ (k+1)+
//"is of MimeType" + mimeType3);
if(o3instanceof String){
//System.out.println("This is a String SubBodyPart");
//System.out.println((String)o3);
if(mimeType3.contains("plain")){
messageBody = (String)o3;
}
}elseif(o3instanceof Multipart){
//System.out.println("This is a nested Sub Multipart");
}elseif(o3instanceof InputStream){
System.out.println("This is an inputstream part");
}
}
}elseif (o2instanceof InputStream){
System.out.println(
"**This is an InputStream BodyPart**");
}
}//End of for
}elseif (oinstanceof InputStream){
System.out.println("**This is an InputStream message**");
InputStream is = (InputStream)o;
// Assumes character content (not binary images)
int c;
while ((c = is.read()) != -1){
System.out.write(c);
}
}
System.out.println("Message Body: "+messageBody);
return messageBody;
}
what should i do? plss help me... i'm really in nid of help ASAP... thanks... i hope u guys understand...
Message was edited by:
Mark.Ramos222

