|
@@ -27,7 +27,7 @@ import com.storlead.mail.pojo.MailDTO;
|
|
|
import com.storlead.mail.pojo.MailListDTO;
|
|
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.framework.mybatis.service.impl.MyBaseServiceImpl;
|
|
|
|
|
|
|
+import com.storlead.mail.service.impl.support.MailDataSourceServiceImpl;
|
|
|
import com.storlead.mail.util.EmailHelper;
|
|
import com.storlead.mail.util.EmailHelper;
|
|
|
import com.storlead.mail.util.EmailSenderWithThreadLocal;
|
|
import com.storlead.mail.util.EmailSenderWithThreadLocal;
|
|
|
import com.storlead.mail.util.ReceiveMailQueueThreadPool;
|
|
import com.storlead.mail.util.ReceiveMailQueueThreadPool;
|
|
@@ -64,7 +64,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* <p>
|
|
* <p>
|
|
|
- * 邮件表 服务实现类
|
|
|
|
|
|
|
+ * 邮件�?服务实现�?
|
|
|
* </p>
|
|
* </p>
|
|
|
*
|
|
*
|
|
|
* @author chenkq
|
|
* @author chenkq
|
|
@@ -72,7 +72,7 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
*/
|
|
|
@Log4j2
|
|
@Log4j2
|
|
|
@Service
|
|
@Service
|
|
|
-public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEntity> implements EmailsService {
|
|
|
|
|
|
|
+public class EmailsServiceImpl extends MailDataSourceServiceImpl<EmailsMapper, EmailsEntity> implements EmailsService {
|
|
|
|
|
|
|
|
|
|
|
|
|
private final ConcurrentMap<String, Boolean> processedMessages = new ConcurrentHashMap<>();
|
|
private final ConcurrentMap<String, Boolean> processedMessages = new ConcurrentHashMap<>();
|
|
@@ -231,10 +231,10 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
message.setContent(multipart);
|
|
message.setContent(multipart);
|
|
|
// 获取邮件大小
|
|
// 获取邮件大小
|
|
|
sizeInBytes = dto.getContent().length();
|
|
sizeInBytes = dto.getContent().length();
|
|
|
- // 发送消息
|
|
|
|
|
|
|
+ // 发送消�?
|
|
|
}
|
|
}
|
|
|
/**
|
|
/**
|
|
|
- * 发送成功,存储邮箱 replyEmailId null
|
|
|
|
|
|
|
+ * 发送成�?存储邮箱 replyEmailId null
|
|
|
*/
|
|
*/
|
|
|
if (Integer.valueOf(1).equals(dto.getIsReceipt())) {
|
|
if (Integer.valueOf(1).equals(dto.getIsReceipt())) {
|
|
|
message.addHeader("Disposition-Notification-To", smtpPop.getEmailAddress());
|
|
message.addHeader("Disposition-Notification-To", smtpPop.getEmailAddress());
|
|
@@ -371,7 +371,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
message.setContent(multipart);
|
|
message.setContent(multipart);
|
|
|
}
|
|
}
|
|
|
/**
|
|
/**
|
|
|
- * 发送成功,存储邮箱 replyEmailId null
|
|
|
|
|
|
|
+ * 发送成�?存储邮箱 replyEmailId null
|
|
|
*/
|
|
*/
|
|
|
if (Integer.valueOf(1).equals(emails .getIsReceipt())) {
|
|
if (Integer.valueOf(1).equals(emails .getIsReceipt())) {
|
|
|
message.addHeader("Disposition-Notification-To", smtpPop.getEmailAddress());
|
|
message.addHeader("Disposition-Notification-To", smtpPop.getEmailAddress());
|
|
@@ -399,7 +399,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
String taskId = smtpPop.getEmailAddress()+"_"+smtpPop.getOwnerBy().toString();
|
|
String taskId = smtpPop.getEmailAddress()+"_"+smtpPop.getOwnerBy().toString();
|
|
|
ReceiveMailQueueThreadPool instance = ReceiveMailQueueThreadPool.getInstance();
|
|
ReceiveMailQueueThreadPool instance = ReceiveMailQueueThreadPool.getInstance();
|
|
|
if (instance.getTaskInProgressByMail(taskId)) {
|
|
if (instance.getTaskInProgressByMail(taskId)) {
|
|
|
- log.error("有任务正在进行--:>>>>>>>>>>>>>"+smtpPop.getEmailAddress());
|
|
|
|
|
|
|
+ log.error("有任务正在进�?-:>>>>>>>>>>>>>"+smtpPop.getEmailAddress());
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
instance.addTask(taskId,new Runnable() {
|
|
instance.addTask(taskId,new Runnable() {
|
|
@@ -469,7 +469,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
// LambdaUpdateWrapper<SmtpPopSettingsEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
|
// LambdaUpdateWrapper<SmtpPopSettingsEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
// updateWrapper.set(SmtpPopSettingsEntity::getEnabled,0);
|
|
// updateWrapper.set(SmtpPopSettingsEntity::getEnabled,0);
|
|
|
// updateWrapper.eq(SmtpPopSettingsEntity::getId, smtpPop.getId())
|
|
// updateWrapper.eq(SmtpPopSettingsEntity::getId, smtpPop.getId())
|
|
|
-// .setSql("connect_error_count = connect_error_count + 1"); // 原值 + 1
|
|
|
|
|
|
|
+// .setSql("connect_error_count = connect_error_count + 1"); // 原�?+ 1
|
|
|
// popSettingsService.update(updateWrapper);
|
|
// popSettingsService.update(updateWrapper);
|
|
|
// // 禁止后续流程
|
|
// // 禁止后续流程
|
|
|
//// smtpPop.setEnabled(false);
|
|
//// smtpPop.setEnabled(false);
|
|
@@ -555,7 +555,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
@Override
|
|
@Override
|
|
|
public void pullHeadMail(List<Message> messages,SmtpPopSettingsEntity smtpPop, EmailBoxEnum boxEnum,Set<String> blackls,List<EmailFolderRuleEntity> folderRules,Boolean isBackTask) {
|
|
public void pullHeadMail(List<Message> messages,SmtpPopSettingsEntity smtpPop, EmailBoxEnum boxEnum,Set<String> blackls,List<EmailFolderRuleEntity> folderRules,Boolean isBackTask) {
|
|
|
// Lock lock = userLockMap.computeIfAbsent(smtpPop.getOwnerBy(), id -> new ReentrantLock());
|
|
// Lock lock = userLockMap.computeIfAbsent(smtpPop.getOwnerBy(), id -> new ReentrantLock());
|
|
|
- log.info("==========邮件入库开始=========="+boxEnum.code);
|
|
|
|
|
|
|
+ log.info("==========邮件入库开�?========="+boxEnum.code);
|
|
|
|
|
|
|
|
// if (lock.tryLock()) {
|
|
// if (lock.tryLock()) {
|
|
|
try {
|
|
try {
|
|
@@ -624,7 +624,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
if (!CollectionUtils.isEmpty(folderRules)) {
|
|
if (!CollectionUtils.isEmpty(folderRules)) {
|
|
|
- /** 处理文件夹入栈规则 **/
|
|
|
|
|
|
|
+ /** 处理文件夹入栈规�?**/
|
|
|
folderRuleService.carveUpMailCustomFolder(entity, folderRules);
|
|
folderRuleService.carveUpMailCustomFolder(entity, folderRules);
|
|
|
}
|
|
}
|
|
|
mesageIds.add(messageId);
|
|
mesageIds.add(messageId);
|
|
@@ -649,7 +649,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
log.info("==========邮件入库结束=========="+boxEnum.code);
|
|
log.info("==========邮件入库结束=========="+boxEnum.code);
|
|
|
- String finalboxCode = boxEnum.code; // 提前取值
|
|
|
|
|
|
|
+ String finalboxCode = boxEnum.code; // 提前取�?
|
|
|
Boolean finalIsBackTask = isBackTask;
|
|
Boolean finalIsBackTask = isBackTask;
|
|
|
List<Long> finalIsMailIds = entities.stream().map(EmailsEntity::getId).collect(Collectors.toList());
|
|
List<Long> finalIsMailIds = entities.stream().map(EmailsEntity::getId).collect(Collectors.toList());
|
|
|
log.error("finalIsMailIds = "+finalIsMailIds);
|
|
log.error("finalIsMailIds = "+finalIsMailIds);
|
|
@@ -657,9 +657,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
CompletableFuture.runAsync(() -> {
|
|
CompletableFuture.runAsync(() -> {
|
|
|
updateFollowUpTime(entities, smtpPop.getOwnerBy());
|
|
updateFollowUpTime(entities, smtpPop.getOwnerBy());
|
|
|
// 发送新邮件提醒,绑定客户后,直接查询性能会好
|
|
// 发送新邮件提醒,绑定客户后,直接查询性能会好
|
|
|
- log.error("操作完绑定客户"+ JSON.toJSON(finalIsMailIds)+"__"+isBackTask+"___EmailBoxEnum.code___"+finalboxCode+"____="+EmailBoxEnum.INBOX.code.equals(finalboxCode));
|
|
|
|
|
if (!CollectionUtils.isEmpty(finalIsMailIds) && finalIsBackTask && EmailBoxEnum.INBOX.code.equals(finalboxCode)) {
|
|
if (!CollectionUtils.isEmpty(finalIsMailIds) && finalIsBackTask && EmailBoxEnum.INBOX.code.equals(finalboxCode)) {
|
|
|
- log.error("进入发送提醒");
|
|
|
|
|
sendNewMailRemind(finalIsMailIds,smtpPop.getOwnerBy(),smtpPop.getEmailAddress());
|
|
sendNewMailRemind(finalIsMailIds,smtpPop.getOwnerBy(),smtpPop.getEmailAddress());
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -713,7 +711,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
Set<Long> toUserIds = new HashSet<>();
|
|
Set<Long> toUserIds = new HashSet<>();
|
|
|
toUserIds.add(userId);
|
|
toUserIds.add(userId);
|
|
|
|
|
|
|
|
- Object myClassInstance = SpringContextUtils.getBean("messageService");
|
|
|
|
|
|
|
+ Object myClassInstance = SpringContextUtils.getBean("messageService");
|
|
|
Class<?> clazz = myClassInstance.getClass();
|
|
Class<?> clazz = myClassInstance.getClass();
|
|
|
|
|
|
|
|
// Class<?> clazz = Class.forName("com.storlead.message.service.impl.MessageService");
|
|
// Class<?> clazz = Class.forName("com.storlead.message.service.impl.MessageService");
|
|
@@ -725,7 +723,6 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
log.error("autoMatchEventSendMessage error",e);
|
|
log.error("autoMatchEventSendMessage error",e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
public void autoReplyMails(List<EmailsEntity> entities){
|
|
public void autoReplyMails(List<EmailsEntity> entities){
|
|
|
for (EmailsEntity entity : entities) {
|
|
for (EmailsEntity entity : entities) {
|
|
|
try {
|
|
try {
|
|
@@ -800,7 +797,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
// 今天23:59:59
|
|
// 今天23:59:59
|
|
|
LocalDateTime endOfDay = now.toLocalDate().atTime(23, 59, 59);
|
|
LocalDateTime endOfDay = now.toLocalDate().atTime(23, 59, 59);
|
|
|
- // 计算剩余时间(秒)
|
|
|
|
|
|
|
+ // 计算剩余时间(秒�?
|
|
|
long timeout = ChronoUnit.SECONDS.between(now, endOfDay);
|
|
long timeout = ChronoUnit.SECONDS.between(now, endOfDay);
|
|
|
redisService.setCacheObject(key,"reply",timeout, TimeUnit.SECONDS);
|
|
redisService.setCacheObject(key,"reply",timeout, TimeUnit.SECONDS);
|
|
|
|
|
|
|
@@ -913,7 +910,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
mailConnection.getFolder(folder);
|
|
mailConnection.getFolder(folder);
|
|
|
Map<String, MailAttachmentEntity> attachmentMapName = mAttachments.stream()
|
|
Map<String, MailAttachmentEntity> attachmentMapName = mAttachments.stream()
|
|
|
.collect(Collectors.toMap(
|
|
.collect(Collectors.toMap(
|
|
|
- attachment -> attachment.getFileName() + "." + attachment.getFileExt(), // 键:拼接 fileName 和 fileExt
|
|
|
|
|
|
|
+ attachment -> attachment.getFileName() + "." + attachment.getFileExt(), // 键:拼接 fileName �?fileExt
|
|
|
attachment -> attachment,
|
|
attachment -> attachment,
|
|
|
(existing, replacement) -> existing
|
|
(existing, replacement) -> existing
|
|
|
));
|
|
));
|
|
@@ -946,7 +943,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
File parentDir = file.getParentFile();
|
|
File parentDir = file.getParentFile();
|
|
|
// 如果父目录不存在,则递归创建
|
|
// 如果父目录不存在,则递归创建
|
|
|
if (parentDir != null && !parentDir.exists()) {
|
|
if (parentDir != null && !parentDir.exists()) {
|
|
|
- parentDir.mkdirs(); // mkdirs() 会创建所有必要的父目录
|
|
|
|
|
|
|
+ parentDir.mkdirs(); // mkdirs() 会创建所有必要的父目�?
|
|
|
}
|
|
}
|
|
|
try (FileOutputStream output = new FileOutputStream(file)) {
|
|
try (FileOutputStream output = new FileOutputStream(file)) {
|
|
|
bodyPart.getInputStream().transferTo(output);
|
|
bodyPart.getInputStream().transferTo(output);
|
|
@@ -974,17 +971,17 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
public static Message[] mergeMessageArrays(Message[] array1, Message[] array2) {
|
|
public static Message[] mergeMessageArrays(Message[] array1, Message[] array2) {
|
|
|
// 处理空数组的情况
|
|
// 处理空数组的情况
|
|
|
if (array1 == null && array2 == null) {
|
|
if (array1 == null && array2 == null) {
|
|
|
- return new Message[0]; // 两个数组都为空,返回空数组
|
|
|
|
|
|
|
+ return new Message[0]; // 两个数组都为空,返回空数�?
|
|
|
} else if (array1 == null) {
|
|
} else if (array1 == null) {
|
|
|
- return array2; // 如果第一个数组为空,返回第二个数组
|
|
|
|
|
|
|
+ return array2; // 如果第一个数组为空,返回第二个数�?
|
|
|
} else if (array2 == null) {
|
|
} else if (array2 == null) {
|
|
|
- return array1; // 如果第二个数组为空,返回第一个数组
|
|
|
|
|
|
|
+ return array1; // 如果第二个数组为空,返回第一个数�?
|
|
|
}
|
|
}
|
|
|
- // 如果两个数组都不为空,创建一个新的 Message[] 数组,大小为两个数组长度之和
|
|
|
|
|
|
|
+ // 如果两个数组都不为空,创建一个新�?Message[] 数组,大小为两个数组长度之和
|
|
|
Message[] mergedArray = new Message[array1.length + array2.length];
|
|
Message[] mergedArray = new Message[array1.length + array2.length];
|
|
|
// 将第一个数组复制到新数组中
|
|
// 将第一个数组复制到新数组中
|
|
|
System.arraycopy(array1, 0, mergedArray, 0, array1.length);
|
|
System.arraycopy(array1, 0, mergedArray, 0, array1.length);
|
|
|
- // 将第二个数组复制到新数组的后半部分
|
|
|
|
|
|
|
+ // 将第二个数组复制到新数组的后半部�?
|
|
|
System.arraycopy(array2, 0, mergedArray, array1.length, array2.length);
|
|
System.arraycopy(array2, 0, mergedArray, array1.length, array2.length);
|
|
|
return mergedArray;
|
|
return mergedArray;
|
|
|
}
|
|
}
|
|
@@ -1034,7 +1031,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
ReceiveMailQueueThreadPool instance = ReceiveMailQueueThreadPool.getInstance();
|
|
ReceiveMailQueueThreadPool instance = ReceiveMailQueueThreadPool.getInstance();
|
|
|
String taskName = smtpPop.getEmailAddress()+"_"+smtpPop.getOwnerBy().toString()+"_load_content";
|
|
String taskName = smtpPop.getEmailAddress()+"_"+smtpPop.getOwnerBy().toString()+"_load_content";
|
|
|
if (instance.getTaskInProgressByMail(taskName)) {
|
|
if (instance.getTaskInProgressByMail(taskName)) {
|
|
|
- log.error("有任务正在进行--:>>>>>>>>>>>>>"+taskName);
|
|
|
|
|
|
|
+ log.error("有任务正在进�?-:>>>>>>>>>>>>>"+taskName);
|
|
|
} else {
|
|
} else {
|
|
|
instance.addTask(taskName,new Runnable() {
|
|
instance.addTask(taskName,new Runnable() {
|
|
|
@Override
|
|
@Override
|
|
@@ -1082,7 +1079,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
ReceiveMailQueueThreadPool instance = ReceiveMailQueueThreadPool.getInstance();
|
|
ReceiveMailQueueThreadPool instance = ReceiveMailQueueThreadPool.getInstance();
|
|
|
String taskName = smtpPop.getEmailAddress()+"_"+smtpPop.getOwnerBy()+"_load";
|
|
String taskName = smtpPop.getEmailAddress()+"_"+smtpPop.getOwnerBy()+"_load";
|
|
|
if (instance.getTaskInProgressByMail(taskName)) {
|
|
if (instance.getTaskInProgressByMail(taskName)) {
|
|
|
- log.error("有任务正在进行--:>>>>>>>>>>>>>"+taskName);
|
|
|
|
|
|
|
+ log.error("有任务正在进�?-:>>>>>>>>>>>>>"+taskName);
|
|
|
} else {
|
|
} else {
|
|
|
instance.addTask(taskName,new Runnable() {
|
|
instance.addTask(taskName,new Runnable() {
|
|
|
@Override
|
|
@Override
|
|
@@ -1526,7 +1523,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
|
|
|
|
|
// 处理 HTML 内容中的图片引用,替换为 base64
|
|
// 处理 HTML 内容中的图片引用,替换为 base64
|
|
|
// private String processHtmlWithBase64Images(String htmlContent, Multipart multipart) throws MessagingException, IOException {
|
|
// private String processHtmlWithBase64Images(String htmlContent, Multipart multipart) throws MessagingException, IOException {
|
|
|
-// // 找到所有 <img> 标签并处理 src="cid:"
|
|
|
|
|
|
|
+// // 找到所�?<img> 标签并处�?src="cid:"
|
|
|
// String regex = "src=\"cid:(.*?)\"";
|
|
// String regex = "src=\"cid:(.*?)\"";
|
|
|
// java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regex);
|
|
// java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regex);
|
|
|
// java.util.regex.Matcher matcher = pattern.matcher(htmlContent);
|
|
// java.util.regex.Matcher matcher = pattern.matcher(htmlContent);
|
|
@@ -1536,7 +1533,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
// BodyPart imagePart = findImagePartByContentId(multipart, contentId);
|
|
// BodyPart imagePart = findImagePartByContentId(multipart, contentId);
|
|
|
//
|
|
//
|
|
|
// if (imagePart != null) {
|
|
// if (imagePart != null) {
|
|
|
-// // 转换图片为 Base64 并替换 HTML 中的 src="cid:..."
|
|
|
|
|
|
|
+// // 转换图片�?Base64 并替�?HTML 中的 src="cid:..."
|
|
|
// String base64Image = convertImageToBase64(imagePart);
|
|
// String base64Image = convertImageToBase64(imagePart);
|
|
|
// htmlContent = htmlContent.replace("cid:" + contentId, "data:image/png;base64," + base64Image);
|
|
// htmlContent = htmlContent.replace("cid:" + contentId, "data:image/png;base64," + base64Image);
|
|
|
// }
|
|
// }
|
|
@@ -1546,7 +1543,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
private String processHtmlWithBase64Images(String htmlContent, BodyPart bodyPart) throws MessagingException, IOException {
|
|
private String processHtmlWithBase64Images(String htmlContent, BodyPart bodyPart) throws MessagingException, IOException {
|
|
|
- // 找到所有 <img> 标签并处理 src="cid:"
|
|
|
|
|
|
|
+ // 找到所�?<img> 标签并处�?src="cid:"
|
|
|
String contentId = ((MimeBodyPart) bodyPart).getContentID();
|
|
String contentId = ((MimeBodyPart) bodyPart).getContentID();
|
|
|
// String contentId = ((IMAPBodyPart) bodyPart).getContentID();
|
|
// String contentId = ((IMAPBodyPart) bodyPart).getContentID();
|
|
|
if (StrUtil.isBlank(contentId)) {
|
|
if (StrUtil.isBlank(contentId)) {
|
|
@@ -1557,7 +1554,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
if (StrUtil.isNotBlank(contentId)) {
|
|
if (StrUtil.isNotBlank(contentId)) {
|
|
|
BodyPart imagePart = bodyPart;
|
|
BodyPart imagePart = bodyPart;
|
|
|
if (imagePart != null) {
|
|
if (imagePart != null) {
|
|
|
- // 转换图片为 Base64 并替换 HTML 中的 src="cid:..."
|
|
|
|
|
|
|
+ // 转换图片�?Base64 并替�?HTML 中的 src="cid:..."
|
|
|
contentId = contentId.replaceAll("^<(.+)>$", "$1");
|
|
contentId = contentId.replaceAll("^<(.+)>$", "$1");
|
|
|
String base64Image = convertImageToBase64(imagePart);
|
|
String base64Image = convertImageToBase64(imagePart);
|
|
|
htmlContent = htmlContent.replace("cid:" + contentId, "data:image/png;base64," + base64Image);
|
|
htmlContent = htmlContent.replace("cid:" + contentId, "data:image/png;base64," + base64Image);
|
|
@@ -1566,21 +1563,21 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
return htmlContent;
|
|
return htmlContent;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 根据 Content-ID 查找对应的图片部分
|
|
|
|
|
|
|
+ // 根据 Content-ID 查找对应的图片部�?
|
|
|
private BodyPart findImagePartByContentId(Multipart multipart, String contentId) throws MessagingException {
|
|
private BodyPart findImagePartByContentId(Multipart multipart, String contentId) throws MessagingException {
|
|
|
for (int i = 0; i < multipart.getCount(); i++) {
|
|
for (int i = 0; i < multipart.getCount(); i++) {
|
|
|
BodyPart bodyPart = multipart.getBodyPart(i);
|
|
BodyPart bodyPart = multipart.getBodyPart(i);
|
|
|
if (bodyPart.getHeader("Content-ID") != null) {
|
|
if (bodyPart.getHeader("Content-ID") != null) {
|
|
|
String[] contentIdHeader = bodyPart.getHeader("Content-ID");
|
|
String[] contentIdHeader = bodyPart.getHeader("Content-ID");
|
|
|
if (contentIdHeader[0].contains(contentId)) {
|
|
if (contentIdHeader[0].contains(contentId)) {
|
|
|
- return bodyPart; // 找到匹配的图片
|
|
|
|
|
|
|
+ return bodyPart; // 找到匹配的图�?
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return null; // 未找到匹配的图片
|
|
return null; // 未找到匹配的图片
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 将图片转换为 Base64 字符串
|
|
|
|
|
|
|
+ // 将图片转换为 Base64 字符�?
|
|
|
private String convertImageToBase64(BodyPart bodyPart) throws IOException, MessagingException {
|
|
private String convertImageToBase64(BodyPart bodyPart) throws IOException, MessagingException {
|
|
|
InputStream inputStream = bodyPart.getInputStream();
|
|
InputStream inputStream = bodyPart.getInputStream();
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
@@ -1870,7 +1867,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
entity.setRecipientCcName(StringUtil.extractUsernames(entity.getRecipientCc()));
|
|
entity.setRecipientCcName(StringUtil.extractUsernames(entity.getRecipientCc()));
|
|
|
}
|
|
}
|
|
|
/**
|
|
/**
|
|
|
- * 如果发件箱是内部邮箱,则代表是发出去的邮件
|
|
|
|
|
|
|
+ * 如果发件箱是内部邮箱,则代表是发出去的邮�?
|
|
|
*/
|
|
*/
|
|
|
if (internalMails.contains(entity.getFrom())) {
|
|
if (internalMails.contains(entity.getFrom())) {
|
|
|
entity.setInOutMark(2);
|
|
entity.setInOutMark(2);
|
|
@@ -1942,13 +1939,13 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
|
|
|
File parentDir = file.getParentFile();
|
|
File parentDir = file.getParentFile();
|
|
|
// 如果父目录不存在,则递归创建
|
|
// 如果父目录不存在,则递归创建
|
|
|
if (parentDir != null && !parentDir.exists()) {
|
|
if (parentDir != null && !parentDir.exists()) {
|
|
|
- parentDir.mkdirs(); // mkdirs() 会创建所有必要的父目录
|
|
|
|
|
|
|
+ parentDir.mkdirs(); // mkdirs() 会创建所有必要的父目�?
|
|
|
}
|
|
}
|
|
|
- String content = "这是要写入文件的字符串内容";
|
|
|
|
|
|
|
+ String content = "这是要写入文件的字符串内?";
|
|
|
|
|
|
|
|
try (InputStream inputStream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
|
|
try (InputStream inputStream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
|
|
|
FileOutputStream output = new FileOutputStream(file)) {
|
|
FileOutputStream output = new FileOutputStream(file)) {
|
|
|
- inputStream.transferTo(output); // 将字符串流写入文件
|
|
|
|
|
|
|
+ inputStream.transferTo(output); // 将字符串流写入文�?
|
|
|
}
|
|
}
|
|
|
System.out.println("-----------------------"+filePath);
|
|
System.out.println("-----------------------"+filePath);
|
|
|
}catch (Exception e) {
|
|
}catch (Exception e) {
|