|
@@ -44,6 +44,7 @@ import jakarta.mail.search.SearchTerm;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.http.MediaType;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.StopWatch;
|
|
import org.springframework.util.StopWatch;
|
|
|
|
|
|
@@ -997,11 +998,10 @@ public class EmailParseService {
|
|
}
|
|
}
|
|
|
|
|
|
Object messageContent = message.getContent();
|
|
Object messageContent = message.getContent();
|
|
- String content;
|
|
|
|
|
|
+ String[] contents = new String[]{null};
|
|
if (messageContent instanceof Multipart multipart) {
|
|
if (messageContent instanceof Multipart multipart) {
|
|
- content = this.reMultipart(emailAddress, emailTitle, emailDate, multipart, dtos);
|
|
|
|
|
|
+ this.reMultipart(emailAddress, emailTitle, emailDate, multipart, contents, dtos);
|
|
} else {
|
|
} else {
|
|
- content = null;
|
|
|
|
log.warn("{} 邮件{} 获取不了附件", folderName, emailTitle);
|
|
log.warn("{} 邮件{} 获取不了附件", folderName, emailTitle);
|
|
}
|
|
}
|
|
if (CollUtil.isEmpty(dtos)) {
|
|
if (CollUtil.isEmpty(dtos)) {
|
|
@@ -1011,7 +1011,7 @@ public class EmailParseService {
|
|
dtos.forEach(e -> {
|
|
dtos.forEach(e -> {
|
|
e.setEmailType(emailType);
|
|
e.setEmailType(emailType);
|
|
e.setSenderEmail(senderEmail);
|
|
e.setSenderEmail(senderEmail);
|
|
- e.setEmailContent(content);
|
|
|
|
|
|
+ e.setEmailContent(contents[0]);
|
|
});
|
|
});
|
|
emailMessageMap.put(IdUtil.simpleUUID(), dtos);
|
|
emailMessageMap.put(IdUtil.simpleUUID(), dtos);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -1096,9 +1096,9 @@ public class EmailParseService {
|
|
return FileUtil.file(filePath + realName);
|
|
return FileUtil.file(filePath + realName);
|
|
}
|
|
}
|
|
|
|
|
|
- private String reMultipart(String account, String subject, Date emailDate, Multipart multipart,
|
|
|
|
|
|
+ private void reMultipart(String account, String subject, Date emailDate,
|
|
|
|
+ Multipart multipart, String[] contents,
|
|
List<EmailContentInfoDTO> emailContentInfoDTOList) throws Exception {
|
|
List<EmailContentInfoDTO> emailContentInfoDTOList) throws Exception {
|
|
- String content = null;
|
|
|
|
for (int i = 0; i < multipart.getCount(); i++) {
|
|
for (int i = 0; i < multipart.getCount(); i++) {
|
|
Part bodyPart = multipart.getBodyPart(i);
|
|
Part bodyPart = multipart.getBodyPart(i);
|
|
Object bodyPartContent = bodyPart.getContent();
|
|
Object bodyPartContent = bodyPart.getContent();
|
|
@@ -1106,16 +1106,17 @@ public class EmailParseService {
|
|
if (log.isDebugEnabled()) {
|
|
if (log.isDebugEnabled()) {
|
|
log.debug("邮件{} 获取的正文不做解析,内容是 {}", subject, bodyPartContent);
|
|
log.debug("邮件{} 获取的正文不做解析,内容是 {}", subject, bodyPartContent);
|
|
}
|
|
}
|
|
- content = bodyPartContent.toString();
|
|
|
|
|
|
+ if (StrUtil.startWithIgnoreCase(bodyPart.getContentType(), MediaType.TEXT_PLAIN_VALUE)) {
|
|
|
|
+ contents[0] = bodyPartContent.toString();
|
|
|
|
+ }
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
if (bodyPartContent instanceof Multipart mp) {
|
|
if (bodyPartContent instanceof Multipart mp) {
|
|
- this.reMultipart(account, subject, emailDate, mp, emailContentInfoDTOList);
|
|
|
|
|
|
+ this.reMultipart(account, subject, emailDate, mp, contents, emailContentInfoDTOList);
|
|
} else {
|
|
} else {
|
|
this.rePart(account, subject, emailDate, bodyPart, emailContentInfoDTOList);
|
|
this.rePart(account, subject, emailDate, bodyPart, emailContentInfoDTOList);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return content;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
private String getSenderEmail(Message message) {
|
|
private String getSenderEmail(Message message) {
|