目前我们收到一封电子邮件,该电子邮件由
解析MimeMessageParser mimeMessageParser = parse(message);
然后用
拉出附件 if (mimeMessageParser.hasAttachments()) {
List<DataSource> attachments = mimeMessageParser.getAttachmentList();
for (DataSource dataSource : attachments) {
saveAttachment(dataSource, subjectLineProperties, documentToUpload, firstHeaders);
}
}
问题是 getAttachmentList 还返回内联图像,例如签名行中的企业 Logo ,并且我们不想将内联图像作为附件取出。我们只想要实际的电子邮件附件。 ATTACHMENT 与 INLINE,但我们也无法通过 Apache Commons Email 1.4 版本访问 java.mail 配置,并且找不到解决方案。我检查了他们的文档https://commons.apache.org/proper/commons-email/javadocs/api-1.4/index.html
运气不好。附件数据源似乎只允许我获取内容以及内容类型和名称,但如果它是内联附件/图像或像 Mime Parts 那样的常规附件,则不允许。
最佳答案
我的印象是,有一种解决方法,无需进入较低级别...但我还没有检查所有附件类型 - 仅检查图像。像这样的事情:
for(DataSource ds : mimeMessageParser.getAttachmentList()) {
for(String id : mimeMessageParser.getContentIds()) {
if(ds == mimeMessageParser.findAttachmentByCid(id)) {
// It is inline attachment with Content ID
break;
}
}
// If not found - it is file attachment without content ID
}
关于apache-commons-email - 如何在 Apache Commons Email 1.4 中接收并区分常规附件和内联附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52373411/