Java mail problem transporting attachments from ImapBodyPart object

D

dalouis

I have a question for anyone that can help. Im writing a very simple
webmail application that works on imap and I have collected my
attachments into MimeBodyPart Objects and now I have trouble sending
them back to the web-user.

The application runs on the server but the real client of the email is
the webbrowser, as such I do not want to use the saveFile() method of
MimeBodyPart. If I do use the saveFile() method , then it saves the
file, correctly, to some file on my apache-jakarta machine.

e.g:
((MimeBodyPart)p).saveFile(f);
//this works fine but results in a file on the apache server which is
no use to me.

The attachment in my test case has a word document .doc file and i am
trying to return it, via the apache machine, to the web client and have
it open properly. So I tried using the methods java.io.InputStream
getInputStream() and java.io.InputStream getRawInputStream() but when i
do this I always end up with 0 bytes.

Finally I tried the
writeTo(java.io_OutputStream os)
//Output the body part as an RFC 822 format stream.

When I use this method it returns what seems to be the file but it
seems to include headers in the stream which confuses microsoft word.
Microsoft Word then displays the file like this:

"Content-Type: application/msword; name="Mydoc.doc";
x-mac-type="42494D41"; x-mac-creator="4D5357D4"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="Mydoc.doc"

0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAADAAAAJAAAAAAAAAAA
EAAALgAAAAEAAAD+////AAAAACMAAAAxAAAA4gAAAP//////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
"

Does anyone know how to properly send this attachment back to the
webbrowser. It looks like i am missing something. Basically the code
that i am using on the jsp engine is the following:

response.setHeader("Content-Type","application/msword");
response.setHeader("Content-disposition", "filename="+filename );
OutputStream outputStream = response.getOutputStream();
myMime.writeTo(outputStream);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top