Compound message: Contains both a picture and body text, which is usually displayed in HTML format. Simple to understand, is a very beautiful kind of mail.
(Personal note, not very comprehensive)
When we need to do a mail-receiving program, how do we display the contents of a composite message?
Today I have a little experience to write out, I hope that the latter can be less detours. Of course, I hope comrades will correct me.
First, we need to get a message object from the folder. This step is not difficult to achieve. You can see many examples. When we get the message object, the next step is to show his content. Before starting this section, you first need to briefly describe several important types of mimetype:
text/html
texl/plain
multipart/alternative
multipart/related
The first two do not have to introduce, one is HTML format body, one is unformatted body. If your message object is one of those two mimetype. Then your mail is not multipart mail. You can just go and show them. As follows:
Object o = m.getContent();
if (m.isMimeType("text/plain")||m.isMimeType("text/html"))
{
s="
"+(String)o+"
";
return s;
}
S is the content string to return. M is the message object.
If your message object is the latter two, it means your email is multipart. Need to do some processing and judgment to normal display content. If the message is multipart, just get the contents of the various parts (part) of the multipart. The content of the entire message is obtained.
if (m.isMimeType("multipart/*")
{
Multipart mp = (Multipart)o;
int cnt = mp.getCount();
for (int i = 0; i < cnt; i++)
{
w=w+"
"+getPart(mp.getBodyPart(i), i, 2,x);
}
}
Getpart is the way to get part content.
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: