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

[8885 byte] By [Mark.Ramos222a] at [2007-11-26 23:17:32]
# 1

I don't know why this is happening. Let's debug the problem...

When you get this failure, save a copy of the message to a file:

msg.writeTo(new FileOutputStream("msg.txt"));

Then use the msgshow.java demo program included with JavaMail

to examine the message:

java msgshow -m -s < msg.txt

If that fails, try this:

java -Dmail.mime.multipart.parsebm=false msgshow -m -s < msg.txt

If that also fails, send or post the output from msgshow.

If possible, send me a copy of the message that fails (as an attachment)

to javamail@sun.com.

bshannona at 2007-7-10 14:18:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
hi thanks for the response im going to try this... but pls be reminded that the message contains 2 attachments.. 1 image and 1 pdf file... thanks! and where will i forward the message? what's your email address?
Mark.Ramos222a at 2007-7-10 14:18:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
the console replies.. Exception in thread "main" java.lang.NoClassDefFoundError: msgshowwhat do i do now?
Mark.Ramos222a at 2007-7-10 14:18:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
hi! the servlet did not anymore displayed the error but i did nothing on the code... now ummm can i just ask u if u can help me how to get the file attachments and save it into a directory? plsss.... thanks!
Mark.Ramos222a at 2007-7-10 14:18:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

hi thanks for the response im going to try this...

but pls be reminded that the message contains 2

attachments.. 1 image and 1 pdf file... thanks! and

where will i forward the message? what's your email

address?

As I said, send it to javamail@sun.com.

The number of attachments in the original message should

make no difference.

bshannona at 2007-7-10 14:18:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6
the console replies.. Exception in thread "main"java.lang.NoClassDefFoundError: msgshowwhat do i do now?Did you compile msgshow.java?It's in the "demo" directory of the JavaMail download bundle.
bshannona at 2007-7-10 14:18:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7

hi! the servlet did not anymore displayed the error

but i did nothing on the code... now ummm can i just

ask u if u can help me how to get the file

attachments and save it into a directory? plsss....

thanks!

msgshow.java includes example code that shows how

to save an attachment to a file.

bshannona at 2007-7-10 14:18:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8
thanks so much shannon :D i'm guessing ur one of the developers of javamail.. am i right?
Mark.Ramos222a at 2007-7-10 14:18:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 9
oh now i c... hehehe author bill shannon! :D thanks for helping!
Mark.Ramos222a at 2007-7-10 14:18:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 10
hi bill got another problem.. iv placed ur msgshow file on netbeans and run the command that u said in command prompt... now the error said:Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingExceptionwhat now master?
Mark.Ramos222a at 2007-7-10 14:18:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 11

i got it now..

here's the output from the message show...

This is the message envelope


From: Jules Lagunday <shem_23@yahoo.com>

TO: mark.ramos222@gmail.com

SUBJECT: Fw: update docs

SendDate: Wed Mar 21 19:03:09 CST 2007

Flags:

X-Mailer: YahooMailRC/471 YahooMailWebService/0.6.132.8

CONTENT-TYPE: multipart/mixed; boundary="0-7-6747419-1174474989=:17982"

This is a Multipart


CONTENT-TYPE: multipart/alternative;

boundary="0-115741951-1174474989-:17982"

This is a Multipart


CONTENT-TYPE: text/plain; charset=iso-8859-1

This is a plain text


CONTENT-TYPE: text/html; charset =iso-8859-1


CONTENT-TYPE: application/pdf; name=UNKNOWN_PARAMETER_VALUE

FILENAME: =?utf-8?q?Automated=20Sales=20and=20Inventory=20System=20of=20Lcas.pdf?=


CONTENT-TYPE: image/jpeg; name = UNKNOWN_PARAMTER_VALUE

FILENAME: =?utf-8?q?jules.jpg?=


Mark.Ramos222a at 2007-7-10 14:18:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 12

i was trying this command

C:\Documents and Settings\Mark Ramos\msgshow\dist>java -jar msgshow.jar -m -s -S

< c:/msg27.txt

This is the message envelope


FROM: Jules Lagunday <shem_23@yahoo.com>

TO: mark.ramos222@gmail.com

SUBJECT: Fw: update docs

SendDate: Wed Mar 21 19:03:09 CST 2007

FLAGS:

X-Mailer: YahooMailRC/471 YahooMailWebService/0.6.132.8

CONTENT-TYPE: multipart/mixed; boundary="0-716747419-1174474989=:17982"

This is a Multipart


CONTENT-TYPE: multipart/alternative;

boundary="0-115741951-1174474989=:17982"

This is a Multipart


CONTENT-TYPE: text/plain; charset=iso-8859-1

This is plain text


Saving attachment to file Attachment1

Failed to save attachment: java.io.IOException: file exists


CONTENT-TYPE: text/html; charset=iso-8859-1


Saving attachment to file Attachment2

Failed to save attachment: java.io.IOException: file exists


CONTENT-TYPE: application/pdf; name=UNKNOWN_PARAMETER_VALUE

FILENAME: =?utf-8?q?Automated=20Sales=20and=20Inventory=20System=20of=20LCAS.p

df?=


Saving attachment to file =?utf-8?q?Automated=20Sales=20and=20Inventory=20Syst

em=20of=20LCAS.pdf?=

Failed to save attachment: java.io.FileNotFoundException: =?utf-8?q?Automated=

20Sales=20and=20Inventory=20System=20of=20LCAS.pdf?= (The filename, directory na

me, or volume label syntax is incorrect)


CONTENT-TYPE: image/jpeg; name=UNKNOWN_PARAMETER_VALUE

FILENAME: =?utf-8?q?jules.jpg?=


Saving attachment to file =?utf-8?q?jules.jpg?=

Failed to save attachment: java.io.FileNotFoundException: =?utf-8?q?jules.jpg?

= (The filename, directory name, or volume label syntax is incorrect)


what should i do here?

Mark.Ramos222a at 2007-7-10 14:18:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...