| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package com.ruoyi.common.utils;
-
- import lombok.extern.slf4j.Slf4j;
-
- import javax.mail.*;
- import javax.mail.internet.MimeMessage;
- import java.io.IOException;
-
- @Slf4j
- public final class EmailUtil {
-
- private static final String multipart = "multipart/*";
-
-
-
- public static String getMessageId(Part part, Session session) throws Exception {
- if (!part.isMimeType(multipart)) {
- return "";
-
- }
-
- Multipart multipart = (Multipart) part.getContent();
- for (int i = 0; i < multipart.getCount(); i++) {
- BodyPart bodyPart = multipart.getBodyPart(i);
- if(bodyPart.getContentType().contains("Message/Rfc822")){
- MimeMessage mimeMessage = new MimeMessage(session, bodyPart.getInputStream());
- if(mimeMessage.getSubject()!=null&&mimeMessage.getSubject().contains("调解书")){
- String[] split = mimeMessage.getSubject().split("调解书");
- if(split.length>0){
- return split[0];
- }
- }
- }
- } return "";
- }
-
- public static boolean isContainAttachment(Part part) {
- boolean attachFlag = false;
- try {
- if (part.isMimeType(multipart)) {
- Multipart mp = (Multipart) part.getContent();
- for (int i = 0; i < mp.getCount(); i++) {
- BodyPart mpart = mp.getBodyPart(i);
- String disposition = mpart.getDisposition();
- if ((disposition != null) && ((disposition.equals(Part.ATTACHMENT)) || (disposition.equals(Part.INLINE))))
- attachFlag = true;
- else if (mpart.isMimeType(multipart)) {
- attachFlag = isContainAttachment((Part) mpart);
- } else {
- String contype = mpart.getContentType();
- if (contype.toLowerCase().contains("application"))
- attachFlag = true;
- if (contype.toLowerCase().contains("name"))
- attachFlag = true;
- }
- }
- } else if (part.isMimeType("message/rfc822")) {
- attachFlag = isContainAttachment((Part) part.getContent());
- }
- } catch (MessagingException | IOException e) {
- e.printStackTrace();
- }
- return attachFlag;
- }
- }
|