【问题标题】:XPages:Display Email content with inline ImagesXPages:使用内嵌图像显示电子邮件内容
【发布时间】:2016-04-28 19:49:36
【问题描述】:

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

当有一个带有 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;
        }
    }

我不知道我做错了什么,我需要一些帮助

【问题讨论】:

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


    【解决方案1】:

    我认为这是一个相当深的兔子洞。如果您想显示从 MIME 树中获取的图像,您需要通过 CID 提取引用的附件并将它们填充到原始 HTML 中,或者作为 data URI 或者作为对另一个脚本的引用提供图片。

    您最好使用 IBM 的 DominoDocument 类。如果您开始使用xp:dominoDocument 数据源,那么您已经准备就绪;否则,您可以使用DominoDocument.wrap 方法手动包装它(请参阅the Javadoc)。一旦你有了它,我相信你可以使用getValue("someRtField").toString() 来获得有用的 HTML 表示,而不管原始格式(CD 或 MIME)如何,它将使用 IBM 的 servlet 来显示嵌入的图像。

    我认为您仍然会丢失附件引用,但您可以在 DominoDocument 对象上使用 xp:fileDownload 控件(如果目标是 XPage 中的演示)或 getAttachmentList("someRtField")

    【讨论】:

      猜你喜欢
      • 2016-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多