Problem reading attachment of single part e-mail

hi, I have a problem with the javax.mail

If an e-mail have content and attachment , the program could treat it like a multipart e-mail, then I can parse it and read the content of attachment.

but there are some e-mails without text , only with attachment, I just found out the program treat it like single part e-mail, then I use getContent() method to get the content of the attachment, it gaves weird letters .

Can anyone help me with this?

Here is some part of my code

content = ((MimeMessage) messages).getContent().toString();

body = messages.getContent();

if ( body instanceof Multipart )

{

}

else

{ System.out.println(content);

}

[733 byte] By [helen1613ca] at [2007-10-2 21:01:19]
# 1

If you're getting messages that are not multipart, and you want to treat

the single part of the message as an attachment, that's fairly easy,

but you need to decide how you're going to recognize that case and

distinguish it from a single part message with no "attachment".

You might try something like this:

if (msg.isMimeType("multipart/*")) {

// handle mutipart case

} else {

// single part case

String disp = msg.getDisposition();

if (disp != null && disp.equalsIgnoreCase(Part.ATTACHMENT)) {

// handle message content as an attachment

} else {

// message with no attachment

}

}

bshannona at 2007-7-13 23:46:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
thank you for your answer. For the mail without content, but with attachment I tried the way you suggested, the problem is that the disposition I get is always NULL, it just can't recognize the attachment.
helen1613ca at 2007-7-13 23:46:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Then what makes you believe it is intended to be an attachment?

Are you just guessing, or do you have some other knowledge

that tells you it definitely is an attachment?

Unless you know how to make that decision, it's going to be hard

to program your application to make that decision.

bshannona at 2007-7-13 23:46:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
thank you for your reply. For instance, my friend send me an e-mail, it has resume.doc. but she didn't write any bodycontent in the e-mail. But I still knows that the email has attachment.right? unfortunately the e-mail program didn't recognize. Could you help me more? thanks.
helen1613ca at 2007-7-13 23:46:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

Well, again, how is it that you know it's an attachment?

Is it only because your friend told you? That's going to be

hard for your program to replicate! Or is it because the message

has a filename? Is it because the message is not a text MIME type?

Think about how it is you know and you can probably make your

program do the same thing.

bshannona at 2007-7-13 23:46:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...