Jelajahi Sumber

feat: html编码统一改成UTF-8

chenjianhua 6 bulan lalu
induk
melakukan
49796d5ed4

+ 10 - 3
service-base/src/main/java/com/simuwang/base/common/util/EmailUtil.java

@@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.mail.javamail.JavaMailSender;
 
 import java.io.File;
+import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.*;
@@ -172,8 +173,16 @@ public class EmailUtil {
                             saveFile.getParentFile().setExecutable(true);
                         }
                     }
+                    //获取邮件编码
+                    String contentType = part.getContentType();
+                    String html = partContent.toString();
                     try{
-                        FileUtils.write(new File(savePath), partContent.toString());
+                        if(contentType.indexOf("charset=") != -1){
+                            contentType = contentType.substring(contentType.indexOf("charset=")+8,contentType.length());
+                            html = html.replace("charset="+contentType.toLowerCase(),"charset=UTF-8");
+                            html = html.replace("charset="+contentType.toUpperCase(),"charset=UTF-8");
+                        }
+                        FileUtils.write(new File(savePath), html);
                     }catch (Exception e){
                         logger.error(e.getMessage(),e);
                     }
@@ -314,8 +323,6 @@ public class EmailUtil {
             properties.setProperty("mail.smtp.socketFactory.port", mailboxInfoDTO.getPort());
             properties.put("mail.smtp.ssl.enable", true);
             // 根据邮件的会话属性构造一个发送邮件的Session,
-            //这里需要注意的是用户名那里不能加后缀,否则便不是用户名了
-            //还需要注意的是,这里的密码不是正常使用邮箱的登陆密码,而是客户端生成的另一个专门的授权码
             JakartaUserPassAuthenticator authenticator = new JakartaUserPassAuthenticator(mailboxInfoDTO.getAccount(), mailboxInfoDTO.getPassword());
             Session session = Session.getInstance(properties, authenticator);
             return session;

+ 3 - 0
service-daq/src/main/java/com/simuwang/daq/service/EmailParseService.java

@@ -838,6 +838,9 @@ public class EmailParseService {
                     continue;
                 }
                 log.info("邮件采集成功 -> 邮件主题:{},邮件日期:{}", message.getSubject(), emailDateStr);
+                if(message.getSubject().contains("盖亚青柯中证1000指数增强1号私募证券投资基金SZK192")){
+                    System.out.println("============");
+                }
                 Object content = message.getContent();
                 // 1.邮件为MIME多部分消息体:可能既有邮件又有正文
                 if (content instanceof MimeMultipart) {