1 package net.suberic.pooka; 2 import javax.mail.*; 3 import net.suberic.pooka.filter.FilterAction; 4 import java.util.List ; 5 import java.util.LinkedList ; 6 7 10 public class MultiMessageInfo extends MessageInfo { 11 12 MessageInfo[] messages; 13 14 17 public MultiMessageInfo(MessageInfo[] newMessageInfos) { 18 messages = newMessageInfos; 19 } 20 21 26 public MultiMessageInfo(MessageInfo[] newMessageInfos, FolderInfo newFolder) { 27 messages = newMessageInfos; 28 folderInfo = newFolder; 29 } 30 31 32 38 public boolean flagIsSet(String flagName) throws MessagingException { 39 throw new MessagingException(Pooka.getProperty("error.MultiMessage.operationNotAllowed", "This operation is not allowed on multiple messages.")); 40 } 41 42 48 public Flags getFlags() throws MessagingException { 49 throw new MessagingException(Pooka.getProperty("error.MultiMessage.operationNotAllowed", "This operation is not allowed on multiple messages.")); 50 } 51 52 58 public Object getMessageProperty(String prop) throws MessagingException { 59 throw new MessagingException(Pooka.getProperty("error.MultiMessage.operationNotAllowed", "This operation is not allowed on multiple messages.")); 60 } 61 62 65 public void moveMessage(FolderInfo targetFolder, boolean expunge) throws MessagingException { 66 if (folderInfo != null) { 67 folderInfo.copyMessages(messages, targetFolder); 68 folderInfo.setFlags(messages, new Flags(Flags.Flag.DELETED), true); 69 if (expunge) 70 folderInfo.expunge(); 71 } else { 72 for (int i = 0; i < messages.length; i++) 73 messages[i].moveMessage(targetFolder, expunge); 74 } 75 } 76 77 80 public void copyMessage(FolderInfo targetFolder) throws MessagingException { 81 if (folderInfo != null) { 82 folderInfo.copyMessages(messages, targetFolder); 83 } else { 84 for (int i = 0; i < messages.length; i++) 85 messages[i].copyMessage(targetFolder); 86 } 87 } 88 89 92 public void deleteMessage(boolean expunge) throws MessagingException { 93 if (folderInfo != null) { 94 FolderInfo trashFolder = folderInfo.getTrashFolder(); 95 if ((folderInfo.useTrashFolder()) && (trashFolder != null) && (trashFolder != folderInfo)) { 96 try { 97 moveMessage(trashFolder, expunge); 98 } catch (MessagingException me) { 99 throw new NoTrashFolderException(Pooka.getProperty("error.Messsage.DeleteNoTrashFolder", "No trash folder available."), me); 100 } 101 } else { 102 remove(expunge); 103 } 104 } else { 105 for (int i = 0; i < messages.length; i++) 106 messages[i].deleteMessage(expunge); 107 108 } 109 } 110 111 121 public void remove(boolean autoExpunge) throws MessagingException { 122 if (folderInfo != null) { 123 folderInfo.setFlags(messages, new Flags(Flags.Flag.DELETED), true); 124 if (autoExpunge) 125 folderInfo.expunge(); 126 } else { 127 for (int i = 0; i < messages.length; i++) 128 messages[i].remove(autoExpunge); 129 } 130 131 } 132 133 136 public void runBackendFilters() { 137 net.suberic.util.swing.ProgressDialog pd = null; 138 139 try { 140 141 if (folderInfo != null) { 142 143 int filterCount = folderInfo.getBackendFilters() == null ? 1 : folderInfo.getBackendFilters().length; 144 145 pd = Pooka.getUIFactory().createProgressDialog(0, messages.length * filterCount, 0, Pooka.getProperty("message.filteringMessages", "Filtering Messages..."), Pooka.getProperty("message.filteringMessages", "Filtering Messages...")); 146 pd.show(); 147 148 java.util.List list = new LinkedList (); 149 for (int i = 0; i < messages.length; i++) { 150 list.add(messages[i].getMessageProxy()); 151 } 152 folderInfo.applyFilters(list, pd); 153 } else { 154 pd = Pooka.getUIFactory().createProgressDialog(0, messages.length, 0, Pooka.getProperty("message.filteringMessages", "Filtering Messages..."), Pooka.getProperty("message.filteringMessages", "Filtering Messages...")); 155 pd.show(); 156 157 for (int i = 0; i < messages.length; i++) { 158 java.util.LinkedList list = new java.util.LinkedList (); 159 list.add(messages[i]); 160 FolderInfo fi = messages[i].getFolderInfo(); 161 fi.applyFilters(list); 162 pd.setValue(messages.length - i -1); 163 } 164 } 165 } finally { 166 pd.dispose(); 167 } 168 } 169 170 173 public void runSpamAction() { 174 FilterAction spamFilter = null; 175 try { 176 spamFilter = MessageFilter.generateFilterAction("Pooka.spamAction"); 177 } catch (Exception e) { 178 int configureNow = Pooka.getUIFactory().showConfirmDialog("Spam action currently not configured. Would you like to configure it now?", "Configure Spam action", javax.swing.JOptionPane.YES_NO_OPTION); 179 if (configureNow == javax.swing.JOptionPane.YES_OPTION) { 180 Pooka.getUIFactory().showEditorWindow(Pooka.getProperty("Preferences.Spam.label", "Spam"), "Pooka.spamAction"); 182 } 183 184 } 185 if (spamFilter != null) { 186 List l = new LinkedList (); 187 for (int i = 0; i < messages.length; i++) { 188 l.add(messages[i].getMessageProxy()); 189 } 190 java.util.List removed = spamFilter.performFilter(l); 191 if (removed != null && removed.size() > 0) { 192 try { 193 getFolderInfo().expunge(); 194 } catch (MessagingException me) { 195 } 197 } 198 199 } 200 } 201 202 205 public void cacheMessage() throws MessagingException { 206 207 net.suberic.util.swing.ProgressDialog pd = Pooka.getUIFactory().createProgressDialog(0, messages.length, 0, Pooka.getProperty("message.cachingMessages", "Caching Messages..."), Pooka.getProperty("message.cachingMessages", "Caching Messages...")); 208 209 pd.show(); 210 try { 211 for (int i = messages.length - 1; i >= 0 && ! pd.isCancelled(); i--) { 212 FolderInfo fi = messages[i].getFolderInfo(); 213 if (fi != null && fi instanceof net.suberic.pooka.cache.CachingFolderInfo) { 214 ((net.suberic.pooka.cache.CachingFolderInfo) fi).cacheMessage(messages[i], net.suberic.pooka.cache.MessageCache.MESSAGE); 215 216 } 217 pd.setValue(messages.length - i -1); 218 } 219 } finally { 220 pd.dispose(); 221 } 222 223 } 224 225 228 public MessageInfo getMessageInfo(int index) { 229 return messages[index]; 230 } 231 232 235 public int getMessageCount() { 236 return messages.length; 237 } 238 239 } 240 241 242 243 | Popular Tags |