xpages:将mime多部分从mail复制到另一个richtext文档

6jygbczu  于 2021-07-09  发布在  Java
关注(0)|答案(2)|浏览(301)

尝试通过将邮件正文保存到richtext项目中,从电子邮件创建新的xpages文档时,我的文档会正确创建附件正文也会创建,但文档中嵌入的所有图像都会替换为imageplaceholder,下面是创建附件和图像的方法

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);
        }   
    }
czq61nw1

czq61nw11#

创建新的mime条目时,会得到新的边界字符串,这些字符串用作嵌入图像的键。检查 src 确切格式的传入图像的属性。
您需要调整这些属性以使图像正确显示。清理html并不有趣,请参考本文中的一些提示:
https://wissel.net/blog/2017/04/from-blogsphere-to-a-static-site-part-2-cleaning-up-the-html.html
最终(需要检查,我不知道从我的头)你可以指定边界和保存你的html清理

gudnpqoy

gudnpqoy2#

一种解决方案是对嵌入的图像进行base64编码,而不是将嵌入的图像作为附件添加。请看我的答案:https://stackoverflow.com/a/19328276/785061.

相关问题