简体   繁体   English

java mail polling从邮件中读取内联或嵌入的图像(表情符号)

[英]java mail polling read inline or embedded images (smileys) from the mail

I am new in java mail polling and i have create one type of conversation application in this if user send mail to each other then i read that from them mail and post as new message in conversation. 我是java邮件轮询的新手,如果用户向对方发送邮件,我会创建一种类型的会话应用程序,然后我从他们那里读取邮件并在对话中作为新邮件发布。

now issue is that, what to do if there is smileys, inline or embedded images. 现在的问题是,如果有笑脸,内联或嵌入图像该怎么办。 for example in gmail mail we can send smileys also now how read that smile and post on to the over page. 例如在gmail邮件中我们也可以发送表情符号,现在如何阅读那个微笑并发布到页面上。 please give me some proper solution for this. 请给我一些适当的解决方案。

这种类型的表情。

I have found the solution to download the inline images + icons from the mail. 我找到了从邮件中下载内嵌图像+图标的解决方案。

  private String getAttachments(Message message, HttpServletRequest request) throws MessagingException, IOException {
    String contentType = message.getContentType();
    String attachFiles="";
    if (contentType.contains("multipart")) {
        // content may contain attachments
        Multipart multiPart = (Multipart) message.getContent();
        int numberOfParts = multiPart.getCount();
        for (int partCount = 0; partCount < numberOfParts; partCount++) {
            MimeBodyPart part = (MimeBodyPart) multiPart.getBodyPart(partCount);
            String disposition =part.getDisposition();
            String file=part.getFileName();
            //External attachments
            if (disposition != null && Part.ATTACHMENT.equalsIgnoreCase(disposition)) {
                // this part is attachment
                String fileName = new Date().getTime()+ "_"+ part.getFileName().replaceAll("[^a-zA-Z0-9\\._]+", "_"); //To make attachment name uniq we are adding current datatime before name.
                attachFiles += fileName + ","; //concrete all attachment's name with comma separated.                  
                part.saveFile(new File(request
                        .getSession()
                        .getServletContext()
                        .getRealPath(
                                "/WEB-INF/attechments/"
                                        + fileName)));   //To save the attachment file at specific location.
      //                    LOG.info("\n\t Path :- " +request.getSession().getServletContext().getRealPath("/WEB-INF/attechments/" + fileName));
            }
            //Inline Attachments
            else if (disposition != null && Part.INLINE.equalsIgnoreCase(disposition)) {
                // this part is attachment
                String fileName = new Date().getTime()+ "_"+ part.getFileName().replaceAll("[^a-zA-Z0-9\\._]+", "_"); //To make attachment name uniq we are adding current datatime before name.
              //  attachFiles += fileName + ","; //concrete all attachment's name with comma separated.                  
                part.saveFile(new File(request
                        .getSession()
                        .getServletContext()
                        .getRealPath(
                                "/WEB-INF/attechments/"
                                        + fileName)));   //To save the attachment file at specific location.
 //                    LOG.info("\n\t Path :- " +request.getSession().getServletContext().getRealPath("/WEB-INF/attechments/" + fileName));
            }
            //Inline icons and smileys
            else if(file != null && disposition==null)
            {
                String fileName = new Date().getTime()+ "_"+ part.getFileName().replaceAll("[^a-zA-Z0-9\\._]+", "_");
            //  attachFiles += fileName + ","; //concrete all attachment's name with comma separated.
                 part.saveFile(new File(request
                        .getSession()
                        .getServletContext()
                        .getRealPath(
                                "/WEB-INF/attechments/"
                                        + fileName))); 

            }
        }
    }
     if (attachFiles.length() > 1) {
         attachFiles = attachFiles.substring(0, attachFiles.length() - 1);
     }
    return attachFiles;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM