Changeset 582
- Timestamp:
- 12/30/09 14:51:50 (2 years ago)
- Location:
- trunk/LogicMail/src/org/logicprobe/LogicMail
- Files:
-
- 12 edited
-
mail/AbstractMailStore.java (modified) (2 diffs)
-
mail/IncomingMailClient.java (modified) (2 diffs)
-
mail/IncomingMailConnectionHandler.java (modified) (5 diffs)
-
mail/LocalMailStore.java (modified) (1 diff)
-
mail/MaildirFolder.java (modified) (1 diff)
-
mail/NetworkMailStore.java (modified) (3 diffs)
-
mail/imap/ImapClient.java (modified) (2 diffs)
-
mail/imap/ImapProtocol.java (modified) (1 diff)
-
mail/pop/PopClient.java (modified) (2 diffs)
-
model/AccountNode.java (modified) (1 diff)
-
model/MailboxNode.java (modified) (1 diff)
-
ui/MailboxScreen.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/AbstractMailStore.java
r529 r582 120 120 121 121 /** 122 * Returns whether the mail store supports expunging of deleted messages. 123 * 124 * @return True if expunge supported, false otherwise 125 */ 126 public abstract boolean hasExpunge(); 127 128 /** 122 129 * Requests the regeneration of the mail folder tree. 123 130 * … … 129 136 */ 130 137 public abstract void requestFolderTree(); 138 139 /** 140 * Requests that a folder be expunged of deleted messages. 141 * 142 * <p>Successful completion is indicated by a call to 143 * {@link FolderListener#folderStatusChanged(FolderEvent)}. 144 * 145 * @param folder The folder to expunge 146 */ 147 public abstract void requestFolderExpunge(FolderTreeItem folder); 131 148 132 149 /** -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/IncomingMailClient.java
r562 r582 92 92 93 93 /** 94 * Return whether the underlying protocol supports expunging of deleted messages. 95 * 96 * @return True if expunge supported, false otherwise 97 */ 98 boolean hasExpunge(); 99 100 /** 94 101 * Return whether the underlying protocol supports an idle connection mode. 95 102 * … … 183 190 */ 184 191 void setActiveFolder(MessageToken messageToken) 192 throws IOException, MailException; 193 194 /** 195 * Expunges deleted messages from the currently active mail folder. 196 * This should do nothing if the underlying protocol does not support expunge. 197 * 198 * @throws IOException on I/O errors 199 * @throws MailException on protocol errors 200 */ 201 void expungeActiveFolder() 185 202 throws IOException, MailException; 186 203 -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/IncomingMailConnectionHandler.java
r564 r582 49 49 // "requestXXXX()" methods from AbstractMailStore 50 50 public static final int REQUEST_FOLDER_TREE = 10; 51 public static final int REQUEST_FOLDER_STATUS = 11; 52 public static final int REQUEST_FOLDER_MESSAGES_RANGE = 12; 53 public static final int REQUEST_FOLDER_MESSAGES_SET = 13; 54 public static final int REQUEST_FOLDER_MESSAGES_RECENT = 14; 51 public static final int REQUEST_FOLDER_EXPUNGE = 11; 52 public static final int REQUEST_FOLDER_STATUS = 12; 53 public static final int REQUEST_FOLDER_MESSAGES_RANGE = 13; 54 public static final int REQUEST_FOLDER_MESSAGES_SET = 14; 55 public static final int REQUEST_FOLDER_MESSAGES_RECENT = 15; 55 56 public static final int REQUEST_MESSAGE = 20; 56 57 public static final int REQUEST_MESSAGE_PARTS = 21; … … 91 92 handleRequestFolderTree(); 92 93 break; 94 case REQUEST_FOLDER_EXPUNGE: 95 handleRequestFolderExpunge((FolderTreeItem)params[0]); 96 break; 93 97 case REQUEST_FOLDER_STATUS: 94 98 handleRequestFolderStatus((FolderTreeItem[])params[0]); … … 132 136 } 133 137 134 /**138 /** 135 139 * Handles the start of the IDLE state. 136 140 */ … … 211 215 } 212 216 } 213 217 218 private void handleRequestFolderExpunge(FolderTreeItem folder) throws IOException, MailException { 219 String message = resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_EXPUNGE); 220 showStatus(message); 221 checkActiveFolder(folder); 222 incomingClient.expungeActiveFolder(); 223 224 MailConnectionHandlerListener listener = getListener(); 225 if(listener != null) { 226 listener.mailConnectionRequestComplete(REQUEST_FOLDER_EXPUNGE, folder); 227 } 228 } 229 214 230 private void handleRequestFolderStatus(FolderTreeItem[] folders) throws IOException, MailException { 215 231 String message = resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_STATUS); … … 243 259 this.param = param; 244 260 this.count = 0; 245 246 261 } 247 262 -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/LocalMailStore.java
r581 r582 115 115 } 116 116 117 public boolean hasExpunge() { 118 return true; 119 } 120 117 121 public void requestFolderTree() { 118 122 fireFolderTreeUpdated(rootFolder); 119 123 } 120 124 125 public void requestFolderExpunge(FolderTreeItem folder) { 126 // TODO: Implement local expunge 127 FolderTreeItem requestFolder = getMatchingFolderTreeItem(folder.getPath()); 128 129 if(requestFolder != null) { 130 threadQueue.invokeLater(new ExpungeFolderRunnable(requestFolder)); 131 } 132 } 133 134 private class ExpungeFolderRunnable extends MaildirRunnable { 135 public ExpungeFolderRunnable(FolderTreeItem requestFolder) { 136 super(requestFolder); 137 } 138 139 public void run() { 140 FolderMessage[] folderMessages = null; 141 try { 142 maildirFolder.open(); 143 maildirFolder.expunge(); 144 maildirFolder.close(); 145 } catch (IOException e) { 146 System.err.println("Unable to expunge folder: " + e.toString()); 147 } 148 149 if(folderMessages != null) { 150 fireFolderStatusChanged(requestFolder); 151 } 152 } 153 } 154 121 155 public void requestFolderStatus(FolderTreeItem[] folders) { 122 156 // Make every entry in the provided array match the local folder -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/MaildirFolder.java
r581 r582 480 480 if(mailFileConnection.exists() && !mailFileConnection.isDirectory() && mailFileConnection.canRead()) { 481 481 mailFileConnection.rename(updatedFilename); 482 mailFileConnection.close(); 482 483 return true; 483 484 } 484 485 else { 486 mailFileConnection.close(); 485 487 return false; 488 } 489 } 490 491 /** 492 * Remove all deleted messages from this folder. 493 */ 494 public void expunge() throws IOException { 495 if (EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 496 EventLogger.logEvent(AppInfo.GUID, 497 ("expunge()").getBytes(), 498 EventLogger.DEBUG_INFO); 499 } 500 501 // Build a list of deleted files in the current directory 502 Vector deletedFiles = new Vector(); 503 Enumeration e = fileConnection.list(); 504 while(e.hasMoreElements()) { 505 String messageFilename = (String)e.nextElement(); 506 int p = messageFilename.indexOf('_'); 507 if(p != -1 && messageFilename.indexOf('T', p) != -1) { 508 deletedFiles.addElement(messageFilename); 509 } 510 } 511 512 // Iterate through the list and actually delete from storage 513 String baseUrl = fileConnection.getURL() + '/'; 514 e = deletedFiles.elements(); 515 while(e.hasMoreElements()) { 516 String messageFilename = (String)e.nextElement(); 517 try { 518 FileConnection mailFileConnection = 519 (FileConnection)Connector.open(baseUrl + messageFilename); 520 if(mailFileConnection.exists() && !mailFileConnection.isDirectory() && mailFileConnection.canRead()) { 521 mailFileConnection.delete(); 522 } 523 mailFileConnection.close(); 524 } catch (IOException exp) { 525 if (EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 526 EventLogger.logEvent(AppInfo.GUID, 527 ("Error deleting message: " + exp.toString()).getBytes(), 528 EventLogger.DEBUG_INFO); 529 } 530 } 486 531 } 487 532 } -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/NetworkMailStore.java
r529 r582 110 110 } 111 111 112 public boolean hasExpunge() { 113 return client.hasExpunge(); 114 } 115 112 116 public boolean isConnected() { 113 117 return client.isConnected(); … … 118 122 } 119 123 124 public void requestFolderExpunge(FolderTreeItem folder) { 125 connectionHandler.addRequest(IncomingMailConnectionHandler.REQUEST_FOLDER_EXPUNGE, new Object[] { folder }); 126 } 127 120 128 public void requestFolderStatus(FolderTreeItem[] folders) { 121 129 connectionHandler.addRequest(IncomingMailConnectionHandler.REQUEST_FOLDER_STATUS, new Object[] { folders }); … … 186 194 fireFolderTreeUpdated((FolderTreeItem)result); 187 195 break; 196 case IncomingMailConnectionHandler.REQUEST_FOLDER_EXPUNGE: 197 fireFolderStatusChanged((FolderTreeItem)result); 198 break; 188 199 case IncomingMailConnectionHandler.REQUEST_FOLDER_STATUS: 189 200 FolderTreeItem[] folders = (FolderTreeItem[])result; -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapClient.java
r580 r582 331 331 332 332 /* (non-Javadoc) 333 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#hasExpunge() 334 */ 335 public boolean hasExpunge() { 336 return true; 337 } 338 339 /* (non-Javadoc) 333 340 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#hasAppend() 334 341 */ … … 584 591 585 592 /* (non-Javadoc) 593 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#expungeActiveFolder() 594 */ 595 public void expungeActiveFolder() throws IOException, MailException { 596 imapProtocol.executeExpunge(); 597 } 598 599 /* (non-Javadoc) 586 600 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getFolderMessages(int, int, org.logicprobe.LogicMail.mail.FolderMessageCallback, org.logicprobe.LogicMail.mail.MailProgressHandler) 587 601 */ -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapProtocol.java
r562 r582 367 367 } 368 368 369 public void executeExpunge() throws IOException, MailException { 370 if (EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 371 EventLogger.logEvent(AppInfo.GUID, 372 ("ImapProtocol.executeExpunge()").getBytes(), 373 EventLogger.DEBUG_INFO); 374 } 375 376 execute("EXPUNGE", null, null); 377 } 378 369 379 public StatusResponse[] executeStatus(String[] mboxpaths, MailProgressHandler progressHandler) 370 380 throws IOException, MailException { -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/pop/PopClient.java
r564 r582 266 266 267 267 /* (non-Javadoc) 268 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#hasExpunge() 269 */ 270 public boolean hasExpunge() { 271 return false; 272 } 273 274 /* (non-Javadoc) 268 275 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#hasAppend() 269 276 */ … … 334 341 // Mailbox cannot be changed, so we just pull the message counts 335 342 activeMailbox.setMsgCount(popProtocol.executeStat()); 343 } 344 345 /* (non-Javadoc) 346 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#expungeActiveFolder() 347 */ 348 public void expungeActiveFolder() throws IOException, MailException { 349 // Expunge is not supported, so we do nothing here. 336 350 } 337 351 -
trunk/LogicMail/src/org/logicprobe/LogicMail/model/AccountNode.java
r574 r582 346 346 347 347 /** 348 * Gets whether this account supports expunging deleted messages. 349 * 350 * @return True if supported, false otherwise. 351 */ 352 public boolean hasExpunge() { 353 return this.mailStore.hasExpunge(); 354 } 355 356 /** 348 357 * Called to trigger a refresh of the mailboxes under 349 358 * this account. Completion is signaled by an -
trunk/LogicMail/src/org/logicprobe/LogicMail/model/MailboxNode.java
r574 r582 690 690 691 691 /** 692 * Check if this mailbox has messages marked as deleted. 693 * This is the recommended way to check for deleted messages, 694 * since the UI may not always track such messages. 695 * 696 * @return True if deleted messages exist 697 */ 698 public boolean hasDeletedMessages() { 699 boolean hasDeleted = false; 700 synchronized(messages) { 701 int size = messages.size(); 702 for(int i=0; i<size; i++) { 703 int flags = ((MessageNode)messages.elementAt(i)).getFlags(); 704 if((flags & MessageNode.Flag.DELETED) != 0) { 705 hasDeleted = true; 706 break; 707 } 708 } 709 } 710 return hasDeleted; 711 } 712 713 /** 714 * Tells the underlying mail store to expunge any deleted messages 715 * from the mailbox, if possible. 716 */ 717 public void expungeDeletedMessages() { 718 parentAccount.getMailStore().requestFolderExpunge(this.folderTreeItem); 719 } 720 721 /** 692 722 * Update the unseen message count from the local messages collection. 693 723 * -
trunk/LogicMail/src/org/logicprobe/LogicMail/ui/MailboxScreen.java
r551 r582 41 41 import net.rim.device.api.ui.MenuItem; 42 42 import net.rim.device.api.ui.Screen; 43 import net.rim.device.api.ui.component.Dialog; 43 44 import net.rim.device.api.ui.component.Menu; 44 45 import net.rim.device.api.ui.container.VerticalFieldManager; … … 294 295 } 295 296 297 298 public boolean onClose() { 299 // Check for deleted messages in the mailbox 300 if(mailboxNode.getParentAccount().hasExpunge() 301 && mailboxNode.hasDeletedMessages()) { 302 // Prompt for expunge if possible and supported 303 int choice = Dialog.ask( 304 Dialog.D_YES_NO, 305 resources.getString(LogicMailResource.MAILBOX_EXPUNGE_PROMPT), 306 Dialog.YES); 307 308 // Request expunge if desired 309 if(choice == Dialog.YES) { 310 mailboxNode.expungeDeletedMessages(); 311 } 312 } 313 314 // Close the screen 315 screen.close(); 316 return true; 317 } 318 296 319 /** 297 320 * Handles mailbox status change events.
Note: See TracChangeset
for help on using the changeset viewer.
