Display the contents of a composite message with JavaMail (2)
Source: Internet
Author: User
Show that it didn't get the part?
One thing to emphasize here is that when you do not get the part object, calling Part.getcontent () can get the contents of parts. I was stuck here at the beginning. Why, then? The reason is:
Theoretically indicates that the first part of the content is neither a text/plain type nor a text/html type. Therefore, the 15th line is never tenable. It was later found that the first part of the content was a multipart type. In other words, this message can be divided into several parts, body and pictures, and the body can be divided into several parts, such as plain body and HTML text. In this way, it's like a tree. Only when you reach the leaf can you know when it is plain or HTML. So, our recursive call in part solves the problem.
The following is a modified Getpart method (very coarse, not optimized) that can be used to correctly display compound messages.
Public String Getpart (part part, int partnum, int msgnum,int x) throws
Messagingexception,ioexception
{
String s= "";
String s1= ""; x parameter to determine whether it is displayed in HTML format or in plain
String s2= "";
String s3= "";
String s5= "";
String SCT = Part.getcontenttype ();
if (SCT = null)
{
s= "part Invalid";
return s;
}
ContentType ct = new ContentType (SCT);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.