Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Reading Multipart Message which is Encrypted

843830Oct 17 2006 — edited Oct 18 2006
Hello All,

I am using JDK - 1.5, Java Mail - 1.4 and BouncyCastle API to Encrypt, Digitally Sign and Transport the Mail.

I have created a new MimeMessage, added Text content, attachments, Digitally Signed the Message and then Encrypted the message using BouncyCastle API.

The same message has been decrypted at the other end using the same API's. I was able to successfully read the content, get the attachments.

After Decrypting the Message i was able to TypeCast with the MimeMultiPart and MimeBodyParts and then read the contents successfully.

The problem is, when i send a Message using Outlook-2000 with attachments and then Digitally Sign and Encrypt the Message, i was not able to read the message contents at the other End using my program.

After decrypting the Message the Content-Type was displayed as "Text/Plain" and also if i print the content it displays as "Base64DecoderStream". Due to which i was unable to TypeCast the message to MimeMultiPart.

So, in order to get the MimeMultiPart i have written the code as given below.

MimeMultipart mmp = new MimeMultipart(decryptedMsg.getDataHandler().getDataSource());

BodyPart mmb = mmp.getBodyPart(0);

String mimeType = mmb.getContentType();

if (!("").equals(mimeType) && mimeType.contains("multipart"))
{
Multipart mmp1 = mmb.getParent();
for(int i=0;i<mmp1.getCount();i++)
{
Part mmbTemp = mmp1.getBodyPart(i);
if(mmbTemp.getFileName()!=null)
{
System.out.println(mmbTemp.getFileName());
mmbTemp.saveFile(mmbTemp.getFileName());
}
}
}

with this i am getting the attachment name. But the file is not getting Saved.

I have also tried reading the attachment using Stream but of no use.

I am totally confused why i need to do such a long process when a mail is sent using Outlook. why the content is given as "Base64DecoderStream" instead of MimeMultiPart.

Please suggest me any way to read the contents properly.

Thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 15 2006
Added on Oct 17 2006
7 comments
755 views