我正在从本地磁盘读取eml文件:
InputStream is = new FileInputStream(body_path);
MimeMessage message = new MimeMessage(session,is);
Multipart multipart = (Multipart)message.getContent();
现在我如何删除" .dat"的附件?类型?
答案 0 :(得分:0)
您可以这样做: -
撰写new mimemsg
并逐个添加所有部分,但扩展名为DAT
撰写新讯息: -
MimeMessage newMimeMsg;
MimeMultipart content;
if (mimemsg.isMimeType("multipart/*")) {
Multipart multipartmsg = (Multipart) mimemsg.getContent();
for (int i = 0; i < multipartmsg.getCount(); ++i) {
MimeBodyPart bodypart = (MimeBodyPart) multipartmsg.getBodyPart(i);
if(getFileExtension(bodypart.getFileName()).equalsIgnoreCase("dat") {
// Do Nothing
} else {
content.addBodyPart(bodypart);
}
}
newMimeMsg.setContent(content);
} else {
newMimeMsg = mimemsg;
}
public static String getFileExtension(String docFileName) {
String[] tokens = docFileName.split("\\.(?=[^\\.]+$)");
return tokens[1];
}