我正在尝试在我的项目中读取内联图像表单,但由于处置返回空值,此代码失败。我想要另一种方式来读取内联图像形式的 eml 文件。
public Map<String, String> getInlineContentMap(Multipart multipart) throws MessagingException, IOException {
Map<String, String> inlineContentMap = new HashMap<>();
int numberOfParts = multipart.getCount();
for (int partCount = 0; partCount < numberOfParts; partCount++) {
MimeBodyPart part1 = (MimeBodyPart) multipart.getBodyPart(partCount);
String disposition = part1.getDisposition();
if (disposition != null && Part.INLINE.equalsIgnoreCase(disposition)) {
logger.info("inline image content id: " + part1.getContentID());
Object content = part1.getContent();
if (content instanceof InputStream) {
InputStream inputStream = (InputStream) content;
byte[] byteArray = IOUtils.toByteArray(inputStream);
String str = Base64.encodeBase64String(byteArray);
// String str=new String(byteArray);
inlineContentMap.put(part1.getContentID(), str);
}
}
}
return inlineContentMap;
}