| text/html texl/plain multipart/alternative multipart/related |
| Object o = m.getContent(); if (m.isMimeType("text/plain")||m.isMimeType("text/html")) { s=" "+(String)o+""; return s; } |
| 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); } } |
| 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 { 11 s="part 无效"; 12 return s; 13 } 14 ContentType ct = new ContentType(sct); 15 if (ct.match("text/plain")) 16 { 17 // display text/plain inline 18 s1=" "+(String)part.getContent()+""; 19 } 20 else 21 { 22 String temp=""; 23 if ((temp = part.getFileName()) != null) 24 s2= "Filename: " + temp + " "; 25 temp = null; 26 if ((temp = part.getDescription()) != null) 27 s3= "Description: " + temp + " "; 28 } 29 s=s1+s2+s3; 30 return s; 31 } |
| public String getPart(Part part, int partNum, int msgNum,int x) throws MessagingException,IOException { String s=""; String s1=""; x参数来确定是以html格式显示还是以plain String s2=""; String s3=""; String s5=""; String sct = part.getContentType(); if (sct == null) { s="part 无效"; return s; } ContentType ct = new ContentType(sct); if (ct.match("text/html")||ct.match("text/plain")) { // display text/plain inline s1=" "+(String)part.getContent()+""; } else if(partNum!=0) { String temp=""; if ((temp = part.getFileName()) != null) { s2= "Filename: " + temp + " "; } /* out.println(" HttpUtils.getRequestURL(req) + "?message=" + msgNum + "&part=" + partNum + "">Display Attachment"); */ } if(part.isMimeType("multipart/alternative")) { String s6=""; String s7=""; Multipart mp = (Multipart)part.getContent(); int count = mp.getCount(); for (int i = 0; i < count; i++) { if(mp.getBodyPart(i).isMimeType("text/plain")) s7=getPart(mp.getBodyPart(i), i, 3,2); if(mp.getBodyPart(i).isMimeType("text/html")) s6=getPart(mp.getBodyPart(i), i, 3,1); } if(x==1){s5=s6;} if(x==2){s5=s7;} return s5; } s=s1+s2; return s; } |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/374079/viewspace-132215/ ,如需转载,请注明出处,否则将追究法律责任。