2014-10-03 34 views
4

我是java郵件投票新手,如果用戶向對方發送郵件,我已經創建了一種類型的對話應用程序,然後我從中讀取郵件和在會話中作爲新消息發佈。java郵件輪詢從郵件中讀取內嵌或嵌入圖像(表情符號)

現在的問題是,如果有笑臉,內嵌或嵌入圖像該怎麼辦。例如在Gmail郵件中,我們現在也可以發送表情符號,如何閱讀該笑臉併發布到頁面上。請給我一些適當的解決方案。

This type of the smileys.

回答

2

我已經找到了解決方案,從郵件下載內嵌圖像+圖標。

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; 
} 
+1

我現在只有一個問題,如何改變我原來的路徑 – 2014-10-07 06:01:17

+0

烏代A. Navapara感謝名單,有呈三角問題,我自己的錯誤感謝發現你的代碼。然而,你是否設法想出一些方法來如何用你的圖像替換帶有cid的img? – thorinkor 2017-12-19 13:37:39