我的磁盘中有一个p7m文件,其中包含1个jpg图片,1个txt文件和一个电子邮件正文上下文。幸运的是,我可以获取电子邮件正文和p7s文件。我可以验证p7s文件(证书),但我找不到这两个附件。看起来像是失踪了。我不知道为什么?有人遇到过这个问题吗? p7m文件来自EWS(Outlook)。
public static void main(String args[]) {
try {
DataSource source = new FileDataSource("C:/Users/zhontao/Desktop/smime.p7m");
MimeMultipart multi1 = new MimeMultipart(source);
for (int i = 0; i < multi1.getCount(); i++) {
Part part1 = multi1.getBodyPart(i);
if (part1.getContent() instanceof Multipart) {
Multipart multi2 = (Multipart) part1.getContent();
for (int j = 0; j < multi2.getCount(); j++) {
Part part2 = multi2.getBodyPart(i);
String contentType = part2.getContentType();
System.out.println(contentType);
// generally if the content type multipart/alternative, it is email text.
if (part2.isMimeType("multipart/alternative")) {
if (part2.getContent() instanceof Multipart) {
Multipart multi3 = (Multipart) part2.getContent();
for (int k = 0; k < multi3.getCount(); k++) {
Part part4 = multi3.getBodyPart(k);
String contentType1 = part4.getContentType();
System.out.println(contentType1);
if (part4.isMimeType("text/plain") && !Part.ATTACHMENT.equalsIgnoreCase(part4.getDisposition())) {
System.out.println(part4.getContent().toString());
} else if (part4.isMimeType("text/html") && !Part.ATTACHMENT.equalsIgnoreCase(part4.getDisposition())) {
System.out.println(part4.getContent().toString());
}
}
}
}
}
} else {
String contentType = part1.getContentType();
System.out.println(contentType);
String disposition = part1.getDisposition();
System.out.println(disposition);
System.out.println(part1.getFileName());
// this.saveFile(part1.getFileName(), part1.getInputStream());
}
}
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
答案 0 :(得分:0)
print("Index is \(viewcontrollerInstall.index)")
应该是
Part part2 = multi2.getBodyPart(i);