|
@@ -683,24 +683,28 @@ public class EmailParseService {
|
|
|
|
|
|
private void rePart(String account, String subject, Date sendDate, Part part,
|
|
|
List<EmailContentInfoDTO> emailContentInfoDTOList) throws Exception {
|
|
|
- String disposition = part.getDisposition();
|
|
|
- if (disposition != null && (disposition.equals(Part.ATTACHMENT) || disposition.equals(Part.INLINE))) {
|
|
|
- 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;
|
|
|
-
|
|
|
- EmailContentInfoDTO emailContentInfoDTO = new EmailContentInfoDTO();
|
|
|
-
|
|
|
- String fileName = MimeUtility.decodeText(part.getFileName());
|
|
|
- emailContentInfoDTO.setFileName(fileName);
|
|
|
- emailContentInfoDTO.setFileSize(part.getSize());
|
|
|
+ String fileName = part.getFileName();
|
|
|
+ if (StrUtil.isBlank(fileName)) {
|
|
|
+ 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();
|
|
|
if (log.isInfoEnabled()) {
|
|
|
- log.info("邮件{} 大小:{}byte 开始下载。。。。。", subject, part.getSize());
|
|
|
+ log.info("邮件{} 大小:{}byte 开始下载。。。。。", subject, size);
|
|
|
}
|
|
|
|
|
|
+ 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()) {
|
|
@@ -714,19 +718,19 @@ public class EmailParseService {
|
|
|
cn.hutool.core.io.FileUtil.del(saveFile);
|
|
|
FileUtil.saveFile(saveFile, part);
|
|
|
}
|
|
|
- emailContentInfoDTO.setFilePath(saveFile.getAbsolutePath());
|
|
|
|
|
|
+ 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);
|
|
|
} else {
|
|
|
- String filename = null;
|
|
|
- if (part.getFileName() != null) {
|
|
|
- filename = MimeUtility.decodeText(part.getFileName());
|
|
|
- }
|
|
|
if (log.isInfoEnabled()) {
|
|
|
- log.info("邮件{} 没有附件(fileName={},disposition={}),下载不了附件内容!", subject, filename, disposition);
|
|
|
+ log.info("邮件{} 没有附件(fileName={},disposition={},contentType={}),下载不了附件内容!",
|
|
|
+ subject, fileName, disposition, contentType);
|
|
|
}
|
|
|
}
|
|
|
}
|