|
@@ -41,6 +41,7 @@ import org.apache.commons.compress.archivers.ArchiveException;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StopWatch;
|
|
|
|
|
@@ -688,51 +689,45 @@ public class EmailParseService {
|
|
|
log.warn("邮件{} 附件文件名是空的,不做下载!", subject);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
fileName = MimeUtility.decodeText(fileName);
|
|
|
String disposition = part.getDisposition();
|
|
|
String contentType = part.getContentType();
|
|
|
boolean isAttachment =
|
|
|
(disposition != null && (disposition.equalsIgnoreCase(Part.ATTACHMENT))) ||
|
|
|
- (contentType.startsWith("application/") || contentType.startsWith("image/"));
|
|
|
- if (isAttachment) {
|
|
|
- int size = part.getSize();
|
|
|
+ StrUtil.startWithIgnoreCase(contentType, MediaType.APPLICATION_PDF.toString());
|
|
|
+ if (!isAttachment) {
|
|
|
if (log.isInfoEnabled()) {
|
|
|
- log.info("邮件{} 大小:{}byte 开始下载。。。。。", subject, size);
|
|
|
+ log.info("邮件{} 没有附件(fileName={},disposition={},contentType={}),下载不了附件内容!",
|
|
|
+ subject, fileName, disposition, contentType);
|
|
|
}
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- String emailDate = DateUtil.format(sendDate, DateConst.YYYYMMDDHHMMSS24);
|
|
|
- String emailDateStr = DateUtil.format(sendDate, DateConst.YYYYMMDD);
|
|
|
- String filePath = path + File.separator + account + File.separator + emailDateStr + File.separator;
|
|
|
- String realPath = filePath + emailDate + fileName;
|
|
|
- File saveFile = cn.hutool.core.io.FileUtil.file(realPath);
|
|
|
- if (!saveFile.exists()) {
|
|
|
- if (!saveFile.getParentFile().exists()) {
|
|
|
- boolean mkdirs = saveFile.getParentFile().mkdirs();
|
|
|
- if (!mkdirs) {
|
|
|
- log.warn("file path mkdir failed.");
|
|
|
- }
|
|
|
+ String emailDate = DateUtil.format(sendDate, DateConst.YYYYMMDDHHMMSS24);
|
|
|
+ String emailDateStr = DateUtil.format(sendDate, DateConst.YYYYMMDD);
|
|
|
+ String filePath = path + File.separator + account + File.separator + emailDateStr + File.separator;
|
|
|
+ String realPath = filePath + emailDate + fileName;
|
|
|
+ File saveFile = cn.hutool.core.io.FileUtil.file(realPath);
|
|
|
+ if (!saveFile.exists()) {
|
|
|
+ if (!saveFile.getParentFile().exists()) {
|
|
|
+ boolean mkdirs = saveFile.getParentFile().mkdirs();
|
|
|
+ if (!mkdirs) {
|
|
|
+ log.warn("file path mkdir failed.");
|
|
|
}
|
|
|
- FileUtil.saveFile(saveFile, part);
|
|
|
- } else {
|
|
|
- cn.hutool.core.io.FileUtil.del(saveFile);
|
|
|
- FileUtil.saveFile(saveFile, part);
|
|
|
}
|
|
|
-
|
|
|
- EmailContentInfoDTO emailContentInfoDTO = new EmailContentInfoDTO();
|
|
|
- emailContentInfoDTO.setFileName(fileName);
|
|
|
- emailContentInfoDTO.setFileSize(size);
|
|
|
- emailContentInfoDTO.setFilePath(saveFile.getAbsolutePath());
|
|
|
- emailContentInfoDTO.setEmailAddress(account);
|
|
|
- emailContentInfoDTO.setEmailTitle(subject);
|
|
|
- emailContentInfoDTO.setEmailDate(DateUtil.format(sendDate, DateConst.YYYY_MM_DD_HH_MM_SS));
|
|
|
- emailContentInfoDTOList.add(emailContentInfoDTO);
|
|
|
+ FileUtil.saveFile(saveFile, part);
|
|
|
} else {
|
|
|
- if (log.isInfoEnabled()) {
|
|
|
- log.info("邮件{} 没有附件(fileName={},disposition={},contentType={}),下载不了附件内容!",
|
|
|
- subject, fileName, disposition, contentType);
|
|
|
- }
|
|
|
+ cn.hutool.core.io.FileUtil.del(saveFile);
|
|
|
+ FileUtil.saveFile(saveFile, part);
|
|
|
}
|
|
|
+ EmailContentInfoDTO emailContentInfoDTO = new EmailContentInfoDTO();
|
|
|
+ emailContentInfoDTO.setFileName(fileName);
|
|
|
+ emailContentInfoDTO.setFileSize(part.getSize());
|
|
|
+ emailContentInfoDTO.setFilePath(saveFile.getAbsolutePath());
|
|
|
+ emailContentInfoDTO.setEmailAddress(account);
|
|
|
+ emailContentInfoDTO.setEmailTitle(subject);
|
|
|
+ emailContentInfoDTO.setEmailDate(DateUtil.format(sendDate, DateConst.YYYY_MM_DD_HH_MM_SS));
|
|
|
+ emailContentInfoDTOList.add(emailContentInfoDTO);
|
|
|
}
|
|
|
|
|
|
private void reMultipart(String account, String subject, Date emailDate, Multipart multipart,
|
|
@@ -741,8 +736,8 @@ public class EmailParseService {
|
|
|
Part bodyPart = multipart.getBodyPart(i);
|
|
|
Object content = bodyPart.getContent();
|
|
|
if (content instanceof String) {
|
|
|
- if (log.isInfoEnabled()) {
|
|
|
- log.info("邮件{} 获取的正文不做解析,内容是 {}", subject, content);
|
|
|
+ if (log.isDebugEnabled()) {
|
|
|
+ log.debug("邮件{} 获取的正文不做解析,内容是 {}", subject, content);
|
|
|
}
|
|
|
continue;
|
|
|
}
|