Bläddra i källkod

fix:附件检测优化

wangzaijun 1 månad sedan
förälder
incheckning
84aa98694b

+ 16 - 9
mo-daq/src/main/java/com/smppw/modaq/domain/service/EmailParseService.java

@@ -41,7 +41,6 @@ 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;
 
@@ -65,6 +64,16 @@ public class EmailParseService {
     //    public static final int stepSize = 10000;
     private static final Logger log = LoggerFactory.getLogger(EmailParseService.class);
 
+    // 扩展支持的 MIME 类型
+    private static final Set<String> attachmentMimePrefixes = Set.of(
+            "application/pdf",
+            "application/zip",
+            "application/x-zip-compressed",
+            "application/rar",
+            "application/x-rar-compressed"
+            // 按需添加其他类型...
+    );
+
     //    private final EmailFieldMappingMapper emailFieldMapper;
     private final EmailParseInfoMapper emailParseInfoMapper;
     private final EmailFileInfoMapper emailFileInfoMapper;
@@ -694,15 +703,13 @@ public class EmailParseService {
         }
         String disposition = part.getDisposition();
         String contentType = part.getContentType();
-        if (log.isInfoEnabled()) {
-            log.info("邮件{} 附件(of={}, fileName={},disposition={},contentType={})",
-                    subject, part.getFileName(), fileName, disposition, contentType);
-        }
-        boolean isAttachment =
-                (disposition != null && (disposition.equalsIgnoreCase(Part.ATTACHMENT))) ||
-                        StrUtil.startWithIgnoreCase(contentType, MediaType.APPLICATION_PDF.toString());
+
+        boolean isAttachment = Part.ATTACHMENT.equalsIgnoreCase(disposition)
+                || (contentType != null && attachmentMimePrefixes.stream().anyMatch(prefix ->
+                StrUtil.startWithIgnoreCase(contentType, prefix)
+        ));
         if (!isAttachment) {
-            log.warn("邮件{} 没有附件(fileName={},disposition={},contentType={}),下载不了附件内容!",
+            log.warn("邮件 {} 未检测到pdf/zip/rar类型的附件 (fileName={}, disposition={}, contentType={})",
                     subject, fileName, disposition, contentType);
             return;
         }