尝试通过将邮件正文保存到富文本项目来创建一个新的XPage文档,我的文档得到了正确的创建附件,但是文件中的所有嵌入图像都被替换为imagePlace文件夹,下面是创建附件和图像的方法
private static void parseMimeEntity(RichTextItem attachmentBody, MIMEEntity entity,Session session,File tmpFolder,String fileSeparator,long attachmentNumber) {
MIMEEntity child;
try{
if(!entity.getContentType().equalsIgnoreCase("text")){
String filename = null;
MIMEHeader header = null;
header = entity.getNthHeader("Content-Disposition");
if (header != null) {
filename = header.getParamVal("filename");
filename = filename.replace("\"", "");
if ("".equals(filename)) filename = null;
}
if (filename == null) {
// when filename is null
filename = "Attachment" + attachmentNumber++ + ".txt";
}
String contentDisposition = entity.getNthHeader("Content-Disposition").getHeaderVal();
if(contentDisposition.equalsIgnoreCase("inline")){
String contentType = entity.getNthHeader("Content-Type").getHeaderVal();
Stream stream = session.createStream();
if (stream.open(file.getAbsolutePath(), "binary")) {
entity.setContentFromBytes(stream, contentType, MIMEEntity.ENC_IDENTITY_BINARY);
stream.close();
}
}else{
Stream stream = session.createStream();
if (stream.open(file.getAbsolutePath(), "binary")) {
entity.getContentAsBytes(stream);
stream.close();
}
attachmentBody.embedObject(EmbeddedObject.EMBED_ATTACHMENT, "", file.getAbsolutePath(), filename);
}
file.delete();
}
}
catch(Exception ex){
System.out.println("NO FILE");
}
child = entity.getFirstChildEntity();
if (child != null) {
parseMimeEntity(attachmentBody, child,session,tmpFolder,fileSeparator,attachmentNumber);
}
child = entity.getNextSibling();
if (child != null) {
parseMimeEntity(attachmentBody, child,session,tmpFolder,fileSeparator,attachmentNumber);
}
}
答案 0 :(得分:0)
创建新的mime条目时,会获得新的边界字符串,作为嵌入图像的键。检查传入图像的src
属性以获取确切的格式。
您需要调整这些属性以使图像正确显示。清理HTML并不好玩,请参阅本文的一些内容:
https://codepen.io/aice09/pen/Ogqajr
最终(需要检查,不知道我的想法)你可以指定边界并保存HTML清理
答案 1 :(得分:0)
一种解决方案是Base64对嵌入的图像进行编码,而不是将嵌入的图像作为附件添加。请在此处查看我的回答:https://stackoverflow.com/a/19328276/785061。