Changeset 264
- Timestamp:
- 08/03/08 02:00:51 PM (4 months ago)
- Location:
- trunk/LogicMail/src/org/logicprobe/LogicMail
- Files:
-
- 8 modified
-
mail/AbstractMailStore.java (modified) (1 diff)
-
mail/imap/ImapClient.java (modified) (4 diffs)
-
mail/imap/ImapProtocol.java (modified) (4 diffs)
-
mail/IncomingMailClient.java (modified) (1 diff)
-
mail/IncomingMailConnectionHandler.java (modified) (2 diffs)
-
mail/NetworkMailStore.java (modified) (1 diff)
-
mail/pop/PopClient.java (modified) (1 diff)
-
model/MailboxNode.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/AbstractMailStore.java
r259 r264 151 151 * 152 152 * @param folder The folder to request a message listing for. 153 * @param count The maximum number of messages to get headers for. 154 */ 155 public abstract void requestFolderMessagesRecent(FolderTreeItem folder, int count); 153 */ 154 public abstract void requestFolderMessagesRecent(FolderTreeItem folder); 156 155 157 156 /** -
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()); -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapProtocol.java
r262 r264 477 477 Integer.toString(lastIndex) + 478 478 " (FLAGS UID ENVELOPE)"); 479 480 FetchEnvelopeResponse[] envResponses = new FetchEnvelopeResponse[(lastIndex - firstIndex)+1]; 481 482 // Pre-process the returned text to clean up mid-field line breaks 479 return prepareFetchEnvelopeResponse(rawList); 480 } 481 482 /** 483 * Execute the "UID FETCH (FLAGS UID ENVELOPE)" command 484 * @param uidNext Unique ID of the next message 485 * @return Array of FetchEnvelopeResponse objects 486 */ 487 public FetchEnvelopeResponse[] executeFetchEnvelopeUid(int uidNext) throws IOException, MailException { 488 if(EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 489 EventLogger.logEvent( 490 AppInfo.GUID, 491 ("ImapProtocol.executeFetchEnvelopeUid("+uidNext+")").getBytes(), 492 EventLogger.DEBUG_INFO); 493 } 494 495 String[] rawList = execute("UID FETCH", 496 Integer.toString(uidNext) + ":*" + 497 " (FLAGS UID ENVELOPE)"); 498 499 return prepareFetchEnvelopeResponse(rawList); 500 } 501 502 private FetchEnvelopeResponse[] prepareFetchEnvelopeResponse(String[] rawList) throws IOException, MailException { 503 // Preprocess the returned text to clean up mid-field line breaks 483 504 // This should all become unnecessary once execute() 484 505 // becomes more intelligent in how it handles replies … … 500 521 } 501 522 502 int index = 0;523 Vector envResponses = new Vector(); 503 524 int size = rawList2.size(); 504 525 for(int i=0;i<size;i++) { … … 558 579 envRespItem.index = midx; 559 580 envRespItem.envelope = env; 560 envResponses [index++] = envRespItem;581 envResponses.addElement(envRespItem); 561 582 } catch (Exception exp) { 562 583 System.err.println("Parse error: " + exp); … … 564 585 } 565 586 566 return envResponses; 567 } 568 587 FetchEnvelopeResponse[] result = new FetchEnvelopeResponse[envResponses.size()]; 588 envResponses.copyInto(result); 589 return result; 590 } 591 569 592 /** 570 593 * Execute the "FETCH (BODYSTRUCTURE)" command -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/IncomingMailClient.java
r259 r264 129 129 130 130 /** 131 * Get a list of new messages in the selected folder. 132 * On the first invocation, it will return the most recent messages 133 * up to the limit configured in the global configuration. 134 * On subsequent invocations, if the underlying protocol supports it, 135 * this method should return all new messages that have entered the 136 * mailbox since. Otherwise, it will behave the same as it 137 * did on the first invocation. 138 * 139 * @return List of message envelopes 140 * @throw IOException on I/O errors 141 * @throw MailException on protocol errors 142 */ 143 public abstract FolderMessage[] getNewFolderMessages() throws IOException, MailException; 144 145 /** 131 146 * Get a particular message from the selected folder. 132 147 * The details of message retrieval should be constrained by -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/IncomingMailConnectionHandler.java
r259 r264 90 90 case REQUEST_FOLDER_MESSAGES_RECENT: 91 91 handleRequestFolderMessagesRecent( 92 (FolderTreeItem)params[0], 93 ((Integer)params[1]).intValue()); 92 (FolderTreeItem)params[0]); 94 93 break; 95 94 case REQUEST_MESSAGE: … … 158 157 } 159 158 160 private void handleRequestFolderMessagesRecent(FolderTreeItem folder, int count) throws IOException, MailException { 161 checkActiveFolder(folder); 162 int msgCount = incomingClient.getActiveFolder().getMsgCount(); 163 int firstIndex = Math.max(1, msgCount - count); 159 private void handleRequestFolderMessagesRecent(FolderTreeItem folder) throws IOException, MailException { 160 checkActiveFolder(folder); 164 161 165 FolderMessage[] messages = incomingClient.get FolderMessages(firstIndex, msgCount);162 FolderMessage[] messages = incomingClient.getNewFolderMessages(); 166 163 167 164 MailConnectionHandlerListener listener = getListener(); -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/NetworkMailStore.java
r259 r264 123 123 } 124 124 125 public void requestFolderMessagesRecent(FolderTreeItem folder , int count) {125 public void requestFolderMessagesRecent(FolderTreeItem folder) { 126 126 connectionHandler.addRequest( 127 127 IncomingMailConnectionHandler.REQUEST_FOLDER_MESSAGES_RECENT, 128 new Object[] { folder , new Integer(count)});128 new Object[] { folder }); 129 129 } 130 130 -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/pop/PopClient.java
r262 r264 246 246 } 247 247 248 public FolderMessage[] getNewFolderMessages() throws IOException, MailException { 249 int count = MailSettings.getInstance().getGlobalConfig().getRetMsgCount(); 250 int msgCount = activeMailbox.getMsgCount(); 251 int firstIndex = Math.max(1, msgCount - count); 252 return getFolderMessages(firstIndex, activeMailbox.getMsgCount()); 253 } 254 248 255 public Message getMessage(FolderMessage folderMessage) throws IOException, MailException { 249 256 // Figure out the max number of lines -
trunk/LogicMail/src/org/logicprobe/LogicMail/model/MailboxNode.java
r259 r264 37 37 import java.util.Vector; 38 38 39 import org.logicprobe.LogicMail.conf.MailSettings;40 39 import org.logicprobe.LogicMail.mail.FolderTreeItem; 41 40 import org.logicprobe.LogicMail.util.EventListenerList; … … 434 433 */ 435 434 public void refreshMessages() { 436 parentAccount.getMailStore().requestFolderMessagesRecent( 437 this.folderTreeItem, 438 MailSettings.getInstance().getGlobalConfig().getRetMsgCount()); 435 parentAccount.getMailStore().requestFolderMessagesRecent(this.folderTreeItem); 439 436 } 440 437
