Display the contents of a composite message with JavaMail (2)

Source: Internet
Author: User
How did you 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.
1 public String Getpart (part part, int partnum)
2 Throws Messagingexception,ioexception
3 {
4 String s= "";
5 String s1= "";
6 String s2= "";
7 String s3= "";
8 String SCT = Part.getcontenttype ();
9 if (SCT = null)
10 {
One s= "part invalid";
return s;
13}
ContentType ct = new ContentType (SCT);
if (Ct.match ("Text/plain"))
16 {
Per/display Text/plain inline
S1= "
"+ (String) part.getcontent () +"
";
19}
Else
21 {
temp= String "";
if (temp = Part.getfilename ())!= null)
S2= "Filename: + temp +"
";
temp = null;
(temp = part.getdescription ())!= null)
S3= "Description: + temp +"
";
28}
S=S1+S2+S3;
return s;
31}
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";

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.