1 17 18 package org.apache.james.fetchmail; 19 20 import javax.mail.Folder ; 21 import javax.mail.MessagingException ; 22 import javax.mail.Session ; 23 import javax.mail.Store ; 24 25 31 public class StoreProcessor extends ProcessorAbstract 32 { 33 37 protected StoreProcessor(Account account) 38 { 39 super(account); 40 } 41 42 49 public void process() throws MessagingException 50 { 51 Store store = null; 52 Folder folder = null; 53 54 StringBuffer logMessageBuffer = 55 new StringBuffer ("Starting fetching mail from server '"); 56 logMessageBuffer.append(getHost()); 57 logMessageBuffer.append("' for user '"); 58 logMessageBuffer.append(getUser()); 59 logMessageBuffer.append("' in folder '"); 60 logMessageBuffer.append(getJavaMailFolderName()); 61 logMessageBuffer.append("'"); 62 getLogger().info(logMessageBuffer.toString()); 63 64 try 65 { 66 store = getSession().getStore(getJavaMailProviderName()); 68 69 if (getHost() != null 71 || getUser() != null 72 || getPassword() != null) 73 store.connect(getHost(), getUser(), getPassword()); 74 else 75 store.connect(); 76 77 folder = store.getFolder(getJavaMailFolderName()); 79 if (folder == null) 80 getLogger().error(getFetchTaskName() + " No default folder"); 81 82 new FolderProcessor(folder, getAccount()).process(); 84 85 } 86 catch (MessagingException ex) 87 { 88 getLogger().error( 89 "A MessagingException has terminated processing of this Folder", 90 ex); 91 } 92 finally 93 { 94 try 95 { 96 if (null != store && store.isConnected()) 97 store.close(); 98 } 99 catch (MessagingException ex) 100 { 101 getLogger().error( 102 "A MessagingException occured while closing the Store", 103 ex); 104 } 105 logMessageBuffer = 106 new StringBuffer ("Finished fetching mail from server '"); 107 logMessageBuffer.append(getHost()); 108 logMessageBuffer.append("' for user '"); 109 logMessageBuffer.append(getUser()); 110 logMessageBuffer.append("' in folder '"); 111 logMessageBuffer.append(getJavaMailFolderName()); 112 logMessageBuffer.append("'"); 113 getLogger().info(logMessageBuffer.toString()); 114 } 115 } 116 117 } 118 | Popular Tags |