我尝试获取电子邮件的html源代码,以便我可以解析它。
由于某种原因,content.getCount()返回2
有时,content.getBodyPart(i)实际上是一个嵌套的Multipart对象
如何区分content.getBodyPart(i)返回的元素
这是获取HTML源的正确方法吗?
ParsedEmailData procesMultiPart(Multipart content){
for (int i = 0; i < content.getCount(); i++) {
BodyPart bodyPart = content.getBodyPart(i);
Object body = bodyPart.getContent();
if(body instanceof Multipart) {
return procesMultiPart((Multipart) body);
}
if (body instanceof String) {
return parsedEmailData = parseEmailBody((String) body);
}
}