試圖通過將郵件正文保存到richtext中來創建新的XPage文檔項目,我的文檔正確創建attachmentBody也被克隆,但是文檔中的所有嵌入圖像一直是用imagePlace支架代替,下面是創建attachement和圖像XPages:將郵件中的MIME多部分複製到另一個Richtext文檔
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);
}
}
您是否確定禁用了MIME轉換,例如通過在創建新文檔之前設置'session.setConvertMime(false);'? –
是的,我確實setConvertMime爲false –
在文檔中我可以看到嵌入的圖像爲base64編碼,但不顯示在richtext字段中 –