XPages:使用内嵌图像显示电子邮件内容

时间:2016-04-28 19:49:36

标签: java xpages mime-types lotus-domino multipart

我正在开发一个显示来自MIMEEntity的电子邮件内容的应用程序,但是,我注意到当电子邮件中有内嵌图像时,它会用图像占位符替换图像enter image description here

当有一个带有pdf附件的空电子邮件内容时,我会收到一些字符串:

%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 个答案:

答案 0 :(得分: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中显示)或getAttachmentList("someRtField") DominoDocument对象

相关问题