|
@@ -1,19 +1,13 @@
|
|
|
package com.storlead.mail.service.impl;
|
|
package com.storlead.mail.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.storlead.framework.common.constant.CommonConstant;
|
|
import com.storlead.framework.common.constant.CommonConstant;
|
|
|
import com.storlead.framework.common.util.*;
|
|
import com.storlead.framework.common.util.*;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.storlead.framework.common.util.encryptor.AccessKeyEncryptor;
|
|
|
|
|
import com.storlead.framework.redis.RedisService;
|
|
import com.storlead.framework.redis.RedisService;
|
|
|
-import com.storlead.mail.connection.MailConnection;
|
|
|
|
|
-import com.storlead.mail.connection.client.MailConnectionUtil;
|
|
|
|
|
-import com.storlead.mail.connection.config.MailProperties;
|
|
|
|
|
import com.storlead.mail.pojo.entity.*;
|
|
import com.storlead.mail.pojo.entity.*;
|
|
|
import com.storlead.mail.pojo.vo.CustomerEmailVo;
|
|
import com.storlead.mail.pojo.vo.CustomerEmailVo;
|
|
|
import com.storlead.mail.pojo.vo.CustomerMailVO;
|
|
import com.storlead.mail.pojo.vo.CustomerMailVO;
|
|
@@ -28,9 +22,6 @@ import com.storlead.mail.pojo.MailListDTO;
|
|
|
import com.storlead.mail.pojo.SendMailDTO;
|
|
import com.storlead.mail.pojo.SendMailDTO;
|
|
|
import com.storlead.mail.service.*;
|
|
import com.storlead.mail.service.*;
|
|
|
import com.storlead.mail.service.impl.support.MailDataSourceServiceImpl;
|
|
import com.storlead.mail.service.impl.support.MailDataSourceServiceImpl;
|
|
|
-import com.storlead.mail.util.EmailHelper;
|
|
|
|
|
-import com.storlead.mail.util.EmailSenderWithThreadLocal;
|
|
|
|
|
-import com.storlead.mail.util.ReceiveMailQueueThreadPool;
|
|
|
|
|
import com.sun.mail.imap.IMAPFolder;
|
|
import com.sun.mail.imap.IMAPFolder;
|
|
|
import com.sun.mail.pop3.POP3Folder;
|
|
import com.sun.mail.pop3.POP3Folder;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
import lombok.extern.log4j.Log4j2;
|
|
@@ -38,9 +29,6 @@ import org.apache.commons.compress.utils.FileNameUtils;
|
|
|
import org.springframework.core.env.Environment;
|
|
import org.springframework.core.env.Environment;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
-import javax.activation.DataHandler;
|
|
|
|
|
-import javax.activation.DataSource;
|
|
|
|
|
-import javax.activation.FileDataSource;
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import javax.mail.*;
|
|
import javax.mail.*;
|
|
|
import javax.mail.internet.*;
|
|
import javax.mail.internet.*;
|
|
@@ -50,15 +38,12 @@ import java.lang.reflect.Method;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.Paths;
|
|
|
-import java.time.LocalDate;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
|
-import java.time.temporal.ChronoUnit;
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.ConcurrentMap;
|
|
import java.util.concurrent.ConcurrentMap;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.concurrent.locks.Lock;
|
|
import java.util.concurrent.locks.Lock;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
@@ -84,33 +69,15 @@ public class EmailsServiceImpl extends MailDataSourceServiceImpl<EmailsMapper, E
|
|
|
*/
|
|
*/
|
|
|
private final ConcurrentMap<Long, Boolean> processedDownloadMailIds = new ConcurrentHashMap<>();
|
|
private final ConcurrentMap<Long, Boolean> processedDownloadMailIds = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
- @Resource
|
|
|
|
|
- private SmtpPopSettingsService popSettingsService;
|
|
|
|
|
-
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private MailFileProperties mailFileProperties;
|
|
private MailFileProperties mailFileProperties;
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private MailAttachmentService mailAttachmentService;
|
|
private MailAttachmentService mailAttachmentService;
|
|
|
|
|
|
|
|
- @Resource
|
|
|
|
|
- private MailTempAttachmentService tempAttachmentService;
|
|
|
|
|
-
|
|
|
|
|
- @Resource
|
|
|
|
|
- private MailDelayPullRecordService delayPullRecordService;
|
|
|
|
|
-
|
|
|
|
|
- @Resource
|
|
|
|
|
- private EmailSenderWithThreadLocal senderWithThreadLocal;
|
|
|
|
|
-
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private RedisService redisService;
|
|
private RedisService redisService;
|
|
|
|
|
|
|
|
- @Resource
|
|
|
|
|
- private EmailBlacklistRecordService blackListService;
|
|
|
|
|
-
|
|
|
|
|
- @Resource
|
|
|
|
|
- private EmailFolderRuleService folderRuleService;
|
|
|
|
|
-
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private Environment environment;
|
|
private Environment environment;
|
|
|
|
|
|
|
@@ -123,154 +90,7 @@ public class EmailsServiceImpl extends MailDataSourceServiceImpl<EmailsMapper, E
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public SendStatus sendEmail(SendMailDTO dto, SmtpPopSettingsEntity smtpPop) {
|
|
public SendStatus sendEmail(SendMailDTO dto, SmtpPopSettingsEntity smtpPop) {
|
|
|
-// String active = environment.getProperty("spring.profiles.active");
|
|
|
|
|
-// if("dev".equals(active)) {
|
|
|
|
|
-// return SendStatus.SUCCESS;
|
|
|
|
|
-// }
|
|
|
|
|
- try {
|
|
|
|
|
- if(Objects.isNull(dto.getRecipientCcls())) {
|
|
|
|
|
- dto.setRecipientCcls(new ArrayList<>());
|
|
|
|
|
- }
|
|
|
|
|
- if(Objects.isNull(dto.getRecipientBccls())) {
|
|
|
|
|
- dto.setRecipientBccls(new ArrayList<>());
|
|
|
|
|
- }
|
|
|
|
|
- if(Objects.isNull(dto.getRecipientls())) {
|
|
|
|
|
- dto.setRecipientls(new ArrayList<>());
|
|
|
|
|
- }
|
|
|
|
|
- String fromAddress = smtpPop.getEmailAddress();
|
|
|
|
|
- String fromNickName = smtpPop.getSenderNickName();
|
|
|
|
|
-
|
|
|
|
|
- Session session = getSendEmailsSession(smtpPop);
|
|
|
|
|
- InternetAddress [] froms = new InternetAddress[dto.getRecipientls().size()];
|
|
|
|
|
- for (int i = 0; i < dto.getRecipientls().size(); i++) {
|
|
|
|
|
- froms[i] = new InternetAddress(dto.getRecipientls().get(i));
|
|
|
|
|
- }
|
|
|
|
|
- InternetAddress [] fromsCC = new InternetAddress[dto.getRecipientCcls().size()];
|
|
|
|
|
- for (int i = 0; i < dto.getRecipientCcls().size(); i++) {
|
|
|
|
|
- fromsCC[i] = new InternetAddress(dto.getRecipientCcls().get(i));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- InternetAddress [] fromsBCC = new InternetAddress[dto.getRecipientBccls().size()];
|
|
|
|
|
- for (int i = 0; i < dto.getRecipientBccls().size(); i++) {
|
|
|
|
|
- fromsBCC[i] = new InternetAddress(dto.getRecipientBccls().get(i));
|
|
|
|
|
- }
|
|
|
|
|
- Transport transport = session.getTransport("smtp");
|
|
|
|
|
- int sizeInBytes = 0;
|
|
|
|
|
- try {
|
|
|
|
|
- MimeMessage message = new MimeMessage(session);
|
|
|
|
|
- if (Objects.nonNull(froms) && froms.length > 0) {
|
|
|
|
|
- message.setRecipients(Message.RecipientType.TO,froms);
|
|
|
|
|
- }
|
|
|
|
|
- if (Objects.nonNull(fromsCC) && fromsCC.length > 0) {
|
|
|
|
|
- message.setRecipients(Message.RecipientType.CC,fromsCC);
|
|
|
|
|
- }
|
|
|
|
|
- if (Objects.nonNull(fromsBCC) && fromsBCC.length > 0) {
|
|
|
|
|
- message.setRecipients(Message.RecipientType.BCC,fromsBCC);
|
|
|
|
|
- }
|
|
|
|
|
- if (CollectionUtils.isEmpty(dto.getFileIds()) && CollectionUtils.isEmpty(dto.getOldfileIds())) {
|
|
|
|
|
- message.setFrom(new InternetAddress(fromAddress));
|
|
|
|
|
- message.setSubject(dto.getSubject());
|
|
|
|
|
-
|
|
|
|
|
- Multipart multipart = new MimeMultipart();
|
|
|
|
|
-// // 消息正文
|
|
|
|
|
- BodyPart messageBodyPart1 = new MimeBodyPart();
|
|
|
|
|
- List<MimeBodyPart> imageParts = new ArrayList<>();
|
|
|
|
|
- String updatedHtmlContent = EmailHelper.convertImageUrlsToCidBodyPart(dto.getContent(),imageParts,mailFileProperties.getPath().getJpeg(),multipart);
|
|
|
|
|
- messageBodyPart1.setContent(updatedHtmlContent, "text/html; charset=UTF-8");
|
|
|
|
|
- multipart.addBodyPart(messageBodyPart1);
|
|
|
|
|
- // 发送完整的消息部分
|
|
|
|
|
- message.setContent(multipart);
|
|
|
|
|
- // 获取邮件大小
|
|
|
|
|
- sizeInBytes = dto.getContent().length();
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
-
|
|
|
|
|
- message.setFrom(new InternetAddress(fromAddress));
|
|
|
|
|
-
|
|
|
|
|
- message.setDescription(dto.getRemark());
|
|
|
|
|
- // 设置邮件主题
|
|
|
|
|
- message.setSubject(dto.getSubject());
|
|
|
|
|
- // 创建消息部分
|
|
|
|
|
- Multipart multipart = new MimeMultipart();
|
|
|
|
|
-// // 消息正文
|
|
|
|
|
- BodyPart messageBodyPart1 = new MimeBodyPart();
|
|
|
|
|
-
|
|
|
|
|
- List<MimeBodyPart> imageParts = new ArrayList<>();
|
|
|
|
|
- String updatedHtmlContent = EmailHelper.convertImageUrlsToCidBodyPart(dto.getContent(),imageParts,mailFileProperties.getPath().getJpeg(),multipart);
|
|
|
|
|
- messageBodyPart1.setContent(updatedHtmlContent, "text/html; charset=UTF-8");
|
|
|
|
|
- multipart.addBodyPart(messageBodyPart1);
|
|
|
|
|
- // 设置文本消息部分
|
|
|
|
|
- if (!CollectionUtils.isEmpty(dto.getFileIds())) {
|
|
|
|
|
- LambdaQueryWrapper fileWrapper = new LambdaQueryWrapper<MailTempAttachmentEntity>().in(MailTempAttachmentEntity::getId,dto.getFileIds());
|
|
|
|
|
- List<MailTempAttachmentEntity> tempAttachment = tempAttachmentService.list(fileWrapper);
|
|
|
|
|
- for (MailTempAttachmentEntity attachment : tempAttachment) {
|
|
|
|
|
- BodyPart messageBodyPart = new MimeBodyPart();
|
|
|
|
|
- String filePath = mailFileProperties.getPath().getPath() + attachment.getFilePath();
|
|
|
|
|
- String fileName = attachment.getFileName()+"."+attachment.getFileExt();
|
|
|
|
|
- DataSource fileSource = new FileDataSource(filePath);
|
|
|
|
|
- messageBodyPart.setDataHandler(new DataHandler(fileSource));
|
|
|
|
|
- messageBodyPart.setFileName(fileName);
|
|
|
|
|
- multipart.addBodyPart(messageBodyPart);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- if (!CollectionUtils.isEmpty(dto.getOldfileIds())) {
|
|
|
|
|
- LambdaQueryWrapper fileMailWrapper = new LambdaQueryWrapper<MailTempAttachmentEntity>().in(MailTempAttachmentEntity::getId,dto.getOldfileIds());
|
|
|
|
|
- List<MailAttachmentEntity> mailAttachments = mailAttachmentService.list(fileMailWrapper);
|
|
|
|
|
- for (MailAttachmentEntity attachment : mailAttachments) {
|
|
|
|
|
- BodyPart messageBodyPart = new MimeBodyPart();
|
|
|
|
|
- String filePath = mailFileProperties.getPath().getPath() + attachment.getFilePath();
|
|
|
|
|
- String fileName = attachment.getFileName()+"."+attachment.getFileExt();
|
|
|
|
|
- DataSource fileSource = new FileDataSource(filePath);
|
|
|
|
|
- messageBodyPart.setDataHandler(new DataHandler(fileSource));
|
|
|
|
|
- messageBodyPart.setFileName(fileName);
|
|
|
|
|
- multipart.addBodyPart(messageBodyPart);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- // 发送完整的消息部分
|
|
|
|
|
- message.setContent(multipart);
|
|
|
|
|
- // 获取邮件大小
|
|
|
|
|
- sizeInBytes = dto.getContent().length();
|
|
|
|
|
- // 发送消�?
|
|
|
|
|
- }
|
|
|
|
|
- /**
|
|
|
|
|
- * 发送成�?存储邮箱 replyEmailId null
|
|
|
|
|
- */
|
|
|
|
|
- if (Integer.valueOf(1).equals(dto.getIsReceipt())) {
|
|
|
|
|
- message.addHeader("Disposition-Notification-To", smtpPop.getEmailAddress());
|
|
|
|
|
- }
|
|
|
|
|
- Long replyMsgId = dto.getReplyMsgId();
|
|
|
|
|
- EmailsEntity email = saveSendEmails(dto,fromAddress,fromNickName,replyMsgId,Long.valueOf(sizeInBytes));
|
|
|
|
|
- email.setIsOnlyHead(0);
|
|
|
|
|
- email.setSmtpPopId(smtpPop.getId());
|
|
|
|
|
- log.error("senderWithThreadLocal - saveOrUpdate----邮件");
|
|
|
|
|
- if(this.saveOrUpdate(email)) {
|
|
|
|
|
- if (Objects.nonNull(email.getDelaySendTime())) {
|
|
|
|
|
- if (!CollectionUtils.isEmpty(dto.getFileIds())) {
|
|
|
|
|
- LambdaUpdateWrapper<MailTempAttachmentEntity> mt = new LambdaUpdateWrapper<>();
|
|
|
|
|
- mt.set(MailTempAttachmentEntity::getEmailId, email.getId());
|
|
|
|
|
- mt.in(MailTempAttachmentEntity::getId, dto.getFileIds());
|
|
|
|
|
- tempAttachmentService.update(mt);
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- try {
|
|
|
|
|
- CompletableFuture<SendStatus> resultFuture = senderWithThreadLocal.sendMailMessage(transport, message, email);
|
|
|
|
|
- SendStatus result = resultFuture.get();
|
|
|
|
|
- return result;
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("email -address --"+smtpPop.getEmailAddress()+"--send - error -",e);
|
|
|
|
|
- return SendStatus.SERVER_LOGIN_FAIL;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }catch (Exception e) {
|
|
|
|
|
- log.error("getSendEmailsSession -error",e);
|
|
|
|
|
- return SendStatus.FAILED;
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("send sendMail -error",e);
|
|
|
|
|
- return SendStatus.FAILED;
|
|
|
|
|
- }
|
|
|
|
|
return SendStatus.SUCCESS;
|
|
return SendStatus.SUCCESS;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -281,137 +101,12 @@ public class EmailsServiceImpl extends MailDataSourceServiceImpl<EmailsMapper, E
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public Boolean sendEmail(EmailsEntity emails,SmtpPopSettingsEntity smtpPop) {
|
|
public Boolean sendEmail(EmailsEntity emails,SmtpPopSettingsEntity smtpPop) {
|
|
|
-// String active = environment.getProperty("spring.profiles.active");
|
|
|
|
|
-// if("dev".equals(active)) {
|
|
|
|
|
-// return true;
|
|
|
|
|
-// }
|
|
|
|
|
- try {
|
|
|
|
|
-
|
|
|
|
|
- List<String> recipientls = new ArrayList<>();
|
|
|
|
|
- if(StrUtil.isNotBlank(emails.getRecipient())) {
|
|
|
|
|
- recipientls = Arrays.asList(emails.getRecipient().split(","));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- List<String> recipientCcls = new ArrayList<>();
|
|
|
|
|
- if(StrUtil.isNotBlank(emails.getRecipientCc())) {
|
|
|
|
|
- recipientCcls = Arrays.asList(emails.getRecipientCc().split(","));
|
|
|
|
|
- }
|
|
|
|
|
- List<String> recipientBccls = new ArrayList<>();
|
|
|
|
|
- if(StrUtil.isNotBlank(emails.getRecipientBcc())) {
|
|
|
|
|
- recipientBccls = Arrays.asList(emails.getRecipientBcc().split(","));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- String fromAddress = smtpPop.getEmailAddress();
|
|
|
|
|
|
|
|
|
|
- Session session = getSendEmailsSession(smtpPop);
|
|
|
|
|
- InternetAddress [] froms = new InternetAddress[recipientls.size()];
|
|
|
|
|
- for (int i = 0; i < recipientls.size(); i++) {
|
|
|
|
|
- froms[i] = new InternetAddress(recipientls.get(i));
|
|
|
|
|
- }
|
|
|
|
|
- InternetAddress [] fromsCC = new InternetAddress[recipientCcls.size()];
|
|
|
|
|
- for (int i = 0; i < recipientCcls.size(); i++) {
|
|
|
|
|
- fromsCC[i] = new InternetAddress(recipientCcls.get(i));
|
|
|
|
|
- }
|
|
|
|
|
- InternetAddress [] fromsBCC = new InternetAddress[recipientBccls.size()];
|
|
|
|
|
- for (int i = 0; i < recipientBccls.size(); i++) {
|
|
|
|
|
- fromsBCC[i] = new InternetAddress(recipientBccls.get(i));
|
|
|
|
|
- }
|
|
|
|
|
- Transport transport = session.getTransport("smtp");
|
|
|
|
|
- int sizeInBytes = 0;
|
|
|
|
|
- try {
|
|
|
|
|
- Message message = new MimeMessage(session);
|
|
|
|
|
- if (Objects.nonNull(froms) && froms.length > 0) {
|
|
|
|
|
- message.setRecipients(Message.RecipientType.TO,froms);
|
|
|
|
|
- }
|
|
|
|
|
- if (Objects.nonNull(fromsCC) && fromsCC.length > 0) {
|
|
|
|
|
- message.setRecipients(Message.RecipientType.CC,fromsCC);
|
|
|
|
|
- }
|
|
|
|
|
- if (Objects.nonNull(fromsBCC) && fromsBCC.length > 0) {
|
|
|
|
|
- message.setRecipients(Message.RecipientType.BCC,fromsBCC);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- LambdaQueryWrapper fileWrapper = new LambdaQueryWrapper<MailTempAttachmentEntity>().in(MailTempAttachmentEntity::getEmailId,emails.getId());
|
|
|
|
|
- List<MailTempAttachmentEntity> tempAttachment = tempAttachmentService.list(fileWrapper);
|
|
|
|
|
- if (CollectionUtils.isEmpty(tempAttachment)) {
|
|
|
|
|
- message.setFrom(new InternetAddress(fromAddress));
|
|
|
|
|
- message.setSubject(emails.getSubject());
|
|
|
|
|
-
|
|
|
|
|
- Multipart multipart = new MimeMultipart();
|
|
|
|
|
-// // 消息正文
|
|
|
|
|
- BodyPart messageBodyPart1 = new MimeBodyPart();
|
|
|
|
|
- List<MimeBodyPart> imageParts = new ArrayList<>();
|
|
|
|
|
- String updatedHtmlContent = EmailHelper.convertImageUrlsToCidBodyPart(emails.getContent(),imageParts,mailFileProperties.getPath().getJpeg(),multipart);
|
|
|
|
|
- messageBodyPart1.setContent(updatedHtmlContent, "text/html; charset=UTF-8");
|
|
|
|
|
- multipart.addBodyPart(messageBodyPart1);
|
|
|
|
|
- // 发送完整的消息部分
|
|
|
|
|
- message.setContent(multipart);
|
|
|
|
|
- } else {
|
|
|
|
|
- message.setFrom(new InternetAddress(fromAddress));
|
|
|
|
|
- message.setDescription(emails.getRemark());
|
|
|
|
|
- // 设置邮件主题
|
|
|
|
|
- message.setSubject(emails.getSubject());
|
|
|
|
|
- Multipart multipart = new MimeMultipart();
|
|
|
|
|
-// // 消息正文
|
|
|
|
|
- BodyPart messageBodyPart1 = new MimeBodyPart();
|
|
|
|
|
- List<MimeBodyPart> imageParts = new ArrayList<>();
|
|
|
|
|
- String updatedHtmlContent = EmailHelper.convertImageUrlsToCidBodyPart(emails.getContent(),imageParts,mailFileProperties.getPath().getJpeg(),multipart);
|
|
|
|
|
- messageBodyPart1.setContent(updatedHtmlContent, "text/html; charset=UTF-8");
|
|
|
|
|
- multipart.addBodyPart(messageBodyPart1);
|
|
|
|
|
- // 设置文本消息部分
|
|
|
|
|
- for (MailTempAttachmentEntity attachment : tempAttachment) {
|
|
|
|
|
- BodyPart messageBodyPart = new MimeBodyPart();
|
|
|
|
|
- String filePath = mailFileProperties.getPath().getPath() + attachment.getFilePath();
|
|
|
|
|
- String fileName = attachment.getFileName()+"."+attachment.getFileExt();
|
|
|
|
|
- DataSource fileSource = new FileDataSource(filePath);
|
|
|
|
|
- messageBodyPart.setDataHandler(new DataHandler(fileSource));
|
|
|
|
|
- messageBodyPart.setFileName(fileName);
|
|
|
|
|
- multipart.addBodyPart(messageBodyPart);
|
|
|
|
|
- }
|
|
|
|
|
- // 发送完整的消息部分
|
|
|
|
|
- message.setContent(multipart);
|
|
|
|
|
- }
|
|
|
|
|
- /**
|
|
|
|
|
- * 发送成�?存储邮箱 replyEmailId null
|
|
|
|
|
- */
|
|
|
|
|
- if (Integer.valueOf(1).equals(emails .getIsReceipt())) {
|
|
|
|
|
- message.addHeader("Disposition-Notification-To", smtpPop.getEmailAddress());
|
|
|
|
|
- }
|
|
|
|
|
- if(this.saveOrUpdate(emails)) {
|
|
|
|
|
- senderWithThreadLocal.sendMailMessage(transport,message,emails);
|
|
|
|
|
- }
|
|
|
|
|
- return true;
|
|
|
|
|
- }catch (Exception e) {
|
|
|
|
|
- log.error("getSendEmailsSession -error",e);
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- log.error("send sendMail -error",e);
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
@Override
|
|
@Override
|
|
|
public void receiveEmails(SmtpPopSettingsEntity smtpPop,Boolean isBackTask) {
|
|
public void receiveEmails(SmtpPopSettingsEntity smtpPop,Boolean isBackTask) {
|
|
|
- String active = environment.getProperty("spring.profiles.active");
|
|
|
|
|
-// if("dev".equals(active)) {
|
|
|
|
|
-// return;
|
|
|
|
|
-// }
|
|
|
|
|
- String taskId = smtpPop.getEmailAddress()+"_"+smtpPop.getOwnerBy().toString();
|
|
|
|
|
- ReceiveMailQueueThreadPool instance = ReceiveMailQueueThreadPool.getInstance();
|
|
|
|
|
- if (instance.getTaskInProgressByMail(taskId)) {
|
|
|
|
|
- log.error("有任务正在进�?-:>>>>>>>>>>>>>"+smtpPop.getEmailAddress());
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- instance.addTask(taskId,new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- receiveHeadEmails(smtpPop,isBackTask);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- addLoadMailContentTask(smtpPop);
|
|
|
|
|
|
|
|
|
|
- addLoadMailFilesTask(smtpPop);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -427,23 +122,23 @@ public class EmailsServiceImpl extends MailDataSourceServiceImpl<EmailsMapper, E
|
|
|
@Override
|
|
@Override
|
|
|
public void receiveHeadEmails(SmtpPopSettingsEntity smtpPop,Boolean isBackTask) {
|
|
public void receiveHeadEmails(SmtpPopSettingsEntity smtpPop,Boolean isBackTask) {
|
|
|
|
|
|
|
|
- try {
|
|
|
|
|
- List<Message> inboxLs = getMessagels(smtpPop,"INBOX",EmailBoxEnum.INBOX,isBackTask);
|
|
|
|
|
- if (!CollectionUtils.isEmpty(inboxLs)) {
|
|
|
|
|
- List<EmailFolderRuleEntity> folderRules = folderRuleService.getUserFolderRules(smtpPop.getOwnerBy());
|
|
|
|
|
- Set<String> blackList = blackListService.getBlackEmaillist(smtpPop.getOwnerBy());
|
|
|
|
|
- pullHeadMail(inboxLs,smtpPop,EmailBoxEnum.INBOX,blackList,folderRules,isBackTask);
|
|
|
|
|
- }
|
|
|
|
|
-// if (!smtpPop.getEnabled()) {
|
|
|
|
|
-// return;
|
|
|
|
|
|
|
+// try {
|
|
|
|
|
+// List<Message> inboxLs = getMessagels(smtpPop,"INBOX",EmailBoxEnum.INBOX,isBackTask);
|
|
|
|
|
+// if (!CollectionUtils.isEmpty(inboxLs)) {
|
|
|
|
|
+// List<EmailFolderRuleEntity> folderRules = folderRuleService.getUserFolderRules(smtpPop.getOwnerBy());
|
|
|
|
|
+// Set<String> blackList = blackListService.getBlackEmaillist(smtpPop.getOwnerBy());
|
|
|
|
|
+// pullHeadMail(inboxLs,smtpPop,EmailBoxEnum.INBOX,blackList,folderRules,isBackTask);
|
|
|
// }
|
|
// }
|
|
|
- List<Message> sentLs = getMessagels(smtpPop,"Sent Items", EmailBoxEnum.SENT,isBackTask);
|
|
|
|
|
- if (!CollectionUtils.isEmpty(sentLs)) {
|
|
|
|
|
- pullHeadMail(sentLs,smtpPop,EmailBoxEnum.SENT,null,null,isBackTask);
|
|
|
|
|
- }
|
|
|
|
|
- }catch (Exception e) {
|
|
|
|
|
- log.error("receiveHeadEmails - error ---"+smtpPop.getEmailAddress(),e);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+//// if (!smtpPop.getEnabled()) {
|
|
|
|
|
+//// return;
|
|
|
|
|
+//// }
|
|
|
|
|
+// List<Message> sentLs = getMessagels(smtpPop,"Sent Items", EmailBoxEnum.SENT,isBackTask);
|
|
|
|
|
+// if (!CollectionUtils.isEmpty(sentLs)) {
|
|
|
|
|
+// pullHeadMail(sentLs,smtpPop,EmailBoxEnum.SENT,null,null,isBackTask);
|
|
|
|
|
+// }
|
|
|
|
|
+// }catch (Exception e) {
|
|
|
|
|
+// log.error("receiveHeadEmails - error ---"+smtpPop.getEmailAddress(),e);
|
|
|
|
|
+// }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public List<Message> getMessagels(SmtpPopSettingsEntity smtpPop,String folderName, EmailBoxEnum boxEnum) {
|
|
public List<Message> getMessagels(SmtpPopSettingsEntity smtpPop,String folderName, EmailBoxEnum boxEnum) {
|
|
@@ -452,90 +147,7 @@ public class EmailsServiceImpl extends MailDataSourceServiceImpl<EmailsMapper, E
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public List<Message> getMessagels(SmtpPopSettingsEntity smtpPop,String folderName, EmailBoxEnum boxEnum,Boolean isBackTask) {
|
|
public List<Message> getMessagels(SmtpPopSettingsEntity smtpPop,String folderName, EmailBoxEnum boxEnum,Boolean isBackTask) {
|
|
|
- try {
|
|
|
|
|
- QueryWrapper queryWrapper = new QueryWrapper<>();
|
|
|
|
|
- queryWrapper.eq("smtp_pop_id", smtpPop.getId());
|
|
|
|
|
- queryWrapper.eq("folder", boxEnum.code);
|
|
|
|
|
- queryWrapper.select("max(recipient_date) as recipient_date");
|
|
|
|
|
- EmailsEntity email = this.getOne(queryWrapper);
|
|
|
|
|
-
|
|
|
|
|
- Date beginDate = null;
|
|
|
|
|
- MailProperties properties = new MailProperties(smtpPop);
|
|
|
|
|
- MailConnection mailConnection = MailConnectionUtil.receiveEmailsConnection(properties);
|
|
|
|
|
- if (Objects.isNull(mailConnection)) {
|
|
|
|
|
-// if(isBackTask) {
|
|
|
|
|
-// // 处理异常,并发送通知
|
|
|
|
|
-// if (Objects.nonNull(smtpPop.getId())) {
|
|
|
|
|
-// LambdaUpdateWrapper<SmtpPopSettingsEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
-// updateWrapper.set(SmtpPopSettingsEntity::getEnabled,0);
|
|
|
|
|
-// updateWrapper.eq(SmtpPopSettingsEntity::getId, smtpPop.getId())
|
|
|
|
|
-// .setSql("connect_error_count = connect_error_count + 1"); // 原�?+ 1
|
|
|
|
|
-// popSettingsService.update(updateWrapper);
|
|
|
|
|
-// // 禁止后续流程
|
|
|
|
|
-//// smtpPop.setEnabled(false);
|
|
|
|
|
-// }
|
|
|
|
|
-//// // 发送消息通知提醒邮箱连接异常
|
|
|
|
|
-//// String[] argsArr = {"wecom"};
|
|
|
|
|
-//// Set<Long> userIds = new HashSet<>();
|
|
|
|
|
-//// userIds.add(smtpPop.getOwnerBy());
|
|
|
|
|
-////
|
|
|
|
|
-//// Map<String,Object> messageMap = new HashMap<>();
|
|
|
|
|
-//// messageMap.put("messageContent","");
|
|
|
|
|
-//// messageMap.put("titleRemark","["+smtpPop.getEmailAddress()+"]");
|
|
|
|
|
-//// invokeSendMessage(messageMap,userIds,argsArr);
|
|
|
|
|
-// }
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- Folder inbox = mailConnection.getFolder(folderName);
|
|
|
|
|
- if (Objects.isNull(inbox)) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- inbox.open(Folder.READ_ONLY);
|
|
|
|
|
- if (Objects.nonNull(email)) {
|
|
|
|
|
- beginDate = email.getRecipientDate();
|
|
|
|
|
- }
|
|
|
|
|
- if (beginDate == null) {
|
|
|
|
|
- if (Integer.valueOf(0).equals(smtpPop.getPullDay()) || Objects.isNull(smtpPop.getPullDay())) {
|
|
|
|
|
- LocalDate currentDate = LocalDate.now();
|
|
|
|
|
- LocalDate datePullDayAgo = currentDate.minusYears(5);
|
|
|
|
|
- beginDate = DateUtil.getDateByFormat(datePullDayAgo.toString(), "yyyy-MM-dd");
|
|
|
|
|
- } else {
|
|
|
|
|
- LocalDate currentDate = LocalDate.now();
|
|
|
|
|
- LocalDate datePullDayAgo = currentDate.minusDays(smtpPop.getPullDay());
|
|
|
|
|
- beginDate = DateUtil.getDateByFormat(datePullDayAgo.toString(), "yyyy-MM-dd");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- SearchTerm searchTerm = new ReceivedDateTerm(ComparisonTerm.GT, beginDate);
|
|
|
|
|
- Message[] messages = inbox.search(searchTerm);
|
|
|
|
|
-
|
|
|
|
|
- List<Message> messagesList = Arrays.asList(messages);
|
|
|
|
|
- if (CollectionUtils.isEmpty(messagesList)) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-// Date finalBeginDate = beginDate;
|
|
|
|
|
-// List<Message> messagels = messagesList.stream().filter(e -> {
|
|
|
|
|
-// try {
|
|
|
|
|
-// return e.getReceivedDate().compareTo(finalBeginDate) > 0;
|
|
|
|
|
-// } catch (MessagingException ex) {
|
|
|
|
|
-// return false;
|
|
|
|
|
-// }
|
|
|
|
|
-// }).collect(Collectors.toList());
|
|
|
|
|
-//
|
|
|
|
|
-// if (Objects.isNull(messagels)) {
|
|
|
|
|
-// return messagels;
|
|
|
|
|
-// } else if (messagels.size() <= 100) {
|
|
|
|
|
-// return messagels;
|
|
|
|
|
-// } else if(messagels.size() > 100 && messagels.size() <= 1000) {
|
|
|
|
|
-// return messagels.stream().limit(500).collect(Collectors.toList());
|
|
|
|
|
-// } else {
|
|
|
|
|
-// return messagels.stream().limit(1000).collect(Collectors.toList());
|
|
|
|
|
-// }
|
|
|
|
|
- return messagesList;
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("error", e);
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void invokeSendMessage(Map messageMap,Set<Long> toUserIds,String[] argsArr ) {
|
|
public void invokeSendMessage(Map messageMap,Set<Long> toUserIds,String[] argsArr ) {
|
|
@@ -623,10 +235,7 @@ public class EmailsServiceImpl extends MailDataSourceServiceImpl<EmailsMapper, E
|
|
|
if (Objects.isNull(entity)) {
|
|
if (Objects.isNull(entity)) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- if (!CollectionUtils.isEmpty(folderRules)) {
|
|
|
|
|
- /** 处理文件夹入栈规�?**/
|
|
|
|
|
- folderRuleService.carveUpMailCustomFolder(entity, folderRules);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
mesageIds.add(messageId);
|
|
mesageIds.add(messageId);
|
|
|
if ("IMAP".equals(smtpPop.getProtocolType())) {
|
|
if ("IMAP".equals(smtpPop.getProtocolType())) {
|
|
|
IMAPFolder folder = (IMAPFolder) message.getFolder();
|
|
IMAPFolder folder = (IMAPFolder) message.getFolder();
|
|
@@ -778,42 +387,7 @@ public class EmailsServiceImpl extends MailDataSourceServiceImpl<EmailsMapper, E
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void autoReplyMail(EmailsEntity entity) {
|
|
public void autoReplyMail(EmailsEntity entity) {
|
|
|
- try {
|
|
|
|
|
- SmtpPopSettingsEntity smtpPop = popSettingsService.getById(entity.getSmtpPopId());
|
|
|
|
|
- if (Integer.valueOf(1).equals(smtpPop.getIsAutoReply()) && smtpPop.getReplyOnTime().before(entity.getSentDate())) {
|
|
|
|
|
- if (entity.getFrom().equals(smtpPop.getEmailAddress())
|
|
|
|
|
- || "system@storlead.com".equals(entity.getFrom())
|
|
|
|
|
- || "system@storlead.com".equals(entity.getRecipient())) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- // 发过了不用发
|
|
|
|
|
- String key = smtpPop.getEmailAddress()+"_"+entity.getFrom();
|
|
|
|
|
- Object object =redisService.getCacheObject(key);
|
|
|
|
|
- Long ttl = 0l;
|
|
|
|
|
- if (Objects.nonNull(object)) {
|
|
|
|
|
- ttl = redisService.getCacheExpire(key, TimeUnit.SECONDS);
|
|
|
|
|
- }
|
|
|
|
|
- if ((Objects.isNull(object) || ttl <= 0) && StrUtil.isNotBlank(smtpPop.getReplyContent())) {
|
|
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
- // 今天23:59:59
|
|
|
|
|
- LocalDateTime endOfDay = now.toLocalDate().atTime(23, 59, 59);
|
|
|
|
|
- // 计算剩余时间(秒�?
|
|
|
|
|
- long timeout = ChronoUnit.SECONDS.between(now, endOfDay);
|
|
|
|
|
- redisService.setCacheObject(key,"reply",timeout, TimeUnit.SECONDS);
|
|
|
|
|
-
|
|
|
|
|
- AccessKeyEncryptor accessKeyEncryptor = AccessKeyEncryptor.getAccessKeyEncryptor("");
|
|
|
|
|
- String pass = accessKeyEncryptor.decrypt(smtpPop.getEmailPassword());
|
|
|
|
|
- smtpPop.setEmailPassword(pass);
|
|
|
|
|
- EmailsEntity repEmail = new EmailsEntity();
|
|
|
|
|
- repEmail.setRecipient(entity.getFrom());
|
|
|
|
|
- repEmail.setSubject(smtpPop.getReplyTitle());
|
|
|
|
|
- repEmail.setContent(smtpPop.getReplyContent());
|
|
|
|
|
- this.sendEmail(repEmail,smtpPop);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }catch (Exception e) {
|
|
|
|
|
- log.error("autoReplyMail errpr ",e);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
@Override
|
|
@Override
|
|
|
public NewMailCountTipVO countMailSummaryNum(Long smtpPopId, Long ownerBy) {
|
|
public NewMailCountTipVO countMailSummaryNum(Long smtpPopId, Long ownerBy) {
|
|
@@ -854,34 +428,7 @@ public class EmailsServiceImpl extends MailDataSourceServiceImpl<EmailsMapper, E
|
|
|
@Override
|
|
@Override
|
|
|
public InputStream loadEmailsFile(SmtpPopSettingsEntity smtpPop, EmailsEntity email,String attachmentName) {
|
|
public InputStream loadEmailsFile(SmtpPopSettingsEntity smtpPop, EmailsEntity email,String attachmentName) {
|
|
|
try {
|
|
try {
|
|
|
- MailProperties properties = new MailProperties(smtpPop);
|
|
|
|
|
- MailConnection mailConnection = MailConnectionUtil.receiveEmailsConnection(properties);
|
|
|
|
|
- if (Objects.isNull(mailConnection)) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- String folder = "Sent Items";
|
|
|
|
|
- if (EmailBoxEnum.INBOX.code.equals(email.getFolder())) {
|
|
|
|
|
- folder = "INBOX";
|
|
|
|
|
- }
|
|
|
|
|
- Message message = mailConnection.getMessageByUid(email.getMsgUid(),folder);
|
|
|
|
|
- if (Objects.isNull(message)) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- Object content = message.getContent();
|
|
|
|
|
- if (content instanceof Multipart) {
|
|
|
|
|
- Multipart multipart = (Multipart) content;
|
|
|
|
|
- for (int i = 0; i < multipart.getCount(); i++) {
|
|
|
|
|
- BodyPart bodyPart = multipart.getBodyPart(i);
|
|
|
|
|
- if (Part.ATTACHMENT.equalsIgnoreCase(bodyPart.getDisposition()) || bodyPart.isMimeType("application/octet-stream")) {
|
|
|
|
|
- String fileName = bodyPart.getFileName();
|
|
|
|
|
- fileName = MimeUtility.decodeText(fileName);
|
|
|
|
|
- fileName = fileName.replace("\n", "").replace("\r", "");
|
|
|
|
|
- if (fileName.equals(attachmentName)) {
|
|
|
|
|
- return bodyPart.getInputStream();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
}catch (Exception e) {
|
|
}catch (Exception e) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -891,79 +438,6 @@ public class EmailsServiceImpl extends MailDataSourceServiceImpl<EmailsMapper, E
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void loadEmailsFiles(SmtpPopSettingsEntity smtpPop, List<EmailsEntity> emails,List<MailAttachmentEntity> attachments) {
|
|
public void loadEmailsFiles(SmtpPopSettingsEntity smtpPop, List<EmailsEntity> emails,List<MailAttachmentEntity> attachments) {
|
|
|
- try {
|
|
|
|
|
- MailProperties properties = new MailProperties(smtpPop);
|
|
|
|
|
- MailConnection mailConnection = MailConnectionUtil.receiveEmailsConnection(properties);
|
|
|
|
|
- if (Objects.isNull(mailConnection)) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- Map<Long,List<MailAttachmentEntity>> attachmentMap = attachments.stream().collect(Collectors.groupingBy(MailAttachmentEntity::getEmailId));
|
|
|
|
|
- for(EmailsEntity email : emails) {
|
|
|
|
|
- List<MailAttachmentEntity> mAttachments = attachmentMap.get(email.getId());
|
|
|
|
|
- if (CollectionUtils.isEmpty(mAttachments)) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- String folder = "Sent Items";
|
|
|
|
|
- if (EmailBoxEnum.INBOX.code.equals(email.getFolder())) {
|
|
|
|
|
- folder = "INBOX";
|
|
|
|
|
- }
|
|
|
|
|
- mailConnection.getFolder(folder);
|
|
|
|
|
- Map<String, MailAttachmentEntity> attachmentMapName = mAttachments.stream()
|
|
|
|
|
- .collect(Collectors.toMap(
|
|
|
|
|
- attachment -> attachment.getFileName() + "." + attachment.getFileExt(), // 键:拼接 fileName �?fileExt
|
|
|
|
|
- attachment -> attachment,
|
|
|
|
|
- (existing, replacement) -> existing
|
|
|
|
|
- ));
|
|
|
|
|
- Message message = mailConnection.getMessageByUid(email.getMsgUid(),folder);
|
|
|
|
|
- if (Objects.isNull(message)) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- Object content = message.getContent();
|
|
|
|
|
- if (content instanceof Multipart) {
|
|
|
|
|
- Multipart multipart = (Multipart) content;
|
|
|
|
|
- for (int i = 0; i < multipart.getCount(); i++) {
|
|
|
|
|
- BodyPart bodyPart = multipart.getBodyPart(i);
|
|
|
|
|
- if (Part.ATTACHMENT.equalsIgnoreCase(bodyPart.getDisposition()) || bodyPart.isMimeType("application/octet-stream")) {
|
|
|
|
|
- String fileName = bodyPart.getFileName();
|
|
|
|
|
- fileName = MimeUtility.decodeText(fileName);
|
|
|
|
|
- fileName = fileName.replace("\n", "").replace("\r", "");
|
|
|
|
|
- MailAttachmentEntity attachment = attachmentMapName.get(fileName);
|
|
|
|
|
- if (Objects.isNull(attachment)) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- String filePath = mailFileProperties.getPath().getPath()+attachment.getFilePath();
|
|
|
|
|
- if (new File(filePath).exists()) {
|
|
|
|
|
- LambdaUpdateWrapper<MailAttachmentEntity> attachmentUpdate = new LambdaUpdateWrapper<>();
|
|
|
|
|
- attachmentUpdate.set(MailAttachmentEntity::getDownload,Integer.valueOf(1));
|
|
|
|
|
- attachmentUpdate.eq(MailAttachmentEntity::getId,attachment.getId());
|
|
|
|
|
- mailAttachmentService.update(attachmentUpdate);
|
|
|
|
|
- }
|
|
|
|
|
- try {
|
|
|
|
|
- File file = new File(filePath);
|
|
|
|
|
- File parentDir = file.getParentFile();
|
|
|
|
|
- // 如果父目录不存在,则递归创建
|
|
|
|
|
- if (parentDir != null && !parentDir.exists()) {
|
|
|
|
|
- parentDir.mkdirs(); // mkdirs() 会创建所有必要的父目�?
|
|
|
|
|
- }
|
|
|
|
|
- try (FileOutputStream output = new FileOutputStream(file)) {
|
|
|
|
|
- bodyPart.getInputStream().transferTo(output);
|
|
|
|
|
- }
|
|
|
|
|
- LambdaUpdateWrapper<MailAttachmentEntity> attachmentUpdate = new LambdaUpdateWrapper<>();
|
|
|
|
|
- attachmentUpdate.set(MailAttachmentEntity::getDownload,Integer.valueOf(1));
|
|
|
|
|
- attachmentUpdate.set(MailAttachmentEntity::getFileSize,file.length());
|
|
|
|
|
- attachmentUpdate.eq(MailAttachmentEntity::getId,attachment.getId());
|
|
|
|
|
- mailAttachmentService.update(attachmentUpdate);
|
|
|
|
|
- }catch (Exception e) {
|
|
|
|
|
- log.error("error --- ",e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }catch (Exception e) {
|
|
|
|
|
- log.error("loadEmailsFiles ---",e);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -987,59 +461,24 @@ public class EmailsServiceImpl extends MailDataSourceServiceImpl<EmailsMapper, E
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void receiveBodyContent(SmtpPopSettingsEntity smtpPop,List<EmailsEntity> emailsls,EmailBoxEnum boxEnum) {
|
|
public void receiveBodyContent(SmtpPopSettingsEntity smtpPop,List<EmailsEntity> emailsls,EmailBoxEnum boxEnum) {
|
|
|
- try {
|
|
|
|
|
- MailProperties properties = new MailProperties(smtpPop);
|
|
|
|
|
- MailConnection mailConnection = MailConnectionUtil.receiveEmailsConnection(properties);
|
|
|
|
|
- if (Objects.isNull(mailConnection)) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- if (!CollectionUtils.isEmpty(emailsls)) {
|
|
|
|
|
- if (Objects.isNull(mailConnection)) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- for (EmailsEntity email : emailsls) {
|
|
|
|
|
- Message message = boxEnum.code.equals("INBOX") ? mailConnection.getMessageByUid(email.getMsgUid(),"INBOX") : mailConnection.getMessageByUid(email.getMsgUid(),"Sent Items");
|
|
|
|
|
- if (Objects.isNull(message)) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- if (Integer.valueOf(0).equals(email.getIsOnlyHead())) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- String bodyContent = getEmailBodyContent(message);
|
|
|
|
|
- LambdaUpdateWrapper<EmailsEntity> update = new LambdaUpdateWrapper<>();
|
|
|
|
|
- update.set(EmailsEntity::getContent,bodyContent);
|
|
|
|
|
- update.set(EmailsEntity::getIsOnlyHead,0);
|
|
|
|
|
- update.eq(EmailsEntity::getId,email.getId());
|
|
|
|
|
- update(update);
|
|
|
|
|
- CompletableFuture.runAsync(() -> {
|
|
|
|
|
- try {
|
|
|
|
|
- pullMailAttachmentHead(email.getId(),email.getRecipientDate(),message.getContent(),smtpPop);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("get message content - error", e);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }catch (Exception e) {
|
|
|
|
|
- log.error("receiveHeadContent -- error",e);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void addLoadMailContentTask(SmtpPopSettingsEntity smtpPop) {
|
|
public void addLoadMailContentTask(SmtpPopSettingsEntity smtpPop) {
|
|
|
|
|
|
|
|
- ReceiveMailQueueThreadPool instance = ReceiveMailQueueThreadPool.getInstance();
|
|
|
|
|
- String taskName = smtpPop.getEmailAddress()+"_"+smtpPop.getOwnerBy().toString()+"_load_content";
|
|
|
|
|
- if (instance.getTaskInProgressByMail(taskName)) {
|
|
|
|
|
- log.error("有任务正在进�?-:>>>>>>>>>>>>>"+taskName);
|
|
|
|
|
- } else {
|
|
|
|
|
- instance.addTask(taskName,new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- loadMailContentTask(smtpPop);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// ReceiveMailQueueThreadPool instance = ReceiveMailQueueThreadPool.getInstance();
|
|
|
|
|
+// String taskName = smtpPop.getEmailAddress()+"_"+smtpPop.getOwnerBy().toString()+"_load_content";
|
|
|
|
|
+// if (instance.getTaskInProgressByMail(taskName)) {
|
|
|
|
|
+// log.error("有任务正在进�?-:>>>>>>>>>>>>>"+taskName);
|
|
|
|
|
+// } else {
|
|
|
|
|
+// instance.addTask(taskName,new Runnable() {
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public void run() {
|
|
|
|
|
+// loadMailContentTask(smtpPop);
|
|
|
|
|
+// }
|
|
|
|
|
+// });
|
|
|
|
|
+// }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -1076,18 +515,6 @@ public class EmailsServiceImpl extends MailDataSourceServiceImpl<EmailsMapper, E
|
|
|
@Override
|
|
@Override
|
|
|
public void addLoadMailFilesTask(SmtpPopSettingsEntity smtpPop) {
|
|
public void addLoadMailFilesTask(SmtpPopSettingsEntity smtpPop) {
|
|
|
|
|
|
|
|
- ReceiveMailQueueThreadPool instance = ReceiveMailQueueThreadPool.getInstance();
|
|
|
|
|
- String taskName = smtpPop.getEmailAddress()+"_"+smtpPop.getOwnerBy()+"_load";
|
|
|
|
|
- if (instance.getTaskInProgressByMail(taskName)) {
|
|
|
|
|
- log.error("有任务正在进�?-:>>>>>>>>>>>>>"+taskName);
|
|
|
|
|
- } else {
|
|
|
|
|
- instance.addTask(taskName,new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- loadMailFiles(smtpPop);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|