|
@@ -3,7 +3,6 @@ package com.fjhx.email.service.impl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.fjhx.email.config.base.BaseEntity;
|
|
|
import com.fjhx.email.config.exception.ServiceException;
|
|
@@ -16,9 +15,11 @@ import com.fjhx.email.entity.vo.MessageDetailVo;
|
|
|
import com.fjhx.email.entity.vo.MessageVo;
|
|
|
import com.fjhx.email.mapper.MailMapper;
|
|
|
import com.fjhx.email.service.*;
|
|
|
-import com.fjhx.email.utils.EmailUtil;
|
|
|
import com.fjhx.email.utils.ObsFileUtil;
|
|
|
import com.fjhx.email.utils.PageWrapper;
|
|
|
+import com.fjhx.email.utils.email.ImapUtil;
|
|
|
+import com.fjhx.email.utils.email.MessageAddress;
|
|
|
+import com.fjhx.email.utils.email.TextAndAttachment;
|
|
|
import com.sun.mail.imap.IMAPFolder;
|
|
|
import com.sun.mail.imap.IMAPMessage;
|
|
|
import com.sun.mail.imap.IMAPStore;
|
|
@@ -30,11 +31,12 @@ import org.springframework.transaction.PlatformTransactionManager;
|
|
|
import org.springframework.transaction.TransactionDefinition;
|
|
|
import org.springframework.transaction.TransactionStatus;
|
|
|
|
|
|
-import javax.mail.*;
|
|
|
-import javax.mail.internet.MimeUtility;
|
|
|
+import javax.mail.Folder;
|
|
|
+import javax.mail.Message;
|
|
|
+import javax.mail.MessagingException;
|
|
|
+import javax.mail.Part;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Date;
|
|
@@ -49,12 +51,12 @@ public class MailServiceImpl implements IMailService {
|
|
|
/**
|
|
|
* 创建一个线程池
|
|
|
*/
|
|
|
- private static final ExecutorService executorService = new ThreadPoolExecutor(
|
|
|
- 20,
|
|
|
- 50,
|
|
|
- 5,
|
|
|
- TimeUnit.MINUTES,
|
|
|
- new ArrayBlockingQueue<>(50),
|
|
|
+ private static final Executor executor = new ThreadPoolExecutor(
|
|
|
+ 12,
|
|
|
+ 36,
|
|
|
+ 60,
|
|
|
+ TimeUnit.SECONDS,
|
|
|
+ new ArrayBlockingQueue<>(36),
|
|
|
new ThreadPoolExecutor.CallerRunsPolicy()
|
|
|
);
|
|
|
|
|
@@ -104,17 +106,21 @@ public class MailServiceImpl implements IMailService {
|
|
|
@Override
|
|
|
public PageWrapper<MessageVo> getMessagePage(GetMessagePageDto dto) {
|
|
|
|
|
|
- PageWrapper<MessageVo> wrapper;
|
|
|
+ PageWrapper<MessageVo> pageWrapper;
|
|
|
+ IMAPStore imapStore;
|
|
|
IMAPFolder folder;
|
|
|
|
|
|
+ // 个人邮箱
|
|
|
if (dto.getType().equals(1)) {
|
|
|
Page<PersonalMessage> page = personalMessageService.page(dto, q -> q
|
|
|
.eq(PersonalMessage::getFolderId, dto.getFolderId())
|
|
|
.orderByDesc(PersonalMessage::getSendDate)
|
|
|
);
|
|
|
- wrapper = new PageWrapper<>(page, MessageVo.class);
|
|
|
+
|
|
|
+ pageWrapper = new PageWrapper<>(page, MessageVo.class);
|
|
|
+
|
|
|
if (page.getSize() == 0) {
|
|
|
- return wrapper;
|
|
|
+ return pageWrapper;
|
|
|
}
|
|
|
|
|
|
PersonalFolder personalFolder = personalFolderService.getById(dto.getFolderId());
|
|
@@ -123,16 +129,25 @@ public class MailServiceImpl implements IMailService {
|
|
|
}
|
|
|
|
|
|
MailboxInfo mailboxInfo = getMailboxInfo(1, personalFolder.getMailboxId());
|
|
|
- IMAPStore imapStore = EmailUtil.getIMAPStore(mailboxInfo);
|
|
|
+ imapStore = ImapUtil.getStore(
|
|
|
+ mailboxInfo.getReceiveHost(),
|
|
|
+ mailboxInfo.getMailUser(),
|
|
|
+ mailboxInfo.getMailPassword()
|
|
|
+ );
|
|
|
folder = (IMAPFolder) imapStore.getFolder(personalFolder.getName());
|
|
|
- } else {
|
|
|
+ }
|
|
|
+
|
|
|
+ // 企业邮箱
|
|
|
+ else {
|
|
|
Page<EnterpriseMessage> page = enterpriseMessageService.page(dto, q -> q
|
|
|
.eq(EnterpriseMessage::getFolderId, dto.getFolderId())
|
|
|
.orderByDesc(EnterpriseMessage::getSendDate)
|
|
|
);
|
|
|
- wrapper = new PageWrapper<>(page, MessageVo.class);
|
|
|
+
|
|
|
+ pageWrapper = new PageWrapper<>(page, MessageVo.class);
|
|
|
+
|
|
|
if (page.getSize() == 0) {
|
|
|
- return wrapper;
|
|
|
+ return pageWrapper;
|
|
|
}
|
|
|
|
|
|
EnterpriseFolder enterpriseFolder = enterpriseFolderService.getById(dto.getFolderId());
|
|
@@ -141,20 +156,37 @@ public class MailServiceImpl implements IMailService {
|
|
|
}
|
|
|
|
|
|
MailboxInfo mailboxInfo = getMailboxInfo(2, enterpriseFolder.getMailboxId());
|
|
|
- IMAPStore imapStore = EmailUtil.getIMAPStore(mailboxInfo);
|
|
|
+ imapStore = ImapUtil.getStore(
|
|
|
+ mailboxInfo.getReceiveHost(),
|
|
|
+ mailboxInfo.getMailUser(),
|
|
|
+ mailboxInfo.getMailPassword()
|
|
|
+ );
|
|
|
folder = (IMAPFolder) imapStore.getFolder(enterpriseFolder.getName());
|
|
|
}
|
|
|
|
|
|
folder.open(Folder.READ_ONLY);
|
|
|
|
|
|
- for (MessageVo messageVo : wrapper.getRows()) {
|
|
|
- Long uid = messageVo.getUid();
|
|
|
- Message message = folder.getMessageByUID(uid);
|
|
|
- String flags = EmailUtil.getFlags(message.getFlags());
|
|
|
- messageVo.setFlags(flags);
|
|
|
+ ArrayList<CompletableFuture<Void>> futureList = new ArrayList<>();
|
|
|
+ for (MessageVo messageVo : pageWrapper.getRows()) {
|
|
|
+ CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
|
|
|
+ Long uid = messageVo.getUid();
|
|
|
+ try {
|
|
|
+ Message message = folder.getMessageByUID(uid);
|
|
|
+ String flags = ImapUtil.getFlags(message.getFlags());
|
|
|
+ messageVo.setFlags(flags);
|
|
|
+ } catch (MessagingException e) {
|
|
|
+ throw new ServiceException("获取邮件是否已读失败");
|
|
|
+ }
|
|
|
+ }, executor);
|
|
|
+ futureList.add(completableFuture);
|
|
|
}
|
|
|
|
|
|
- return wrapper;
|
|
|
+ futureList.forEach(CompletableFuture::join);
|
|
|
+
|
|
|
+ ImapUtil.closeFolder(folder);
|
|
|
+ ImapUtil.closeStore(imapStore);
|
|
|
+
|
|
|
+ return pageWrapper;
|
|
|
}
|
|
|
|
|
|
@SneakyThrows
|
|
@@ -163,9 +195,9 @@ public class MailServiceImpl implements IMailService {
|
|
|
Long messageId = dto.getMessageId();
|
|
|
Integer type = dto.getType();
|
|
|
|
|
|
- String folderName;
|
|
|
Long mailboxId;
|
|
|
Integer syncStatus;
|
|
|
+ String folderName;
|
|
|
Long uid;
|
|
|
|
|
|
if (type.equals(1)) {
|
|
@@ -174,9 +206,9 @@ public class MailServiceImpl implements IMailService {
|
|
|
throw new ServiceException("没有找到邮箱");
|
|
|
}
|
|
|
|
|
|
- folderName = personalMessage.getFolderName();
|
|
|
- syncStatus = personalMessage.getSyncStatus();
|
|
|
mailboxId = personalMessage.getMailboxId();
|
|
|
+ syncStatus = personalMessage.getSyncStatus();
|
|
|
+ folderName = personalMessage.getFolderName();
|
|
|
uid = personalMessage.getUid();
|
|
|
} else {
|
|
|
EnterpriseMessage enterpriseMessage = enterpriseMessageService.getById(messageId);
|
|
@@ -184,29 +216,39 @@ public class MailServiceImpl implements IMailService {
|
|
|
throw new ServiceException("没有找到邮箱");
|
|
|
}
|
|
|
|
|
|
- folderName = enterpriseMessage.getFolderName();
|
|
|
- syncStatus = enterpriseMessage.getSyncStatus();
|
|
|
mailboxId = enterpriseMessage.getMailboxId();
|
|
|
+ syncStatus = enterpriseMessage.getSyncStatus();
|
|
|
+ folderName = enterpriseMessage.getFolderName();
|
|
|
uid = enterpriseMessage.getUid();
|
|
|
}
|
|
|
|
|
|
MessageDetailVo messageDetailVo = new MessageDetailVo();
|
|
|
+ messageDetailVo.setMessageId(messageId);
|
|
|
|
|
|
// 已同步
|
|
|
if (syncStatus.equals(1)) {
|
|
|
+
|
|
|
if (type.equals(1)) {
|
|
|
setPersonalMessageDetailVo(messageDetailVo, messageId);
|
|
|
} else {
|
|
|
setEnterpriseMessageDetailVo(messageDetailVo, messageId);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
// 未同步
|
|
|
else {
|
|
|
|
|
|
MailboxInfo mailboxInfo = getMailboxInfo(type, mailboxId);
|
|
|
|
|
|
- IMAPStore imapStore = EmailUtil.getIMAPStore(mailboxInfo);
|
|
|
- IMAPFolder folder = (IMAPFolder) imapStore.getFolder(folderName);
|
|
|
+ IMAPStore store = ImapUtil.getStore(
|
|
|
+ mailboxInfo.getReceiveHost(),
|
|
|
+ mailboxInfo.getMailUser(),
|
|
|
+ mailboxInfo.getMailPassword()
|
|
|
+ );
|
|
|
+
|
|
|
+ IMAPFolder folder = (IMAPFolder) store.getFolder(folderName);
|
|
|
+
|
|
|
folder.open(Folder.READ_WRITE);
|
|
|
|
|
|
IMAPMessage message = (IMAPMessage) folder.getMessageByUID(uid);
|
|
@@ -215,35 +257,34 @@ public class MailServiceImpl implements IMailService {
|
|
|
throw new ServiceException("没有找到邮件详情,此邮件可能已被删除");
|
|
|
}
|
|
|
|
|
|
- Flags flags = message.getFlags();
|
|
|
- if (!flags.contains(Flags.Flag.SEEN)) {
|
|
|
- flags.add(Flags.Flag.SEEN);
|
|
|
- }
|
|
|
- message.setFlags(flags, true);
|
|
|
-
|
|
|
- List<CompletableFuture<MessageDetailVo.MessageAttachment>> list = new ArrayList<>();
|
|
|
-
|
|
|
- CompletableFuture<Void> attachmentFuture = CompletableFuture.runAsync(() -> {
|
|
|
-
|
|
|
- getMessageAndAttachment(messageDetailVo, message, messageId, list);
|
|
|
-
|
|
|
- List<MessageDetailVo.MessageAttachment> messageAttachmentList =
|
|
|
- list.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
|
|
+ // 赋值邮件 正文、附件
|
|
|
+ CompletableFuture<Void> setTextAndAttachmentFuture =
|
|
|
+ CompletableFuture.runAsync(() -> setTextAndAttachment(message, messageDetailVo), executor);
|
|
|
|
|
|
- messageDetailVo.setMessageAttachmentList(messageAttachmentList);
|
|
|
+ // 赋值邮件 收件人、抄送人、密送人、回复人
|
|
|
+ CompletableFuture<Void> setAddressFuture =
|
|
|
+ CompletableFuture.runAsync(() -> setAddress(message, messageDetailVo), executor);
|
|
|
|
|
|
- }, executorService);
|
|
|
-
|
|
|
- CompletableFuture<Void> addressFuture = CompletableFuture.runAsync(() ->
|
|
|
- messageDetailVo.setMessageAddressList(EmailUtil.mailAddressList(message)), executorService);
|
|
|
+ // 设置已读
|
|
|
+ CompletableFuture<Void> setSeenFuture = CompletableFuture.runAsync(() -> {
|
|
|
+ try {
|
|
|
+ ImapUtil.setSeen(message);
|
|
|
+ } catch (MessagingException e) {
|
|
|
+ throw new ServiceException("设置邮件已读错误");
|
|
|
+ }
|
|
|
+ }, executor);
|
|
|
|
|
|
- CompletableFuture.allOf(attachmentFuture, addressFuture).join();
|
|
|
+ // 保存数据
|
|
|
+ setSeenFuture.join();
|
|
|
+ setAddressFuture.join();
|
|
|
+ setTextAndAttachmentFuture.join();
|
|
|
|
|
|
- new Thread(() -> saveMessageDetail(messageId, messageDetailVo, type)).start();
|
|
|
+ // 保存内容
|
|
|
+ executor.execute(() -> saveMessageDetail(messageId, messageDetailVo, type));
|
|
|
|
|
|
- if (folder.isOpen()) {
|
|
|
- folder.close();
|
|
|
- }
|
|
|
+ // 关闭连接
|
|
|
+ ImapUtil.closeFolder(folder);
|
|
|
+ ImapUtil.closeStore(store);
|
|
|
}
|
|
|
|
|
|
// copy一份数据,防止多线程下把文件路径前缀保存到数据库中
|
|
@@ -262,22 +303,28 @@ public class MailServiceImpl implements IMailService {
|
|
|
|
|
|
for (MailboxInfo mailboxInfo : mailboxInfoList) {
|
|
|
|
|
|
- IMAPStore imapStore = EmailUtil.getIMAPStore(mailboxInfo);
|
|
|
+ IMAPStore store = ImapUtil.getStore(
|
|
|
+ mailboxInfo.getReceiveHost(),
|
|
|
+ mailboxInfo.getMailUser(),
|
|
|
+ mailboxInfo.getMailPassword()
|
|
|
+ );
|
|
|
|
|
|
for (MailFolderInfo mailFolderInfo : mailboxInfo.getMailFolderInfoList()) {
|
|
|
- IMAPFolder folder = (IMAPFolder) imapStore.getFolder(mailFolderInfo.getName());
|
|
|
+ IMAPFolder folder = (IMAPFolder) store.getFolder(mailFolderInfo.getName());
|
|
|
folder.open(Folder.READ_WRITE);
|
|
|
int unreadMessageCount = folder.getUnreadMessageCount();
|
|
|
mailFolderInfo.setUnreadMessageCount(unreadMessageCount);
|
|
|
- if (folder.isOpen()) {
|
|
|
- folder.close();
|
|
|
- }
|
|
|
+ ImapUtil.closeFolder(folder);
|
|
|
}
|
|
|
|
|
|
+ ImapUtil.closeStore(store);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存内容
|
|
|
+ */
|
|
|
private void saveMessageDetail(Long messageId, MessageDetailVo messageDetailVo, Integer type) {
|
|
|
|
|
|
TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition);
|
|
@@ -386,6 +433,9 @@ public class MailServiceImpl implements IMailService {
|
|
|
return mailboxInfo;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存个人邮件明细
|
|
|
+ */
|
|
|
private void setPersonalMessageDetailVo(MessageDetailVo vo, Long messageId) {
|
|
|
List<PersonalMessageAddress> addressList = personalMessageAddressService.list(
|
|
|
q -> q.eq(PersonalMessageAddress::getMessageId, messageId));
|
|
@@ -400,6 +450,9 @@ public class MailServiceImpl implements IMailService {
|
|
|
vo.setContent(content.getContent());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存企业邮件明细
|
|
|
+ */
|
|
|
private void setEnterpriseMessageDetailVo(MessageDetailVo vo, Long messageId) {
|
|
|
List<EnterpriseMessageAddress> addressList = enterpriseMessageAddressService.list(
|
|
|
q -> q.eq(EnterpriseMessageAddress::getMessageId, messageId));
|
|
@@ -415,151 +468,82 @@ public class MailServiceImpl implements IMailService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 保存附件和正文
|
|
|
+ * 获取邮件 收件人、抄送人、密送人、回复人
|
|
|
*/
|
|
|
@SneakyThrows
|
|
|
- private void getMessageAndAttachment(MessageDetailVo messageDetailVo,
|
|
|
- Part part,
|
|
|
- Long messageId,
|
|
|
- List<CompletableFuture<MessageDetailVo.MessageAttachment>> completableFutureList) {
|
|
|
-
|
|
|
- // 正文:文本格式
|
|
|
- if (part.isMimeType("text/plain")) {
|
|
|
- addPlain(part, messageDetailVo);
|
|
|
- }
|
|
|
-
|
|
|
- // 正文:html格式
|
|
|
- else if (part.isMimeType("text/html")) {
|
|
|
- addHtml(part, messageDetailVo);
|
|
|
- }
|
|
|
-
|
|
|
- // 正文:html格式
|
|
|
- else if (part.isMimeType("text/html; charset=UTF-8")) {
|
|
|
- addHtmlUtf8(part, messageDetailVo);
|
|
|
- }
|
|
|
-
|
|
|
- // 大对象
|
|
|
- else if (part.isMimeType("multipart/*")) {
|
|
|
-
|
|
|
- // 复杂体邮件
|
|
|
- Multipart multipart = (Multipart) part.getContent();
|
|
|
-
|
|
|
- // 复杂体邮件包含多个邮件体
|
|
|
- int partCount = multipart.getCount();
|
|
|
-
|
|
|
- for (int i = 0; i < partCount; i++) {
|
|
|
-
|
|
|
- // 获得复杂体邮件中其中一个邮件体
|
|
|
- BodyPart bodyPart = multipart.getBodyPart(i);
|
|
|
-
|
|
|
- // 某一个邮件体也有可能是由多个邮件体组成的复杂体
|
|
|
- String disposition = bodyPart.getDisposition();
|
|
|
-
|
|
|
- // 正文:html格式
|
|
|
- if (bodyPart.isMimeType("text/html")) {
|
|
|
- addHtml(bodyPart, messageDetailVo);
|
|
|
- }
|
|
|
-
|
|
|
- // 正文:文本格式
|
|
|
- if (bodyPart.isMimeType("text/plain")) {
|
|
|
- addPlain(bodyPart, messageDetailVo);
|
|
|
- }
|
|
|
+ private void setAddress(IMAPMessage message, MessageDetailVo messageDetailVo) {
|
|
|
+
|
|
|
+ List<MessageAddress> messageAddressList = ImapUtil.getMessageAddressList(message);
|
|
|
+
|
|
|
+ List<MessageDetailVo.MessageAddress> list = messageAddressList
|
|
|
+ .stream()
|
|
|
+ .map(item -> {
|
|
|
+ MessageDetailVo.MessageAddress messageAddress = new MessageDetailVo.MessageAddress();
|
|
|
+ messageAddress.setType(item.getType());
|
|
|
+ messageAddress.setEmail(item.getEmail());
|
|
|
+ messageAddress.setPersonalName(item.getName());
|
|
|
+ return messageAddress;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ messageDetailVo.setMessageAddressList(list);
|
|
|
+ }
|
|
|
|
|
|
- // 正文:html格式
|
|
|
- else if (part.isMimeType("text/html; charset=UTF-8")) {
|
|
|
- addHtmlUtf8(part, messageDetailVo);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 获取邮件正文以及附件
|
|
|
+ */
|
|
|
+ @SneakyThrows
|
|
|
+ private void setTextAndAttachment(IMAPMessage message, MessageDetailVo vo) {
|
|
|
|
|
|
- // 附件
|
|
|
- else if (disposition != null && (disposition.equalsIgnoreCase(Part.ATTACHMENT) || disposition.equalsIgnoreCase(Part.INLINE))) {
|
|
|
- completableFutureList.add(CompletableFuture.supplyAsync(() -> getMessageAttachment(bodyPart), executorService));
|
|
|
- }
|
|
|
+ List<CompletableFuture<Void>> futureList = new ArrayList<>();
|
|
|
|
|
|
- // 大对象
|
|
|
- else if (bodyPart.isMimeType("multipart/*")) {
|
|
|
- getMessageAndAttachment(messageDetailVo, bodyPart, messageId, completableFutureList);
|
|
|
- }
|
|
|
+ List<MessageDetailVo.MessageAttachment> attachmentList = new ArrayList<>();
|
|
|
|
|
|
- // 其他类型
|
|
|
- else {
|
|
|
- String contentType = bodyPart.getContentType();
|
|
|
- if (contentType.contains("name") || contentType.contains("application")) {
|
|
|
- completableFutureList.add(CompletableFuture.supplyAsync(() -> getMessageAttachment(bodyPart), executorService));
|
|
|
+ ImapUtil.setTextAndAttachment(message, new TextAndAttachment() {
|
|
|
|
|
|
- } else {
|
|
|
- if (!contentType.equals("text/html; charset=UTF-8")) {
|
|
|
- log.error("未知文件格式:{} ,邮件id:{},待解析", contentType, messageId);
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void setPlain(String plain) {
|
|
|
+ if (plain != null) {
|
|
|
+ if (ObjectUtil.notEqual(vo.getMimeType(), "text/html")) {
|
|
|
+ vo.setContent(plain);
|
|
|
+ vo.setMimeType("text/plain");
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public void setHtml(String html) {
|
|
|
+ vo.setContent(html);
|
|
|
+ vo.setMimeType("text/html");
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // rfc822
|
|
|
- else if (part.isMimeType("message/rfc822")) {
|
|
|
- getMessageAndAttachment(messageDetailVo, (Part) part.getContent(), messageId, completableFutureList);
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void setAttachment(String fileName, InputStream is) {
|
|
|
|
|
|
- // 未知格式
|
|
|
- else {
|
|
|
- log.error("未知文件格式:{} ,邮件id:{},待解析", part.getContentType(), messageId);
|
|
|
- }
|
|
|
+ CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
|
|
|
|
|
|
- }
|
|
|
+ String url = ObsFileUtil.uploadFile(fileName, is);
|
|
|
+ MessageDetailVo.MessageAttachment messageAttachment = new MessageDetailVo.MessageAttachment();
|
|
|
+ messageAttachment.setUrl(url);
|
|
|
+ messageAttachment.setName(fileName);
|
|
|
+ attachmentList.add(messageAttachment);
|
|
|
|
|
|
- @SneakyThrows
|
|
|
- private MessageDetailVo.MessageAttachment getMessageAttachment(Part part) {
|
|
|
- InputStream is = part.getInputStream();
|
|
|
- String fileName = decodeText(part.getFileName());
|
|
|
+ }, executor);
|
|
|
|
|
|
- String url = ObsFileUtil.uploadFile(fileName, is);
|
|
|
+ futureList.add(future);
|
|
|
|
|
|
- MessageDetailVo.MessageAttachment messageAttachment = new MessageDetailVo.MessageAttachment();
|
|
|
- messageAttachment.setUrl(url);
|
|
|
- messageAttachment.setName(fileName);
|
|
|
- return messageAttachment;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- private void addHtml(Part part, MessageDetailVo messageDetailVo) throws MessagingException, IOException {
|
|
|
- Object content = part.getContent();
|
|
|
- if (content != null) {
|
|
|
- messageDetailVo.setContent(content.toString());
|
|
|
- } else {
|
|
|
- messageDetailVo.setContent(StringPool.EMPTY);
|
|
|
- }
|
|
|
- messageDetailVo.setMimeType("text/html");
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void unknown(Part part) throws MessagingException, IOException {
|
|
|
+ log.error("id为 {} 的邮件存在未知类型:{}", vo.getMessageId(), part.getContentType());
|
|
|
+ }
|
|
|
|
|
|
- private void addHtmlUtf8(Part part, MessageDetailVo messageDetailVo) throws MessagingException, IOException {
|
|
|
- Object content = part.getContent();
|
|
|
- if (content != null) {
|
|
|
- messageDetailVo.setContent(content.toString());
|
|
|
- } else {
|
|
|
- messageDetailVo.setContent(StringPool.EMPTY);
|
|
|
- }
|
|
|
- messageDetailVo.setMimeType("text/html; charset=UTF-8");
|
|
|
- }
|
|
|
+ });
|
|
|
|
|
|
- private void addPlain(Part part, MessageDetailVo messageDetailVo) throws MessagingException, IOException {
|
|
|
- Object content = part.getContent();
|
|
|
- if (content != null) {
|
|
|
- if (ObjectUtil.notEqual(messageDetailVo.getMimeType(), "text/html")) {
|
|
|
- messageDetailVo.setContent(content.toString());
|
|
|
- messageDetailVo.setMimeType("text/plain");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ futureList.forEach(CompletableFuture::join);
|
|
|
+ vo.setMessageAttachmentList(attachmentList);
|
|
|
|
|
|
- /**
|
|
|
- * 文本解码
|
|
|
- */
|
|
|
- private String decodeText(String encodeText) throws UnsupportedEncodingException {
|
|
|
- if (encodeText == null || StringPool.EMPTY.equals(encodeText)) {
|
|
|
- return StringPool.EMPTY;
|
|
|
- } else {
|
|
|
- return MimeUtility.decodeText(encodeText);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
}
|