Ckeditor 接收邮件正文时,如何从多部分正文中提取图像

Ckeditor 接收邮件正文时,如何从多部分正文中提取图像,ckeditor,jakarta-mail,mime-message,mime-mail,Ckeditor,Jakarta Mail,Mime Message,Mime Mail,我的应用程序实际上具有邮件发送/接收功能 在接收邮件时,我无法查看从outlook发送的内联图像 有人能帮我吗?我怎样才能捕捉图像并始终可用 我有如下java代码 try (InputStream stream = new ByteArrayInputStream(Base64 .getMimeDecoder().decode(mail))) { MimeMessage message = new MimeMessage(null, stream);

我的应用程序实际上具有邮件发送/接收功能

在接收邮件时,我无法查看从outlook发送的内联图像

有人能帮我吗?我怎样才能捕捉图像并始终可用

我有如下java代码

try (InputStream stream = new ByteArrayInputStream(Base64
            .getMimeDecoder().decode(mail))) {

        MimeMessage message = new MimeMessage(null, stream);
        Object messageContent = message.getContent();
        if (messageContent instanceof String) {
            body = (String) messageContent;
        } else if (messageContent instanceof MimeMultipart) {
            content = (MimeMultipart) messageContent;
            for (int i = 0; i < content.getCount(); i++) {
                BodyPart bodyPart = content.getBodyPart(i);
                String disposition = bodyPart.getDisposition();

                if (disposition == null
                        || disposition
                                .equalsIgnoreCase(Part.INLINE)) {
                    Object object = bodyPart.getContent();
                    if (object instanceof String) {
                        body = object.toString();
                    } else if (object instanceof MimeMultipart) {
                        MimeMultipart mimeMultipart = (MimeMultipart) object;
                        String plainBody = null;
                        String htmlBody = null;

                        for (int j = 0; j < mimeMultipart.getCount(); j++) {
                            BodyPart multipartBodyPart = mimeMultipart
                                    .getBodyPart(j);
                            String multipartDisposition = multipartBodyPart
                                    .getDisposition();
                            String multipartContentType = multipartBodyPart
                                    .getContentType();
                            if (multipartDisposition == null
                                    && multipartContentType != null) {
                                if (multipartContentType
                                        .contains(MediaType.TEXT_HTML)) {
                                    htmlBody = multipartBodyPart
                                            .getContent().toString();
                                } else if (multipartContentType
                                        .contains(MediaType.TEXT_PLAIN)) {
                                    plainBody = multipartBodyPart
                                            .getContent().toString();
                                }
                            }
                        }
                        if (htmlBody != null) {
                            body = htmlBody;
                        } else {
                            body = plainBody;
                        }
                    }
                }
            }
        }
try(InputStream=newbytearrayinputstream(Base64
.getMimeDecoder().decode(邮件))){
MimeMessage message=新MimeMessage(空,流);
对象messageContent=message.getContent();
if(messageContent instanceof String){
body=(字符串)messageContent;
}else if(MimeMultipart的messageContent实例){
content=(MimeMultipart)messageContent;
for(int i=0;i
客户端我正在使用CKEditor处理电子邮件正文数据


非常感谢。

我从下面分享的示例中得到了一个解决方案

但是,这个例子解释了如何在body中找到图像并存储。 我还做了以下工作来替换src

` 模式htmltag=Pattern.compile(“]src=\”[^>]>(.?)”; Pattern link=Pattern.compile(“src=\”[^>]\“>”); 字符串s1=“”

Matcher-tagmatch=htmltag.Matcher(s1);
列表链接=新建ArrayList();
while(tagmatch.find()){
Matcher Matcher=link.Matcher(tagmatch.group());
matcher.find();
字符串link1=matcher.group().replaceFirst(“src=\”,“”)
.replaceFirst(“\”>”,“”)
.replaceFirst(“\”[\\s]?target=\”[a-zA-Z_0-9]*”,“”);
links.add(link1);
s1=s1.replaceAll(link1,“C:\\//kim\\\//image.jpg”);
}
`

除此之外,我还要进行Base64编码,这样我就不需要存储在文件系统中

encodedfileString=Base64.getEncoder().encodeToString(bArray);

有了这些,我可以总结说,我找到了解决问题的办法。谢谢

    Matcher tagmatch = htmltag.matcher(s1);
    List<String> links = new ArrayList<String>();
    while (tagmatch.find()) {
        Matcher matcher = link.matcher(tagmatch.group());
        matcher.find();
        String link1 = matcher.group().replaceFirst("src=\"", "")
                .replaceFirst("\">", "")
                .replaceFirst("\"[\\s]?target=\"[a-zA-Z_0-9]*", "");
        links.add(link1);
        s1 = s1.replaceAll(link1, "C:\\//Initiatives_KM\\//image.jpg");            

    }