2017-07-14 52 views
0

試圖通過將郵件正文保存到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); 
     } 
    } 
+0

您是否確定禁用了MIME轉換,例如通過在創建新文檔之前設置'session.setConvertMime(false);'? –

+0

是的,我確實setConvertMime爲false –

+0

在文檔中我可以看到嵌入的圖像爲base64編碼,但不顯示在richtext字段中 –

回答

0

當你創建一個新的MIME條目,你會得到新的邊界字符串,其作爲密鑰嵌入圖像的方法。檢查傳入圖像的src屬性的確切格式。

您需要調整這些屬性以使圖像正確顯示。清理HTML沒有什麼好玩的,需要一定的指針從這篇文章:

https://wissel.net/blog/2017/04/from-blogsphere-to-a-static-site-part-2-cleaning-up-the-html.html

最終(需要檢查,不知道把我的頭),您可以指定邊界,並節省您的HTML清理

0

一個解決方案是Base64對嵌入式圖像進行編碼,而不是將嵌入式圖像作爲附件添加。在這裏看到我的答案:https://stackoverflow.com/a/19328276/785061

+0

圖像已經作爲Base64存儲在文檔中,但是當我使用maildocument.getEmbeddedImagesList(「Body」)時,它會返回空列表 –

相關問題