Show
Ignore:
Timestamp:
08/03/08 02:00:51 PM (5 months ago)
Author:
octorian
Message:

More UID FETCH code

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapClient.java

    r262 r264  
    9191    private FolderTreeItem activeMailbox = null; 
    9292 
     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     
    93107    public ImapClient(GlobalConfig globalConfig, ImapConfig accountConfig) { 
    94108        this.accountConfig = accountConfig; 
     
    361375        this.activeMailbox = mailbox; 
    362376        activeMailbox.setMsgCount(response.exists); 
     377        knownMailboxes.put(activeMailbox, response); 
    363378         
    364379        // ideally, this should parse out the message counts 
     
    375390                imapProtocol.executeFetchEnvelope(firstIndex, lastIndex); 
    376391         
     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) { 
    377424        FolderMessage[] folderMessages = new FolderMessage[response.length]; 
    378425        for(int i=0;i<response.length;i++) { 
     
    386433            folderMessages[i].setJunk(response[i].flags.junk); 
    387434        } 
    388          
    389         return folderMessages; 
    390     } 
    391  
     435        return folderMessages; 
     436    } 
     437     
    392438    public Message getMessage(FolderMessage folderMessage) throws IOException, MailException { 
    393439        ImapParser.MessageSection structure = getMessageStructure(folderMessage.getUid());