From d1f26741bddf6f512d62c0100d42c52be8d37e76 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 06 二月 2021 15:35:40 +0800
Subject: [PATCH] 工具类优化

---
 utils/src/main/java/org/yeshi/utils/mail/ShowMail.java | 1296 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 648 insertions(+), 648 deletions(-)

diff --git a/utils/src/main/java/org/yeshi/utils/mail/ShowMail.java b/utils/src/main/java/org/yeshi/utils/mail/ShowMail.java
index 84c7925..800dae8 100644
--- a/utils/src/main/java/org/yeshi/utils/mail/ShowMail.java
+++ b/utils/src/main/java/org/yeshi/utils/mail/ShowMail.java
@@ -1,648 +1,648 @@
-package org.yeshi.utils.mail;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import javax.mail.BodyPart;
-import javax.mail.Flags;
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.Multipart;
-import javax.mail.Part;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeUtility;
-
-public class ShowMail {
-
-	private MimeMessage mimeMessage = null;
-
-	private String saveAttachPath = ""; // 闄勪欢涓嬭浇鍚庣殑瀛樻斁鐩綍
-
-	private StringBuffer bodyText = new StringBuffer(); // 瀛樻斁閭欢鍐呭鐨凷tringBuffer瀵硅薄
-
-	private String dateFormat = "yy-MM-dd HH:mm"; // 榛樿鐨勬棩鍓嶆樉绀烘牸寮�
-
-	/**
-	 * 
-	 * 鏋勯�犲嚱鏁�,鍒濆鍖栦竴涓狹imeMessage瀵硅薄
-	 * 
-	 */
-
-	public ShowMail() {
-
-	}
-
-	public ShowMail(MimeMessage mimeMessage) {
-
-		this.mimeMessage = mimeMessage;
-
-		// System.out.println("鍒涘缓涓�涓猂eceiveEmail瀵硅薄....");
-
-	}
-
-	public void setMimeMessage(MimeMessage mimeMessage) {
-
-		this.mimeMessage = mimeMessage;
-
-		// System.out.println("璁剧疆涓�涓狹imeMessage瀵硅薄...");
-
-	}
-
-	/**
-	 * 
-	 * * 鑾峰緱鍙戜欢浜虹殑鍦板潃鍜屽鍚�
-	 * 
-	 */
-
-	public String getFrom() throws Exception {
-
-		InternetAddress address[] = (InternetAddress[]) mimeMessage.getFrom();
-
-		String from = address[0].getAddress();
-
-		if (from == null) {
-
-			from = "";
-
-			// System.out.println("鏃犳硶鐭ラ亾鍙戦�佽��.");
-
-		}
-
-		String personal = address[0].getPersonal();
-
-		if (personal == null) {
-
-			personal = "";
-
-			// System.out.println("鏃犳硶鐭ラ亾鍙戦�佽�呯殑濮撳悕.");
-
-		}
-
-		String fromAddr = null;
-
-		if (personal != null || from != null) {
-			fromAddr = personal + "<" + from + ">";
-			// System.out.println("鍙戦�佽�呮槸锛�" + fromAddr);
-		}
-		return fromAddr;
-	}
-
-	/**
-	 * 
-	 * * 鑾峰緱閭欢鐨勬敹浠朵汉锛屾妱閫侊紝鍜屽瘑閫佺殑鍦板潃鍜屽鍚嶏紝鏍规嵁鎵�浼犻�掔殑鍙傛暟鐨勪笉鍚�
-	 * 
-	 * * "to"----鏀朵欢浜� "cc"---鎶勯�佷汉鍦板潃 "bcc"---瀵嗛�佷汉鍦板潃
-	 * 
-	 */
-
-	public String getMailAddress(String type) throws Exception {
-
-		String mailAddr = "";
-
-		String addType = type.toUpperCase();
-
-		InternetAddress[] address = null;
-
-		if (addType.equals("TO") || addType.equals("CC")
-
-				|| addType.equals("BCC")) {
-
-			if (addType.equals("TO")) {
-
-				address = (InternetAddress[]) mimeMessage
-
-						.getRecipients(Message.RecipientType.TO);
-
-			} else if (addType.equals("CC")) {
-
-				address = (InternetAddress[]) mimeMessage
-
-						.getRecipients(Message.RecipientType.CC);
-
-			} else {
-
-				address = (InternetAddress[]) mimeMessage
-
-						.getRecipients(Message.RecipientType.BCC);
-
-			}
-
-			if (address != null) {
-
-				for (int i = 0; i < address.length; i++) {
-
-					String emailAddr = address[i].getAddress();
-
-					if (emailAddr == null) {
-
-						emailAddr = "";
-
-					} else {
-
-						// System.out.println("杞崲涔嬪墠鐨別mailAddr: " + emailAddr);
-
-						emailAddr = MimeUtility.decodeText(emailAddr);
-
-						// System.out.println("杞崲涔嬪悗鐨別mailAddr: " + emailAddr);
-
-					}
-
-					String personal = address[i].getPersonal();
-
-					if (personal == null) {
-
-						personal = "";
-
-					} else {
-
-						// System.out.println("杞崲涔嬪墠鐨刾ersonal: " + personal);
-
-						personal = MimeUtility.decodeText(personal);
-
-						// System.out.println("杞崲涔嬪悗鐨刾ersonal: " + personal);
-
-					}
-
-					String compositeto = personal + "<" + emailAddr + ">";
-
-					// System.out.println("瀹屾暣鐨勯偖浠跺湴鍧�锛�" + compositeto);
-
-					mailAddr += "," + compositeto;
-
-				}
-
-				mailAddr = mailAddr.substring(1);
-
-			}
-
-		} else {
-
-			throw new Exception("閿欒鐨勭數瀛愰偖浠剁被鍨�!");
-
-		}
-
-		return mailAddr;
-
-	}
-
-	/**
-	 * 
-	 * * 鑾峰緱閭欢涓婚
-	 * 
-	 */
-
-	public String getSubject() throws MessagingException {
-
-		String subject = "";
-
-		try {
-
-			// System.out.println("杞崲鍓嶇殑subject锛�" + mimeMessage.getSubject());
-
-			subject = MimeUtility.decodeText(mimeMessage.getSubject());
-
-			// System.out.println("杞崲鍚庣殑subject: " + mimeMessage.getSubject());
-
-			if (subject == null) {
-
-				subject = "";
-
-			}
-
-		} catch (Exception exce) {
-
-			exce.printStackTrace();
-
-		}
-
-		return subject;
-
-	}
-
-	/**
-	 * 
-	 * * 鑾峰緱閭欢鍙戦�佹棩鏈�
-	 * 
-	 */
-
-	public String getSentDate() throws Exception {
-
-		Date sentDate = mimeMessage.getSentDate();
-
-		// System.out.println("鍙戦�佹棩鏈� 鍘熷绫诲瀷: " + dateFormat);
-
-		SimpleDateFormat format = new SimpleDateFormat(dateFormat);
-
-		String strSentDate = format.format(sentDate);
-
-		// System.out.println("鍙戦�佹棩鏈� 鍙绫诲瀷: " + strSentDate);
-
-		return strSentDate;
-
-	}
-
-	/**
-	 * 
-	 * * 鑾峰緱閭欢姝f枃鍐呭
-	 * 
-	 */
-
-	public String getBodyText() {
-
-		return bodyText.toString();
-
-	}
-
-	/**
-	 * 
-	 * * 瑙f瀽閭欢锛屾妸寰楀埌鐨勯偖浠跺唴瀹逛繚瀛樺埌涓�涓猄tringBuffer瀵硅薄涓紝瑙f瀽閭欢
-	 * 
-	 * * 涓昏鏄牴鎹甅imeType绫诲瀷鐨勪笉鍚屾墽琛屼笉鍚岀殑鎿嶄綔锛屼竴姝ヤ竴姝ョ殑瑙f瀽
-	 * 
-	 */
-
-	public void getMailContent(Part part) throws Exception {
-
-		String contentType = part.getContentType();
-
-		// 鑾峰緱閭欢鐨凪imeType绫诲瀷
-
-		// System.out.println("閭欢鐨凪imeType绫诲瀷: " + contentType);
-
-		int nameIndex = contentType.indexOf("name");
-
-		boolean conName = false;
-
-		if (nameIndex != -1) {
-
-			conName = true;
-
-		}
-
-		// System.out.println("閭欢鍐呭鐨勭被鍨�: " + contentType);
-
-		if (part.isMimeType("text/plain") && conName == false) {
-
-			// text/plain 绫诲瀷
-
-			bodyText.append((String) part.getContent());
-
-		} else if (part.isMimeType("text/html") && conName == false) {
-
-			// text/html 绫诲瀷
-
-			bodyText.append((String) part.getContent());
-
-		} else if (part.isMimeType("multipart/*")) {
-
-			// multipart/*
-
-			Multipart multipart = (Multipart) part.getContent();
-
-			int counts = multipart.getCount();
-
-			for (int i = 0; i < counts; i++) {
-
-				getMailContent(multipart.getBodyPart(i));
-
-			}
-
-		} else if (part.isMimeType("message/rfc822")) {
-
-			// message/rfc822
-
-			getMailContent((Part) part.getContent());
-
-		} else {
-
-		}
-
-	}
-
-	/**
-	 * 
-	 * * 鍒ゆ柇姝ら偖浠舵槸鍚﹂渶瑕佸洖鎵э紝濡傛灉闇�瑕佸洖鎵ц繑鍥�"true",鍚﹀垯杩斿洖"false"
-	 * 
-	 */
-
-	public boolean getReplySign() throws MessagingException {
-
-		boolean replySign = false;
-
-		String needReply[] = mimeMessage
-
-				.getHeader("Disposition-Notification-To");
-
-		if (needReply != null) {
-
-			replySign = true;
-
-		}
-
-		if (replySign) {
-
-			// System.out.println("璇ラ偖浠堕渶瑕佸洖澶�");
-
-		} else {
-
-			// System.out.println("璇ラ偖浠朵笉闇�瑕佸洖澶�");
-
-		}
-
-		return replySign;
-
-	}
-
-	/**
-	 * 
-	 * 鑾峰緱姝ら偖浠剁殑Message-ID
-	 * 
-	 */
-
-	public String getMessageId() throws MessagingException {
-
-		String messageID = mimeMessage.getMessageID();
-
-		// System.out.println("閭欢ID: " + messageID);
-
-		return messageID;
-
-	}
-
-	/**
-	 * 
-	 * 鍒ゆ柇姝ら偖浠舵槸鍚﹀凡璇伙紝濡傛灉鏈杩斿洖false,鍙嶄箣杩斿洖true
-	 * 
-	 */
-
-	public boolean isNew() throws MessagingException {
-
-		boolean isNew = false;
-
-		Flags flags = ((Message) mimeMessage).getFlags();
-
-		Flags.Flag[] flag = flags.getSystemFlags();
-
-		// System.out.println("flags鐨勯暱搴�: " + flag.length);
-
-		for (int i = 0; i < flag.length; i++) {
-
-			if (flag[i] == Flags.Flag.SEEN) {
-
-				isNew = true;
-
-				// System.out.println("seen email...");
-
-				// break;
-
-			}
-
-		}
-
-		return isNew;
-
-	}
-
-	/**
-	 * 
-	 * 鍒ゆ柇姝ら偖浠舵槸鍚﹀寘鍚檮浠�
-	 * 
-	 */
-
-	public boolean isContainAttach(Part part) throws Exception {
-
-		boolean attachFlag = false;
-
-		// String contentType = part.getContentType();
-
-		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 = isContainAttach((Part) mPart);
-
-				} else {
-
-					String conType = mPart.getContentType();
-
-					if (conType.toLowerCase().indexOf("application") != -1)
-
-						attachFlag = true;
-
-					if (conType.toLowerCase().indexOf("name") != -1)
-
-						attachFlag = true;
-
-				}
-
-			}
-
-		} else if (part.isMimeType("message/rfc822")) {
-
-			attachFlag = isContainAttach((Part) part.getContent());
-
-		}
-
-		return attachFlag;
-
-	}
-
-	/**
-	 * 
-	 * * 淇濆瓨闄勪欢
-	 * 
-	 */
-
-	public List<InputStream> saveAttachMent(Part part) throws Exception {
-
-		List<InputStream> inputStreamList = new ArrayList<>();
-		String fileName = "";
-
-		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)))) {
-
-					fileName = mPart.getFileName();
-
-					if (fileName.toLowerCase().indexOf("gb2312") != -1) {
-						fileName = MimeUtility.decodeText(fileName);
-					}
-					inputStreamList.add(mPart.getInputStream());
-				} else if (mPart.isMimeType("multipart/*")) {
-					saveAttachMent(mPart);
-
-				} else {
-
-					fileName = mPart.getFileName();
-
-					if ((fileName != null)
-
-							&& (fileName.toLowerCase().indexOf("GB2312") != -1)) {
-
-						fileName = MimeUtility.decodeText(fileName);
-						inputStreamList.add(mPart.getInputStream());
-					}
-				}
-			}
-
-		} else if (part.isMimeType("message/rfc822")) {
-			saveAttachMent((Part) part.getContent());
-		}
-		return inputStreamList;
-	}
-
-	/**
-	 * 
-	 * 璁剧疆闄勪欢瀛樻斁璺緞
-	 * 
-	 */
-
-	public void setAttachPath(String attachPath) {
-
-		this.saveAttachPath = attachPath;
-
-	}
-
-	/**
-	 * 
-	 * * 璁剧疆鏃ユ湡鏄剧ず鏍煎紡
-	 * 
-	 */
-
-	public void setDateFormat(String format) throws Exception {
-
-		this.dateFormat = format;
-
-	}
-
-	/**
-	 * 
-	 * * 鑾峰緱闄勪欢瀛樻斁璺緞
-	 * 
-	 */
-
-	public String getAttachPath() {
-
-		return saveAttachPath;
-
-	}
-
-	/**
-	 * 
-	 * * 鐪熸鐨勪繚瀛橀檮浠跺埌鎸囧畾鐩綍閲�
-	 * 
-	 */
-
-	private void saveFile(String fileName, InputStream in) throws Exception {
-
-		String osName = System.getProperty("os.name");
-
-		String storeDir = getAttachPath();
-
-		String separator = "";
-
-		if (osName == null) {
-
-			osName = "";
-
-		}
-
-		if (osName.toLowerCase().indexOf("win") != -1) {
-
-			separator = "\\";
-
-			if (storeDir == null || storeDir.equals(""))
-
-				storeDir = "c:\\tmp";
-
-		} else {
-
-			separator = "/";
-
-			storeDir = "/tmp";
-
-		}
-
-		File storeFile = new File(storeDir + separator + fileName);
-
-		// System.out.println("闄勪欢鐨勪繚瀛樺湴鍧�: " + storeFile.toString());
-
-		// for(int i=0;storefile.exists();i++){
-
-		// storefile = new File(storedir+separator+fileName+i);
-
-		// }
-
-		BufferedOutputStream bos = null;
-
-		BufferedInputStream bis = null;
-
-		try {
-
-			bos = new BufferedOutputStream(new FileOutputStream(storeFile));
-
-			bis = new BufferedInputStream(in);
-
-			int c;
-
-			while ((c = bis.read()) != -1) {
-
-				bos.write(c);
-
-				bos.flush();
-
-			}
-
-		} catch (Exception exception) {
-
-			exception.printStackTrace();
-
-			throw new Exception("鏂囦欢淇濆瓨澶辫触!");
-
-		} finally {
-
-			bos.close();
-
-			bis.close();
-
-		}
-
-	}
-
-}
+package org.yeshi.utils.mail;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.mail.BodyPart;
+import javax.mail.Flags;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Multipart;
+import javax.mail.Part;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeUtility;
+
+public class ShowMail {
+
+	private MimeMessage mimeMessage = null;
+
+	private String saveAttachPath = ""; // 闄勪欢涓嬭浇鍚庣殑瀛樻斁鐩綍
+
+	private StringBuffer bodyText = new StringBuffer(); // 瀛樻斁閭欢鍐呭鐨凷tringBuffer瀵硅薄
+
+	private String dateFormat = "yy-MM-dd HH:mm"; // 榛樿鐨勬棩鍓嶆樉绀烘牸寮�
+
+	/**
+	 * 
+	 * 鏋勯�犲嚱鏁�,鍒濆鍖栦竴涓狹imeMessage瀵硅薄
+	 * 
+	 */
+
+	public ShowMail() {
+
+	}
+
+	public ShowMail(MimeMessage mimeMessage) {
+
+		this.mimeMessage = mimeMessage;
+
+		// System.out.println("鍒涘缓涓�涓猂eceiveEmail瀵硅薄....");
+
+	}
+
+	public void setMimeMessage(MimeMessage mimeMessage) {
+
+		this.mimeMessage = mimeMessage;
+
+		// System.out.println("璁剧疆涓�涓狹imeMessage瀵硅薄...");
+
+	}
+
+	/**
+	 * 
+	 * * 鑾峰緱鍙戜欢浜虹殑鍦板潃鍜屽鍚�
+	 * 
+	 */
+
+	public String getFrom() throws Exception {
+
+		InternetAddress address[] = (InternetAddress[]) mimeMessage.getFrom();
+
+		String from = address[0].getAddress();
+
+		if (from == null) {
+
+			from = "";
+
+			// System.out.println("鏃犳硶鐭ラ亾鍙戦�佽��.");
+
+		}
+
+		String personal = address[0].getPersonal();
+
+		if (personal == null) {
+
+			personal = "";
+
+			// System.out.println("鏃犳硶鐭ラ亾鍙戦�佽�呯殑濮撳悕.");
+
+		}
+
+		String fromAddr = null;
+
+		if (personal != null || from != null) {
+			fromAddr = personal + "<" + from + ">";
+			// System.out.println("鍙戦�佽�呮槸锛�" + fromAddr);
+		}
+		return fromAddr;
+	}
+
+	/**
+	 * 
+	 * * 鑾峰緱閭欢鐨勬敹浠朵汉锛屾妱閫侊紝鍜屽瘑閫佺殑鍦板潃鍜屽鍚嶏紝鏍规嵁鎵�浼犻�掔殑鍙傛暟鐨勪笉鍚�
+	 * 
+	 * * "to"----鏀朵欢浜� "cc"---鎶勯�佷汉鍦板潃 "bcc"---瀵嗛�佷汉鍦板潃
+	 * 
+	 */
+
+	public String getMailAddress(String type) throws Exception {
+
+		String mailAddr = "";
+
+		String addType = type.toUpperCase();
+
+		InternetAddress[] address = null;
+
+		if (addType.equals("TO") || addType.equals("CC")
+
+				|| addType.equals("BCC")) {
+
+			if (addType.equals("TO")) {
+
+				address = (InternetAddress[]) mimeMessage
+
+						.getRecipients(Message.RecipientType.TO);
+
+			} else if (addType.equals("CC")) {
+
+				address = (InternetAddress[]) mimeMessage
+
+						.getRecipients(Message.RecipientType.CC);
+
+			} else {
+
+				address = (InternetAddress[]) mimeMessage
+
+						.getRecipients(Message.RecipientType.BCC);
+
+			}
+
+			if (address != null) {
+
+				for (int i = 0; i < address.length; i++) {
+
+					String emailAddr = address[i].getAddress();
+
+					if (emailAddr == null) {
+
+						emailAddr = "";
+
+					} else {
+
+						// System.out.println("杞崲涔嬪墠鐨別mailAddr: " + emailAddr);
+
+						emailAddr = MimeUtility.decodeText(emailAddr);
+
+						// System.out.println("杞崲涔嬪悗鐨別mailAddr: " + emailAddr);
+
+					}
+
+					String personal = address[i].getPersonal();
+
+					if (personal == null) {
+
+						personal = "";
+
+					} else {
+
+						// System.out.println("杞崲涔嬪墠鐨刾ersonal: " + personal);
+
+						personal = MimeUtility.decodeText(personal);
+
+						// System.out.println("杞崲涔嬪悗鐨刾ersonal: " + personal);
+
+					}
+
+					String compositeto = personal + "<" + emailAddr + ">";
+
+					// System.out.println("瀹屾暣鐨勯偖浠跺湴鍧�锛�" + compositeto);
+
+					mailAddr += "," + compositeto;
+
+				}
+
+				mailAddr = mailAddr.substring(1);
+
+			}
+
+		} else {
+
+			throw new Exception("閿欒鐨勭數瀛愰偖浠剁被鍨�!");
+
+		}
+
+		return mailAddr;
+
+	}
+
+	/**
+	 * 
+	 * * 鑾峰緱閭欢涓婚
+	 * 
+	 */
+
+	public String getSubject() throws MessagingException {
+
+		String subject = "";
+
+		try {
+
+			// System.out.println("杞崲鍓嶇殑subject锛�" + mimeMessage.getSubject());
+
+			subject = MimeUtility.decodeText(mimeMessage.getSubject());
+
+			// System.out.println("杞崲鍚庣殑subject: " + mimeMessage.getSubject());
+
+			if (subject == null) {
+
+				subject = "";
+
+			}
+
+		} catch (Exception exce) {
+
+			exce.printStackTrace();
+
+		}
+
+		return subject;
+
+	}
+
+	/**
+	 * 
+	 * * 鑾峰緱閭欢鍙戦�佹棩鏈�
+	 * 
+	 */
+
+	public String getSentDate() throws Exception {
+
+		Date sentDate = mimeMessage.getSentDate();
+
+		// System.out.println("鍙戦�佹棩鏈� 鍘熷绫诲瀷: " + dateFormat);
+
+		SimpleDateFormat format = new SimpleDateFormat(dateFormat);
+
+		String strSentDate = format.format(sentDate);
+
+		// System.out.println("鍙戦�佹棩鏈� 鍙绫诲瀷: " + strSentDate);
+
+		return strSentDate;
+
+	}
+
+	/**
+	 * 
+	 * * 鑾峰緱閭欢姝f枃鍐呭
+	 * 
+	 */
+
+	public String getBodyText() {
+
+		return bodyText.toString();
+
+	}
+
+	/**
+	 * 
+	 * * 瑙f瀽閭欢锛屾妸寰楀埌鐨勯偖浠跺唴瀹逛繚瀛樺埌涓�涓猄tringBuffer瀵硅薄涓紝瑙f瀽閭欢
+	 * 
+	 * * 涓昏鏄牴鎹甅imeType绫诲瀷鐨勪笉鍚屾墽琛屼笉鍚岀殑鎿嶄綔锛屼竴姝ヤ竴姝ョ殑瑙f瀽
+	 * 
+	 */
+
+	public void getMailContent(Part part) throws Exception {
+
+		String contentType = part.getContentType();
+
+		// 鑾峰緱閭欢鐨凪imeType绫诲瀷
+
+		// System.out.println("閭欢鐨凪imeType绫诲瀷: " + contentType);
+
+		int nameIndex = contentType.indexOf("name");
+
+		boolean conName = false;
+
+		if (nameIndex != -1) {
+
+			conName = true;
+
+		}
+
+		// System.out.println("閭欢鍐呭鐨勭被鍨�: " + contentType);
+
+		if (part.isMimeType("text/plain") && conName == false) {
+
+			// text/plain 绫诲瀷
+
+			bodyText.append((String) part.getContent());
+
+		} else if (part.isMimeType("text/html") && conName == false) {
+
+			// text/html 绫诲瀷
+
+			bodyText.append((String) part.getContent());
+
+		} else if (part.isMimeType("multipart/*")) {
+
+			// multipart/*
+
+			Multipart multipart = (Multipart) part.getContent();
+
+			int counts = multipart.getCount();
+
+			for (int i = 0; i < counts; i++) {
+
+				getMailContent(multipart.getBodyPart(i));
+
+			}
+
+		} else if (part.isMimeType("message/rfc822")) {
+
+			// message/rfc822
+
+			getMailContent((Part) part.getContent());
+
+		} else {
+
+		}
+
+	}
+
+	/**
+	 * 
+	 * * 鍒ゆ柇姝ら偖浠舵槸鍚﹂渶瑕佸洖鎵э紝濡傛灉闇�瑕佸洖鎵ц繑鍥�"true",鍚﹀垯杩斿洖"false"
+	 * 
+	 */
+
+	public boolean getReplySign() throws MessagingException {
+
+		boolean replySign = false;
+
+		String needReply[] = mimeMessage
+
+				.getHeader("Disposition-Notification-To");
+
+		if (needReply != null) {
+
+			replySign = true;
+
+		}
+
+		if (replySign) {
+
+			// System.out.println("璇ラ偖浠堕渶瑕佸洖澶�");
+
+		} else {
+
+			// System.out.println("璇ラ偖浠朵笉闇�瑕佸洖澶�");
+
+		}
+
+		return replySign;
+
+	}
+
+	/**
+	 * 
+	 * 鑾峰緱姝ら偖浠剁殑Message-ID
+	 * 
+	 */
+
+	public String getMessageId() throws MessagingException {
+
+		String messageID = mimeMessage.getMessageID();
+
+		// System.out.println("閭欢ID: " + messageID);
+
+		return messageID;
+
+	}
+
+	/**
+	 * 
+	 * 鍒ゆ柇姝ら偖浠舵槸鍚﹀凡璇伙紝濡傛灉鏈杩斿洖false,鍙嶄箣杩斿洖true
+	 * 
+	 */
+
+	public boolean isNew() throws MessagingException {
+
+		boolean isNew = false;
+
+		Flags flags = ((Message) mimeMessage).getFlags();
+
+		Flags.Flag[] flag = flags.getSystemFlags();
+
+		// System.out.println("flags鐨勯暱搴�: " + flag.length);
+
+		for (int i = 0; i < flag.length; i++) {
+
+			if (flag[i] == Flags.Flag.SEEN) {
+
+				isNew = true;
+
+				// System.out.println("seen email...");
+
+				// break;
+
+			}
+
+		}
+
+		return isNew;
+
+	}
+
+	/**
+	 * 
+	 * 鍒ゆ柇姝ら偖浠舵槸鍚﹀寘鍚檮浠�
+	 * 
+	 */
+
+	public boolean isContainAttach(Part part) throws Exception {
+
+		boolean attachFlag = false;
+
+		// String contentType = part.getContentType();
+
+		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 = isContainAttach((Part) mPart);
+
+				} else {
+
+					String conType = mPart.getContentType();
+
+					if (conType.toLowerCase().indexOf("application") != -1)
+
+						attachFlag = true;
+
+					if (conType.toLowerCase().indexOf("name") != -1)
+
+						attachFlag = true;
+
+				}
+
+			}
+
+		} else if (part.isMimeType("message/rfc822")) {
+
+			attachFlag = isContainAttach((Part) part.getContent());
+
+		}
+
+		return attachFlag;
+
+	}
+
+	/**
+	 * 
+	 * * 淇濆瓨闄勪欢
+	 * 
+	 */
+
+	public List<InputStream> saveAttachMent(Part part) throws Exception {
+
+		List<InputStream> inputStreamList = new ArrayList<>();
+		String fileName = "";
+
+		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)))) {
+
+					fileName = mPart.getFileName();
+
+					if (fileName.toLowerCase().indexOf("gb2312") != -1) {
+						fileName = MimeUtility.decodeText(fileName);
+					}
+					inputStreamList.add(mPart.getInputStream());
+				} else if (mPart.isMimeType("multipart/*")) {
+					saveAttachMent(mPart);
+
+				} else {
+
+					fileName = mPart.getFileName();
+
+					if ((fileName != null)
+
+							&& (fileName.toLowerCase().indexOf("GB2312") != -1)) {
+
+						fileName = MimeUtility.decodeText(fileName);
+						inputStreamList.add(mPart.getInputStream());
+					}
+				}
+			}
+
+		} else if (part.isMimeType("message/rfc822")) {
+			saveAttachMent((Part) part.getContent());
+		}
+		return inputStreamList;
+	}
+
+	/**
+	 * 
+	 * 璁剧疆闄勪欢瀛樻斁璺緞
+	 * 
+	 */
+
+	public void setAttachPath(String attachPath) {
+
+		this.saveAttachPath = attachPath;
+
+	}
+
+	/**
+	 * 
+	 * * 璁剧疆鏃ユ湡鏄剧ず鏍煎紡
+	 * 
+	 */
+
+	public void setDateFormat(String format) throws Exception {
+
+		this.dateFormat = format;
+
+	}
+
+	/**
+	 * 
+	 * * 鑾峰緱闄勪欢瀛樻斁璺緞
+	 * 
+	 */
+
+	public String getAttachPath() {
+
+		return saveAttachPath;
+
+	}
+
+	/**
+	 * 
+	 * * 鐪熸鐨勪繚瀛橀檮浠跺埌鎸囧畾鐩綍閲�
+	 * 
+	 */
+
+	private void saveFile(String fileName, InputStream in) throws Exception {
+
+		String osName = System.getProperty("os.name");
+
+		String storeDir = getAttachPath();
+
+		String separator = "";
+
+		if (osName == null) {
+
+			osName = "";
+
+		}
+
+		if (osName.toLowerCase().indexOf("win") != -1) {
+
+			separator = "\\";
+
+			if (storeDir == null || storeDir.equals(""))
+
+				storeDir = "c:\\tmp";
+
+		} else {
+
+			separator = "/";
+
+			storeDir = "/tmp";
+
+		}
+
+		File storeFile = new File(storeDir + separator + fileName);
+
+		// System.out.println("闄勪欢鐨勪繚瀛樺湴鍧�: " + storeFile.toString());
+
+		// for(int i=0;storefile.exists();i++){
+
+		// storefile = new File(storedir+separator+fileName+i);
+
+		// }
+
+		BufferedOutputStream bos = null;
+
+		BufferedInputStream bis = null;
+
+		try {
+
+			bos = new BufferedOutputStream(new FileOutputStream(storeFile));
+
+			bis = new BufferedInputStream(in);
+
+			int c;
+
+			while ((c = bis.read()) != -1) {
+
+				bos.write(c);
+
+				bos.flush();
+
+			}
+
+		} catch (Exception exception) {
+
+			exception.printStackTrace();
+
+			throw new Exception("鏂囦欢淇濆瓨澶辫触!");
+
+		} finally {
+
+			bos.close();
+
+			bis.close();
+
+		}
+
+	}
+
+}

--
Gitblit v1.8.0