Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

Please Help:[JavaMail]How to make the embeded images display properly when to show a Multipart/related message?

Thread view: 
M.Liang Liu - 25 May 2007 11:16 GMT
Hi,all:
I am writing a web application to show mails received by JavaMail.
And I found that some content-type of the mail headers is:multipart/
related,which means there are some embeded images,vidios,etc.And I
checked the original tmp file to find the mail contains one part
labeled "text/html",including tokens as this:
++++++++++++++++++++++++++++++++++++++
<DIV><FONT face=Verdana><IMG alt="" hspace=0
src="cid:__0@Foxmail.net"
align=baseline border=0></DIV>
++++++++++++++++++++++++++++++++++++++
I found the id of one of the parts which looks like an attachment, is
"__0@Foxmail.net" and I assumed that it was the very image.
OK,the question is:
How to make the embeded images display properly when to show a  HTML
message?

Any comments is greatly appreciated.
Pardon me for my poor English :)
M.Liang Liu - 28 May 2007 07:10 GMT
> Hi,all:
> I am writing a web application to show mails received by JavaMail.
[quoted text clipped - 15 lines]
> Any comments is greatly appreciated.
> Pardon me for my poor English :)

Multipart mp = (Multipart) part.getContent();
                    Part tmp = mp.getBodyPart(0);
                    String body = LmlMessage.getBody(tmp, userName);
                    int count = mp.getCount();
                    for (int k = 1; k < count; k++) {
                        Part att = mp.getBodyPart(k);
                        String attname = att.getFileName();
                        File attFile = new File(Constants.tomcat_AttHome_Key,
                                userName.concat(attname));
                        FileOutputStream fileoutput = new FileOutputStream(
                                attFile);

                        try {
                            InputStream is = att.getInputStream();
                            BufferedOutputStream outs = new BufferedOutputStream(
                                    fileoutput);
                            byte b[] = new byte[att.getSize()];
                            is.read(b);
                            outs.write(b);
                            outs.close();
                        } catch (Exception e) {
                            logger
                                    .error("Error occurred when to get the photos from server");
                        }
                        String Content_ID[] = att.getHeader("Content-ID");
                        if (Content_ID != null && Content_ID.length > 0) {
                            String cid_name = Content_ID[0].replaceAll("<", "")
                                    .replaceAll(">", "");
                            body = body.replaceAll("cid:" + cid_name,
                                    Constants.server_attHome_Key.concat("/")
                                            .concat(userName.concat(attname)));
                        }
                    }
                    sb.append(body);
                    return sb.toString();
Roedy Green - 28 May 2007 11:08 GMT
>How to make the embeded images display properly when to show a  HTML
>message?

I think what you have to do is translate the bastardised HTML used in
Emails into traditional HTML, then render that.

See http://mindprod.com/jgloss/htmlrendering.html
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.