2016-04-28 62 views
1

我上的應用程序的工作,顯示從MIMEEntity電子郵件的內容,但是,我注意到,當有電子郵件中的內嵌圖像,它的圖像佔位符代替圖像enter image description here的XPages:顯示郵件內容與內嵌圖片

和當曾經有一個空的電子郵件內容與PDF attachement,我得到了一些字符串,如:

%PDF-1.3 
%ÔÒ¤Ë 
%RSTXPDF3 Parameters: ERSXh 
2 0 obj 
<< 
/Type /FontDescriptor 
/Ascent 720 
/CapHeight 660 
/Descent -270 
/Flags 32 
/FontBBox [-177 -269 1123 866] 
/FontName /Helvetica 
/ItalicAngle 0 
/StemV 105 
>> 
endobj 
3 0 obj 
/WinAnsiEncoding 
endobj 
4 0 obj 
<< 
%Devtype PDF1  Font HELVE normal Lang DE 
/Type /Font 
/Subtype /Type1 
/BaseFont /Helvetica 
/Name /F001 
/Encoding 3 0 R 
/FirstChar 32 
/LastChar 255 
%Charwidth values from PDF1 HELVE 080 normal 
/Widths 
[ 278 275 356 556 556 888 669 225 331 331 388 581 275 331 275 275 556 556 556 556 556 556 556 556 556 556 275 275 581 581 581 556 1013 669 669 725 725 669 613 775 725 275 500 669 556 831 725 775 669 775 725 669 613 725 669 944 669 669 613 275 275 275 469 
556 225 556 556 500 556 556 275 556 556 225 225 500 225 831 556 556 556 556 331 500 275 556 500 725 500 500 500 331 263 331 581 0 556 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 331 556 556 556 556 263 556 331 738 369 556 581 0 738 
331 331 581 331 331 331 500 538 275 331 331 363 556 831 831 831 613 669 669 669 669 669 669 1000 725 669 669 669 669 275 275 275 275 725 725 775 775 775 775 775 581 775 725 725 725 725 669 669 613 556 556 556 556 556 556 888 500 556 556 556 556 275 275 
275 275 556 556 556 556 556 556 556 581 613 556 556 556 556 500 556 500] 
/FontDescriptor 2 0 R 
>> 
endobj 
5 0 obj 
<< 
/Type /FontDescriptor 
/Ascent 720... 

下面是我的代碼:

public static String getEmailContent(MIMEEntity mime) throws NotesException { 
     String text = null; 
     String html = null; 
     if (mime != null) { 
      if ("multipart".equalsIgnoreCase(mime.getContentType())) { 
       MIMEEntity child = mime.getFirstChildEntity(); 
       while (child != null) { 
        String mimeType = child.getContentType() + "/" + child.getContentSubType(); 
        child.decodeContent(); 
        String contentDecoded = child.getContentAsText(); 
        if ("text/html".equals(mimeType)) { 
         if (html == null) {       
          html = contentDecoded;      
         } 
        } else if ("text/plain".equals(mimeType)) { 
         if (text == null) { 
          text = "<pre>" + contentDecoded + "</pre>"; 
         } 
        } 
        // get next Child-Element 
        MIMEEntity tmpChild = child.getFirstChildEntity(); 
        if (tmpChild == null) { 
         tmpChild = child.getNextSibling(); 
         if (tmpChild == null) { 
          tmpChild = child.getParentEntity(); 
          if (tmpChild != null) 
           tmpChild = tmpChild.getNextSibling();      } 
        } 
        child = tmpChild; 
       } 
      } else if ("text".equalsIgnoreCase(mime.getContentType())) { 
       String subType = mime.getContentSubType(); 
       mime.decodeContent(); 
       String contentDecoded = mime.getContentAsText(); 
       if ("html".equalsIgnoreCase(subType)) { 
        if (html == null) { 
         html = contentDecoded; 
        } 
       } else if ("plain".equalsIgnoreCase(mime.getContentSubType())) { 
        if (text == null) { 
         text = "<pre>" + contentDecoded + "</pre>"; 
        } 
       } 
      } else { 
       mime.decodeContent(); 
       text = "<pre>" + mime.getContentAsText() + "</pre>"; 
      } 
     } 
     if (html != null) { 

      return html; 
     } else { 

      return text; 
     } 
    } 

我不知道我做錯了什麼,我需要一些幫助

回答

1

這是一個相當深的兔子洞,我想。如果要顯示通過漫遊MIME樹導出的圖像,您將處於掛鉤狀態,以便通過CID提取引用的附件並將其填充到原始HTML中,或者作爲data URI或作爲將提供的另一個腳本的引用圖像。

您可能最擅長使用IBM的DominoDocument類。如果您首先使用的是xp:dominoDocument數據源,那麼您已經設置好了;否則,您可以使用DominoDocument.wrap方法手動打包它(請參閱the Javadoc)。一旦你有了這些,我相信你可以使用getValue("someRtField").toString()來獲得一個有用的HTML表示,而不管原始格式(CD或MIME),它將使用IBM的servlet來顯示嵌入式圖像。

我認爲您仍然會丟失附件參考,但您可以使用xp:fileDownload控件(如果目標是在XPage中呈現)或DominoDocument對象上的getAttachmentList("someRtField")