- Timestamp:
- 08/03/08 02:00:51 PM (5 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapClient.java
r262 r264 91 91 private FolderTreeItem activeMailbox = null; 92 92 93 /** 94 * Seen mailboxes, used to track whether fetching new 95 * messages should be based on a limited range, or 96 * the UIDNEXT parameter. 97 */ 98 private Hashtable seenMailboxes = new Hashtable(); 99 100 /** 101 * Known mailboxes, used to track protocol-specific 102 * information on mailboxes that is not exposed 103 * to other classes. 104 */ 105 private Hashtable knownMailboxes = new Hashtable(); 106 93 107 public ImapClient(GlobalConfig globalConfig, ImapConfig accountConfig) { 94 108 this.accountConfig = accountConfig; … … 361 375 this.activeMailbox = mailbox; 362 376 activeMailbox.setMsgCount(response.exists); 377 knownMailboxes.put(activeMailbox, response); 363 378 364 379 // ideally, this should parse out the message counts … … 375 390 imapProtocol.executeFetchEnvelope(firstIndex, lastIndex); 376 391 392 return prepareFolderMessages(response); 393 } 394 395 public FolderMessage[] getNewFolderMessages() throws IOException, MailException { 396 // Sanity check 397 if(activeMailbox == null) { 398 throw new MailException("Mailbox not selected"); 399 } 400 401 FolderMessage[] result; 402 if(!seenMailboxes.containsKey(activeMailbox)) { 403 int count = MailSettings.getInstance().getGlobalConfig().getRetMsgCount(); 404 int msgCount = activeMailbox.getMsgCount(); 405 int firstIndex = Math.max(1, msgCount - count); 406 result = getFolderMessages(firstIndex, activeMailbox.getMsgCount()); 407 seenMailboxes.put(activeMailbox, new Object()); 408 } 409 else { 410 int uidNext = ((ImapProtocol.SelectResponse)knownMailboxes.get(activeMailbox)).uidNext; 411 ImapProtocol.FetchEnvelopeResponse[] response = 412 imapProtocol.executeFetchEnvelopeUid(uidNext); 413 result = prepareFolderMessages(response); 414 415 if(result.length > 0) { 416 uidNext = result[result.length-1].getUid() + 1; 417 ((ImapProtocol.SelectResponse)knownMailboxes.get(activeMailbox)).uidNext = uidNext; 418 } 419 } 420 return result; 421 } 422 423 private FolderMessage[] prepareFolderMessages(ImapProtocol.FetchEnvelopeResponse[] response) { 377 424 FolderMessage[] folderMessages = new FolderMessage[response.length]; 378 425 for(int i=0;i<response.length;i++) { … … 386 433 folderMessages[i].setJunk(response[i].flags.junk); 387 434 } 388 389 return folderMessages; 390 } 391 435 return folderMessages; 436 } 437 392 438 public Message getMessage(FolderMessage folderMessage) throws IOException, MailException { 393 439 ImapParser.MessageSection structure = getMessageStructure(folderMessage.getUid());
