import java.awt.Toolkit; import java.awt.datatransfer.StringSelection; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Properties; import javax.mail.Flags; import javax.mail.Folder; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Multipart; import javax.mail.Part; import javax.mail.Session; import javax.mail.Store; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeUtility; public class gotMail{ private MimeMessage mail = null; private StringBuffer bodytext = new StringBuffer(); //store mail content private String dateformat = "yy-MM-ddĦĦHH:mm";//date&time //Toolkit toolKit = Toolkit.getDefaultToolkit(); //Clipboard clipBoard = toolKit.getSystemClipboard(); public static void setClipboard(String str) { StringSelection ss = new StringSelection(str); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null); } /*public static void writeToClipboard(String writeMe) { // get the system clipboard Clipboard systemClipboard = Toolkit .getDefaultToolkit() .getSystemClipboard(); // set the textual content on the clipboard to our // Transferable object // we use the Transferable transferableText = new StringSelection(writeMe); systemClipboard.setContents( transferableText, null); }*/ /**init**/ public gotMail(){} public gotMail(MimeMessage mail){ this.mail = mail; System.out.println("New Email"); } /*public void setMail(MimeMessage mail){ this.mail = mail; }*/ /**get sender's address and name**/ public String getFrom()throws Exception{ InternetAddress address[] = (InternetAddress[])mail.getFrom(); String from = address[0].getAddress(); if(from == null){ from = "";} String personal = address[0].getPersonal(); if(personal == null) personal = ""; String fromaddr = personal+"<"+from+">"; return fromaddr; } /** get subject**/ public String getSubject()throws MessagingException{ String subject = ""; try{ subject = MimeUtility.decodeText(mail.getSubject()); if(subject == null){subject = "";} }catch(Exception exce){} return subject; } /**get sentdate**/ public String getSentDate()throws Exception{ Date sentdate = mail.getSentDate(); SimpleDateFormat format = new SimpleDateFormat(dateformat); return format.format(sentdate); } /**get content**/ public String getBodyText(){ return bodytext.toString(); } /**understand content**/ public void getMailContent(Part part)throws Exception{ String contenttype = part.getContentType(); int nameindex = contenttype.indexOf("name"); boolean conname = false; if(nameindex !=-1) conname = true; System.out.println("CONTENTTYPE:"+contenttype); if(part.isMimeType("text/plain")&&!conname){ bodytext.append((String)part.getContent()); }else if(part.isMimeType("text/html")&&!conname){ bodytext.append((String)part.getContent()); }else if(part.isMimeType("multipart/*")){ Multipart multipart = (Multipart)part.getContent(); int counts = multipart.getCount(); for(int i=0; i