gpt4 book ai didi

java邮件轮询从邮件中读取内联或嵌入图像(笑脸)

转载 作者:搜寻专家 更新时间:2023-11-01 03:22:34 29 4
gpt4 key购买 nike

我是 java 邮件轮询的新手,如果用户互相发送邮件,我会在其中创建一种对话应用程序,然后我会从他们的邮件中读取该邮件并将其作为对话中的新消息发布。

现在的问题是,如果有笑脸、内联或嵌入图像怎么办。例如,在 gmail 邮件中,我们现在也可以发送笑脸,如何阅读那个笑脸并将其张贴到页面上。请给我一些适当的解决方案。

This type of the smileys.

最佳答案

我找到了从邮件中下载内联图像 + 图标的解决方案。

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

关于java邮件轮询从邮件中读取内联或嵌入图像(笑脸),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26173888/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com