1 25 26 package net.killingar.actions.email; 27 28 import javax.mail.FetchProfile ; 29 import javax.mail.Folder ; 30 import javax.mail.MessagingException ; 31 import java.util.ArrayList ; 32 33 public class List 34 extends MailSupport 35 { 36 38 39 java.util.List messages; 41 Folder folder; 42 43 public java.util.List getMessages() { return messages; } 45 public Folder getFolder() { return folder; } 46 47 49 public String doExecute() 51 { 52 try 53 { 54 folder = mailStore.getDefaultFolder(); 56 folder = folder.getFolder("INBOX"); 57 try 58 { 59 folder.open(Folder.READ_WRITE); 60 } 61 catch (MessagingException ex) 62 { 63 folder.open(Folder.READ_ONLY); 64 System.err.println("net.killingar.actions.email.List: opened folder as read only"); 65 } 66 int totalMessages = folder.getMessageCount(); 67 int newMessages = folder.getNewMessageCount(); 68 69 javax.mail.Message [] msgs = folder.getMessages(); 70 FetchProfile fp = new FetchProfile (); 72 fp.add(FetchProfile.Item.ENVELOPE); 73 fp.add(FetchProfile.Item.FLAGS); 74 fp.add("X-Mailer"); 75 folder.fetch(msgs, fp); 76 77 messages = new ArrayList (); 78 for (int i = 0; i < msgs.length; i++) 79 messages.add(new Mail(msgs[i])); 80 } 81 catch (Exception e) 82 { 83 addErrorMessage("viewing mailbox failed, exception thrown ("+e.toString()+")"); 84 e.printStackTrace(); 85 86 return ERROR; 87 } 88 89 return SUCCESS; 90 } 91 92 public void cleanup() 93 { 94 try 95 { 96 folder.close(true); 97 super.cleanup(); 98 } 99 catch (Exception e){} } 101 } 102 | Popular Tags |