Changeset 471


Ignore:
Timestamp:
07/27/09 16:53:20 (3 years ago)
Author:
octorian
Message:

Granular progress indication of time consuming network operations

Location:
trunk
Files:
1 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LogicMail/LogicMail.jdp

    r469 r471  
    108108src\org\logicprobe\LogicMail\mail\MailException.java 
    109109src\org\logicprobe\LogicMail\mail\MailFactory.java 
     110src\org\logicprobe\LogicMail\mail\MailProgressHandler.java 
    110111src\org\logicprobe\LogicMail\mail\MailSenderEvent.java 
    111112src\org\logicprobe\LogicMail\mail\MailSenderListener.java 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/LogicMail.rrc

    r470 r471  
    7070MAILCONNECTION_CLOSING_CONNECTION#0="Closing connection..."; 
    7171MAILCONNECTION_OPENING_CONNECTION#0="Opening connection..."; 
    72 MAILCONNECTION_REQUEST_FOLDER_MESSAGES#0="Getting folder messages..."; 
     72MAILCONNECTION_REQUEST_FOLDER_MESSAGES#0="Getting folder messages"; 
    7373MAILCONNECTION_REQUEST_FOLDER_STATUS#0="Refreshing folder status..."; 
    7474MAILCONNECTION_REQUEST_FOLDER_TREE#0="Getting folder tree..."; 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/mail/AbstractMailConnectionHandler.java

    r470 r471  
    4040import org.logicprobe.LogicMail.LogicMailResource; 
    4141import org.logicprobe.LogicMail.util.Queue; 
     42import org.logicprobe.LogicMail.util.StringParser; 
    4243 
    4344/** 
     
    417418        protected void showStatus(String message, int progress) { 
    418419                MailConnectionManager.getInstance().fireMailConnectionStatus(client.getConnectionConfig(), message, progress); 
     420        } 
     421         
     422        /** 
     423         * Gets a progress handler for a request with the provided status message. 
     424         * <p> 
     425         * This default progress handler displays the message along with the 
     426         * amount of data downloaded for network updates, and percentage complete 
     427         * for processing updates. 
     428         * </p> 
     429         *  
     430         * @param message The status message for the request 
     431         * @return The progress handler 
     432         */ 
     433        protected MailProgressHandler getProgressHandler(String message) { 
     434                return new MailConnectionProgressHandler(message); 
    419435        } 
    420436         
     
    613629        } 
    614630        } 
     631         
     632        /** 
     633         * Standard progress handler to be used for mail connection handlers. 
     634         * This takes the operation's message and appends a relevant status 
     635         * indicator to it. 
     636         */ 
     637        private class MailConnectionProgressHandler implements MailProgressHandler { 
     638                private int total = 0; 
     639                private int lastTotal = 0; 
     640                private int threshold = 128; 
     641                private String messageStart; 
     642                private String networkMessageEnd = ")..."; 
     643                private String processingMessageEnd = "%)..."; 
     644                 
     645                public MailConnectionProgressHandler(String message) { 
     646                        this.messageStart = message + " ("; 
     647                } 
     648                 
     649                public void mailProgress(int type, int count, int max) { 
     650                        if(type == MailProgressHandler.TYPE_NETWORK) { 
     651                                total += count; 
     652                                if((total - lastTotal) >= threshold) { 
     653                                        showStatus(messageStart + StringParser.toDataSizeString(total) + networkMessageEnd); 
     654                                        lastTotal = total; 
     655                                        if(threshold < 1024 && total >= 1024) { threshold = 1024; } 
     656                                } 
     657                        } 
     658                        else if(type == MailProgressHandler.TYPE_PROCESSING && max > 0){ 
     659                                if(count > 0) { count = count / max; } 
     660                                showStatus(messageStart + count + processingMessageEnd); 
     661                        } 
     662                } 
     663        }; 
    615664} 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/mail/IncomingMailClient.java

    r407 r471  
    4141 * Provides a generic interface to different incoming mail protocols. 
    4242 * This class allows most of the UI code to be protocol-agnostic. 
    43  * 
     43 * <p> 
    4444 * Since a number of features may not be supported by all protocols, 
    45  * a variety of hasXXXX() methods are provided by this interface to 
     45 * a variety of <tt>hasXXXX()</tt> methods are provided by this interface to 
    4646 * determine whether those features exist. 
     47 * </p> 
     48 * <p> 
     49 * Methods that involve a noticeable amount of network traffic and/or 
     50 * parsing overhead take an instance of {@link MailProgressHandler} as 
     51 * a parameter.  This allows more granular progress monitoring than would 
     52 * otherwise be available. 
     53 * </p> 
    4754 */ 
    4855public interface IncomingMailClient extends MailClient { 
     
    8390     * reference an invisible root node.  Otherwise, this should 
    8491     * reference the visible root folder. 
    85      * 
     92     *  
     93     * @param progressHandler the progress handler 
     94     *  
    8695     * @return Root folder of the tree, and all children below it 
    87      * @throws IOException on I/O errors 
    88      * @throws MailException on protocol errors 
    89      */ 
    90     public abstract FolderTreeItem getFolderTree() 
     96     *  
     97     * @throws IOException on I/O errors 
     98     * @throws MailException on protocol errors 
     99     */ 
     100    public abstract FolderTreeItem getFolderTree(MailProgressHandler progressHandler) 
    91101        throws IOException, MailException; 
    92102     
    93103    /** 
    94104     * Refresh the folder status. 
    95      * 
     105     *  
    96106     * @param folders The folders to refresh 
    97      * @throws IOException on I/O errors 
    98      * @throws MailException on protocol errors 
    99      */ 
    100     public abstract void refreshFolderStatus(FolderTreeItem[] folders) 
     107     * @param progressHandler the progress handler 
     108     *  
     109     * @throws IOException on I/O errors 
     110     * @throws MailException on protocol errors 
     111     */ 
     112    public abstract void refreshFolderStatus(FolderTreeItem[] folders, MailProgressHandler progressHandler) 
    101113        throws IOException, MailException; 
    102114     
     
    150162    /** 
    151163     * Get a list of the messages in the selected folder. 
    152      * 
     164     *  
    153165     * @param firstIndex Index of the first message 
    154166     * @param lastIndex Index of the last message 
     167     * @param progressHandler the progress handler 
     168     *  
    155169     * @return List of message envelopes 
    156      * @throws IOException on I/O errors 
    157      * @throws MailException on protocol errors 
    158      */ 
    159     public abstract FolderMessage[] getFolderMessages(int firstIndex, int lastIndex) 
     170     *  
     171     * @throws IOException on I/O errors 
     172     * @throws MailException on protocol errors 
     173     */ 
     174    public abstract FolderMessage[] getFolderMessages(int firstIndex, int lastIndex, MailProgressHandler progressHandler) 
    160175        throws IOException, MailException; 
    161176     
     
    169184     * did on the first invocation. 
    170185     *  
     186     * @param progressHandler the progress handler 
     187     *  
    171188     * @return List of message envelopes 
    172      * @throws IOException on I/O errors 
    173      * @throws MailException on protocol errors 
    174      */ 
    175     public abstract FolderMessage[] getNewFolderMessages() throws IOException, MailException; 
     189     *  
     190     * @throws IOException on I/O errors 
     191     * @throws MailException on protocol errors 
     192     */ 
     193    public abstract FolderMessage[] getNewFolderMessages(MailProgressHandler progressHandler) throws IOException, MailException; 
    176194     
    177195    /** 
     
    180198     * protocol-specific capabilities, application-wide data 
    181199     * format capabilities, and user configuration options. 
    182      * 
    183      * @throws IOException on I/O errors 
    184      * @throws MailException on protocol errors 
    185      */ 
    186     public abstract Message getMessage(MessageToken messageToken) throws IOException, MailException; 
     200     *  
     201     * @param messageToken the message token 
     202     * @param progressHandler the progress handler 
     203     *  
     204     * @return the message 
     205     *  
     206     * @throws IOException on I/O errors 
     207     * @throws MailException on protocol errors 
     208     */ 
     209    public abstract Message getMessage(MessageToken messageToken, MailProgressHandler progressHandler) throws IOException, MailException; 
    187210     
    188211    /** 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/mail/IncomingMailConnectionHandler.java

    r470 r471  
    201201 
    202202        private void handleRequestFolderTree() throws IOException, MailException { 
    203                 showStatus(resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_TREE)); 
    204                 FolderTreeItem root = incomingClient.getFolderTree(); 
     203                String message = resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_TREE); 
     204                showStatus(message); 
     205                FolderTreeItem root = incomingClient.getFolderTree(getProgressHandler(message)); 
    205206 
    206207                MailConnectionHandlerListener listener = getListener(); 
     
    211212         
    212213        private void handleRequestFolderStatus(FolderTreeItem[] folders) throws IOException, MailException { 
    213                 showStatus(resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_STATUS)); 
    214                 incomingClient.refreshFolderStatus(folders); 
     214                String message = resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_STATUS); 
     215                showStatus(message); 
     216                incomingClient.refreshFolderStatus(folders, getProgressHandler(message)); 
    215217                 
    216218                MailConnectionHandlerListener listener = getListener(); 
     
    221223         
    222224        private void handleRequestFolderMessagesRange(FolderTreeItem folder, int firstIndex, int lastIndex) throws IOException, MailException { 
    223                 showStatus(resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_MESSAGES)); 
     225                String message = resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_MESSAGES); 
     226                showStatus(message + "..."); 
    224227                checkActiveFolder(folder); 
    225228                 
    226                 FolderMessage[] messages = incomingClient.getFolderMessages(firstIndex, lastIndex); 
     229                FolderMessage[] messages = incomingClient.getFolderMessages(firstIndex, lastIndex, getProgressHandler(message)); 
    227230                 
    228231                MailConnectionHandlerListener listener = getListener(); 
     
    245248         
    246249        private void handleRequestFolderMessagesRecent(FolderTreeItem folder) throws IOException, MailException { 
    247                 showStatus(resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_MESSAGES)); 
     250                String message = resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_MESSAGES); 
     251                showStatus(message + "..."); 
    248252                checkActiveFolder(folder); 
    249253         
    250                 FolderMessage[] messages = incomingClient.getNewFolderMessages(); 
     254                FolderMessage[] messages = incomingClient.getNewFolderMessages(getProgressHandler(message)); 
    251255                 
    252256                MailConnectionHandlerListener listener = getListener(); 
     
    257261         
    258262        private void handleRequestMessage(MessageToken messageToken) throws IOException, MailException { 
    259                 showStatus(resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_MESSAGE)); 
     263                String statusMessage = resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_MESSAGE); 
     264                showStatus(statusMessage); 
    260265                checkActiveFolder(messageToken); 
    261266                 
    262                 Message message = incomingClient.getMessage(messageToken); 
     267                Message message = incomingClient.getMessage(messageToken, getProgressHandler(statusMessage)); 
    263268                 
    264269                MailConnectionHandlerListener listener = getListener(); 
     
    269274 
    270275        private void handleRequestMessageParts(MessageToken messageToken, MimeMessagePart[] messageParts) throws IOException, MailException { 
    271                 showStatus(resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_MESSAGE)); 
     276                String statusMessage = resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_MESSAGE); 
     277                showStatus(statusMessage); 
    272278                checkActiveFolder(messageToken); 
    273279 
     
    279285                        for(int i=0; i<messageParts.length; i++) { 
    280286                                MimeMessageContent content = 
    281                                         ((org.logicprobe.LogicMail.mail.imap.ImapClient)incomingClient).getMessagePart(messageToken, messageParts[i]); 
     287                                        ((org.logicprobe.LogicMail.mail.imap.ImapClient)incomingClient).getMessagePart(messageToken, messageParts[i], getProgressHandler(statusMessage)); 
    282288                                if(content != null) { 
    283289                                        messageContentVector.addElement(content); 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapClient.java

    r467 r471  
    4646import org.logicprobe.LogicMail.mail.IncomingMailClient; 
    4747import org.logicprobe.LogicMail.mail.MailException; 
     48import org.logicprobe.LogicMail.mail.MailProgressHandler; 
    4849import org.logicprobe.LogicMail.mail.MessageToken; 
    4950import org.logicprobe.LogicMail.message.FolderMessage; 
     
    168169    } 
    169170     
     171    /* (non-Javadoc) 
     172     * @see org.logicprobe.LogicMail.mail.MailClient#open() 
     173     */ 
    170174    public boolean open() throws IOException, MailException { 
    171175        try { 
     
    204208            if(nsPersonal == null) { 
    205209                // Discover folder delimiter 
    206                 Vector resp = imapProtocol.executeList("", ""); 
     210                Vector resp = imapProtocol.executeList("", "", null); 
    207211                if(resp.size() > 0) { 
    208212                    folderDelim = ((ImapProtocol.ListResponse)resp.elementAt(0)).delim; 
     
    222226    } 
    223227     
     228    /* (non-Javadoc) 
     229     * @see org.logicprobe.LogicMail.mail.MailClient#close() 
     230     */ 
    224231    public void close() throws IOException, MailException { 
    225232        if(connection.isConnected()) { 
     
    247254    } 
    248255 
     256    /* (non-Javadoc) 
     257     * @see org.logicprobe.LogicMail.mail.MailClient#isConnected() 
     258     */ 
    249259    public boolean isConnected() { 
    250260        return connection.isConnected(); 
    251261    } 
    252262 
     263    /* (non-Javadoc) 
     264     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getAcctConfig() 
     265     */ 
    253266    public AccountConfig getAcctConfig() { 
    254267        return accountConfig; 
    255268    } 
    256269 
     270    /* (non-Javadoc) 
     271     * @see org.logicprobe.LogicMail.mail.MailClient#getConnectionConfig() 
     272     */ 
    257273    public ConnectionConfig getConnectionConfig() { 
    258274                return getAcctConfig(); 
    259275        } 
    260276 
     277    /* (non-Javadoc) 
     278     * @see org.logicprobe.LogicMail.mail.MailClient#getUsername() 
     279     */ 
    261280    public String getUsername() { 
    262281        return username; 
    263282    } 
    264283 
     284    /* (non-Javadoc) 
     285     * @see org.logicprobe.LogicMail.mail.MailClient#setUsername(java.lang.String) 
     286     */ 
    265287    public void setUsername(String username) { 
    266288        this.username = username; 
    267289    } 
    268290 
     291    /* (non-Javadoc) 
     292     * @see org.logicprobe.LogicMail.mail.MailClient#getPassword() 
     293     */ 
    269294    public String getPassword() { 
    270295        return password; 
    271296    } 
    272297 
     298    /* (non-Javadoc) 
     299     * @see org.logicprobe.LogicMail.mail.MailClient#setPassword(java.lang.String) 
     300     */ 
    273301    public void setPassword(String password) { 
    274302        this.password = password; 
    275303    } 
    276304 
     305    /* (non-Javadoc) 
     306     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#hasFolders() 
     307     */ 
    277308    public boolean hasFolders() { 
    278309        return true; 
    279310    } 
    280311 
     312    /* (non-Javadoc) 
     313     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#hasUndelete() 
     314     */ 
    281315    public boolean hasUndelete() { 
    282316        return true; 
    283317    } 
    284318 
     319    /* (non-Javadoc) 
     320     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#hasIdle() 
     321     */ 
    285322    public boolean hasIdle() { 
    286323                return true; 
    287324        } 
    288325     
    289     public FolderTreeItem getFolderTree() throws IOException, MailException { 
     326    /* (non-Javadoc) 
     327     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getFolderTree(org.logicprobe.LogicMail.mail.MailProgressHandler) 
     328     */ 
     329    public FolderTreeItem getFolderTree(MailProgressHandler progressHandler) throws IOException, MailException { 
    290330        FolderTreeItem rootItem = new FolderTreeItem("", "", folderDelim); 
    291331         
     
    296336        if(folderPrefix != null && folderPrefix.length() > 0) { 
    297337            FolderTreeItem fakeRootItem = new FolderTreeItem("", folderPrefix, folderDelim); 
    298             getFolderTreeImpl(fakeRootItem, 0, childrenExtension); 
     338            getFolderTreeImpl(fakeRootItem, 0, childrenExtension, progressHandler); 
    299339             
    300340            // Since we have no way to find the inbox with a hard-coded prefix, 
     
    303343            // safely ignore.  Otherwise, create a folder item and add it. 
    304344            try { 
    305                 imapProtocol.executeStatus(new String[] { strINBOX }); 
     345                imapProtocol.executeStatus(new String[] { strINBOX }, null); 
    306346                FolderTreeItem inboxItem = new FolderTreeItem(rootItem, strINBOX, strINBOX, folderDelim, true, true); 
    307347                rootItem.addChild(inboxItem); 
     
    318358        } 
    319359        else { 
    320             getFolderTreeImpl(rootItem, 0, childrenExtension); 
     360            getFolderTreeImpl(rootItem, 0, childrenExtension, progressHandler); 
    321361        } 
    322362 
     
    330370    } 
    331371 
    332     private void getFolderTreeImpl(FolderTreeItem baseFolder, int depth, boolean childrenExtension) throws IOException, MailException { 
     372    private void getFolderTreeImpl(FolderTreeItem baseFolder, int depth, boolean childrenExtension, MailProgressHandler progressHandler) throws IOException, MailException { 
    333373        Vector respList; 
    334374        if(depth == 0) { 
    335             respList = imapProtocol.executeList(baseFolder.getPath(), "%"); 
     375            respList = imapProtocol.executeList(baseFolder.getPath(), "%", progressHandler); 
    336376        } 
    337377        else { 
    338             respList = imapProtocol.executeList(baseFolder.getPath() + baseFolder.getDelim(), "%"); 
     378            respList = imapProtocol.executeList(baseFolder.getPath() + baseFolder.getDelim(), "%", progressHandler); 
    339379        } 
    340380 
     
    347387                // The folder has children, so lets go and list them 
    348388                if(depth+1 < accountConfig.getMaxFolderDepth()) { 
    349                     getFolderTreeImpl(childItem, depth+1, childrenExtension); 
     389                    getFolderTreeImpl(childItem, depth+1, childrenExtension, progressHandler); 
    350390                } 
    351391            } 
     
    357397                // folder that matches the personal namespace prefix, so 
    358398                // look for children anyways. 
    359                 getFolderTreeImpl(childItem, depth+1, childrenExtension); 
    360             } 
    361         } 
    362     } 
    363  
    364     public void refreshFolderStatus(FolderTreeItem[] folders) throws IOException, MailException { 
     399                getFolderTreeImpl(childItem, depth+1, childrenExtension, progressHandler); 
     400            } 
     401        } 
     402    } 
     403 
     404    /* (non-Javadoc) 
     405     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#refreshFolderStatus(org.logicprobe.LogicMail.mail.FolderTreeItem[]) 
     406     */ 
     407    public void refreshFolderStatus(FolderTreeItem[] folders, MailProgressHandler progressHandler) throws IOException, MailException { 
    365408        int i; 
    366409         
     
    379422         
    380423        // Execute the STATUS command on the folders 
    381         ImapProtocol.StatusResponse[] response = imapProtocol.executeStatus(mboxPathsArray); 
     424        ImapProtocol.StatusResponse[] response = imapProtocol.executeStatus(mboxPathsArray, progressHandler); 
    382425         
    383426        // Iterate through the results and update the FolderTreeItem objects 
     
    447490    } 
    448491     
     492    /* (non-Javadoc) 
     493     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getActiveFolder() 
     494     */ 
    449495    public FolderTreeItem getActiveFolder() { 
    450496        return activeMailbox; 
    451497    } 
    452498 
     499    /* (non-Javadoc) 
     500     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#setActiveFolder(org.logicprobe.LogicMail.mail.FolderTreeItem) 
     501     */ 
    453502    public void setActiveFolder(FolderTreeItem mailbox) throws IOException, MailException { 
    454503        // Shortcut out if a folder change is not necessary 
     
    468517    } 
    469518     
     519    /* (non-Javadoc) 
     520     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#setActiveFolder(org.logicprobe.LogicMail.mail.MessageToken) 
     521     */ 
    470522    public void setActiveFolder(MessageToken messageToken) throws IOException, MailException { 
    471523        ImapMessageToken imapMessageToken = (ImapMessageToken)messageToken; 
     
    504556    } 
    505557     
    506     public FolderMessage[] getFolderMessages(int firstIndex, int lastIndex) throws IOException, MailException { 
     558    /* (non-Javadoc) 
     559     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getFolderMessages(int, int, org.logicprobe.LogicMail.mail.MailProgressHandler) 
     560     */ 
     561    public FolderMessage[] getFolderMessages(int firstIndex, int lastIndex, MailProgressHandler progressHandler) throws IOException, MailException { 
    507562        // Sanity check 
    508563        if(activeMailbox == null) { 
     
    516571         
    517572        ImapProtocol.FetchEnvelopeResponse[] response = 
    518                 imapProtocol.executeFetchEnvelope(firstIndex, lastIndex); 
     573                imapProtocol.executeFetchEnvelope(firstIndex, lastIndex, progressHandler); 
    519574         
    520575        return prepareFolderMessages(response); 
    521576    } 
    522577 
    523     public FolderMessage[] getNewFolderMessages() throws IOException, MailException { 
     578    /* (non-Javadoc) 
     579     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getNewFolderMessages(org.logicprobe.LogicMail.mail.MailProgressHandler) 
     580     */ 
     581    public FolderMessage[] getNewFolderMessages(MailProgressHandler progressHandler) throws IOException, MailException { 
    524582        // Sanity check 
    525583        if(activeMailbox == null) { 
     
    532590                        int msgCount = activeMailbox.getMsgCount(); 
    533591                int firstIndex = Math.max(1, msgCount - count); 
    534                 result = getFolderMessages(firstIndex, activeMailbox.getMsgCount()); 
     592                result = getFolderMessages(firstIndex, activeMailbox.getMsgCount(), progressHandler); 
    535593                seenMailboxes.put(activeMailbox, new Object()); 
    536594        } 
     
    538596                int uidNext = ((ImapProtocol.SelectResponse)knownMailboxes.get(activeMailbox)).uidNext; 
    539597                ImapProtocol.FetchEnvelopeResponse[] response = 
    540                         imapProtocol.executeFetchEnvelopeUid(uidNext); 
     598                        imapProtocol.executeFetchEnvelopeUid(uidNext, progressHandler); 
    541599                result = prepareFolderMessages(response); 
    542600                 
     
    569627    } 
    570628     
    571     public Message getMessage(MessageToken messageToken) throws IOException, MailException { 
     629    /* (non-Javadoc) 
     630     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getMessage(org.logicprobe.LogicMail.mail.MessageToken, org.logicprobe.LogicMail.mail.MailProgressHandler) 
     631     */ 
     632    public Message getMessage(MessageToken messageToken, MailProgressHandler progressHandler) throws IOException, MailException { 
    572633        ImapMessageToken imapMessageToken = (ImapMessageToken)messageToken; 
    573634        if(!imapMessageToken.getFolderPath().equalsIgnoreCase(activeMailbox.getPath())) { 
     
    579640        MimeMessagePart rootPart = 
    580641            getMessagePart(contentMap, imapMessageToken.getMessageUid(), 
    581                            structure, accountConfig.getMaxMessageSize()); 
     642                           structure, accountConfig.getMaxMessageSize(), 
     643                           progressHandler); 
    582644        Message msg = new Message(rootPart); 
    583645        Enumeration e = contentMap.keys(); 
     
    589651    } 
    590652 
    591     public MimeMessageContent getMessagePart(MessageToken messageToken, MimeMessagePart mimeMessagePart) throws IOException, MailException { 
     653    public MimeMessageContent getMessagePart(MessageToken messageToken, MimeMessagePart mimeMessagePart, MailProgressHandler progressHandler) throws IOException, MailException { 
    592654        ImapMessageToken imapMessageToken = (ImapMessageToken)messageToken; 
    593655        if(!imapMessageToken.getFolderPath().equalsIgnoreCase(activeMailbox.getPath())) { 
     
    607669 
    608670         
    609         String data = getMessageBody(imapMessageToken.getMessageUid(), partAddress); 
     671        String data = getMessageBody(imapMessageToken.getMessageUid(), partAddress, progressHandler); 
    610672        MimeMessageContent content; 
    611673        try { 
     
    621683                int uid, 
    622684            ImapParser.MessageSection structure, 
    623             int maxSize) 
     685            int maxSize, 
     686            MailProgressHandler progressHandler) 
    624687        throws IOException, MailException 
    625688    { 
     
    631694            else { 
    632695                if(structure.size < maxSize) { 
    633                     data = getMessageBody(uid, structure.address); 
     696                    data = getMessageBody(uid, structure.address, progressHandler); 
    634697                    maxSize -= structure.size; 
    635698                } 
     
    666729        if((part instanceof MultiPart)&&(structure.subsections != null)&&(structure.subsections.length > 0)) { 
    667730            for(int i=0;i<structure.subsections.length;i++) { 
    668                 MimeMessagePart subPart = getMessagePart(contentMap, uid, structure.subsections[i], maxSize); 
     731                MimeMessagePart subPart = getMessagePart(contentMap, uid, structure.subsections[i], maxSize, progressHandler); 
    669732                if(subPart != null) { 
    670733                    ((MultiPart)part).addPart(subPart); 
     
    731794    } 
    732795 
    733     private String getMessageBody(int uid, String address) throws IOException, MailException { 
     796    private String getMessageBody(int uid, String address, MailProgressHandler progressHandler) throws IOException, MailException { 
    734797        if(activeMailbox.equals("")) { 
    735798            throw new MailException("Mailbox not selected"); 
    736799        } 
    737          
    738         return imapProtocol.executeFetchBody(uid, address); 
    739     } 
    740      
     800        return imapProtocol.executeFetchBody(uid, address, progressHandler); 
     801    } 
     802     
     803    /* (non-Javadoc) 
     804     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#deleteMessage(org.logicprobe.LogicMail.mail.MessageToken, org.logicprobe.LogicMail.message.MessageFlags) 
     805     */ 
    741806    public void deleteMessage(MessageToken messageToken, MessageFlags messageFlags) throws IOException, MailException { 
    742807        ImapMessageToken imapMessageToken = (ImapMessageToken)messageToken; 
     
    751816 
    752817 
     818    /* (non-Javadoc) 
     819     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#undeleteMessage(org.logicprobe.LogicMail.mail.MessageToken, org.logicprobe.LogicMail.message.MessageFlags) 
     820     */ 
    753821    public void undeleteMessage(MessageToken messageToken, MessageFlags messageFlags) throws IOException, MailException { 
    754822        ImapMessageToken imapMessageToken = (ImapMessageToken)messageToken; 
     
    810878    } 
    811879 
     880        /* (non-Javadoc) 
     881         * @see org.logicprobe.LogicMail.mail.IncomingMailClient#noop() 
     882         */ 
    812883        public boolean noop() throws IOException, MailException { 
    813884                boolean result = imapProtocol.executeNoop(); 
     
    815886        } 
    816887         
     888        /* (non-Javadoc) 
     889         * @see org.logicprobe.LogicMail.mail.IncomingMailClient#idleModeBegin() 
     890         */ 
    817891        public void idleModeBegin() throws IOException, MailException { 
    818892                imapProtocol.executeIdle(); 
    819893        } 
    820894 
     895        /* (non-Javadoc) 
     896         * @see org.logicprobe.LogicMail.mail.IncomingMailClient#idleModeEnd() 
     897         */ 
    821898        public void idleModeEnd() throws IOException, MailException { 
    822899                imapProtocol.executeIdleDone(); 
    823900        } 
    824901 
     902        /* (non-Javadoc) 
     903         * @see org.logicprobe.LogicMail.mail.IncomingMailClient#idleModePoll() 
     904         */ 
    825905        public boolean idleModePoll() throws IOException, MailException { 
    826906                return imapProtocol.executeIdlePoll(); 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapProtocol.java

    r434 r471  
    3636import org.logicprobe.LogicMail.AppInfo; 
    3737import org.logicprobe.LogicMail.mail.MailException; 
     38import org.logicprobe.LogicMail.mail.MailProgressHandler; 
    3839import org.logicprobe.LogicMail.message.MessageEnvelope; 
    3940import org.logicprobe.LogicMail.util.Connection; 
     
    8283            execute("LOGIN", 
    8384                "\"" + StringParser.addEscapedChars(username) + "\" \"" + 
    84                 StringParser.addEscapedChars(password) + "\""); 
     85                StringParser.addEscapedChars(password) + "\"", null); 
    8586        } catch (MailException exp) { 
    8687            // Invalid users are caught by execute() 
     
    102103        } 
    103104 
    104         execute("LOGOUT", null); 
     105        execute("LOGOUT", null, null); 
    105106    } 
    106107 
     
    115116        } 
    116117 
    117         execute("CLOSE", null); 
     118        execute("CLOSE", null, null); 
    118119    } 
    119120 
     
    130131        } 
    131132 
    132         String[] replyText = execute("CAPABILITY", null); 
     133        String[] replyText = execute("CAPABILITY", null, null); 
    133134 
    134135        if ((replyText == null) || (replyText.length < 1)) { 
     
    160161        } 
    161162 
    162         String[] replyText = execute("NAMESPACE", null); 
     163        String[] replyText = execute("NAMESPACE", null, null); 
    163164 
    164165        if ((replyText == null) || (replyText.length < 1)) { 
     
    276277 
    277278        String[] replyText = execute("SELECT", 
    278                 "\"" + StringParser.addEscapedChars(mboxpath) + "\""); 
     279                "\"" + StringParser.addEscapedChars(mboxpath) + "\"", null); 
    279280        SelectResponse response = new SelectResponse(); 
    280281 
     
    351352    } 
    352353 
    353     public StatusResponse[] executeStatus(String[] mboxpaths) 
     354    public StatusResponse[] executeStatus(String[] mboxpaths, MailProgressHandler progressHandler) 
    354355        throws IOException, MailException { 
    355356        if (EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 
     
    380381        } 
    381382 
    382         String[] result = executeBatch("STATUS", arguments); 
     383        String[] result = executeBatch("STATUS", arguments, progressHandler); 
    383384 
    384385        if ((result == null) || (result.length != arguments.length)) { 
     
    432433     */ 
    433434    public FetchEnvelopeResponse[] executeFetchEnvelope(int firstIndex, 
    434         int lastIndex) throws IOException, MailException { 
     435        int lastIndex, MailProgressHandler progressHandler) throws IOException, MailException { 
    435436        if (EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 
    436437            EventLogger.logEvent(AppInfo.GUID, 
     
    441442        String[] rawList = execute("FETCH", 
    442443                Integer.toString(firstIndex) + ":" + 
    443                 Integer.toString(lastIndex) + " (FLAGS UID ENVELOPE BODYSTRUCTURE)"); 
    444  
    445         return prepareFetchEnvelopeResponse(rawList); 
     444                Integer.toString(lastIndex) + " (FLAGS UID ENVELOPE BODYSTRUCTURE)", progressHandler); 
     445 
     446        return prepareFetchEnvelopeResponse(rawList, progressHandler); 
    446447    } 
    447448 
     
    451452     * @return Array of FetchEnvelopeResponse objects 
    452453     */ 
    453     public FetchEnvelopeResponse[] executeFetchEnvelopeUid(int uidNext) 
     454    public FetchEnvelopeResponse[] executeFetchEnvelopeUid(int uidNext, MailProgressHandler progressHandler) 
    454455        throws IOException, MailException { 
    455456        if (EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 
     
    460461 
    461462        String[] rawList = execute("UID FETCH", 
    462                 Integer.toString(uidNext) + ":*" + " (FLAGS UID ENVELOPE BODYSTRUCTURE)"); 
    463  
    464         return prepareFetchEnvelopeResponse(rawList); 
     463                Integer.toString(uidNext) + ":*" + " (FLAGS UID ENVELOPE BODYSTRUCTURE)", progressHandler); 
     464 
     465        return prepareFetchEnvelopeResponse(rawList, progressHandler); 
    465466    } 
    466467 
    467468    private FetchEnvelopeResponse[] prepareFetchEnvelopeResponse( 
    468         String[] rawList) throws IOException, MailException { 
     469        String[] rawList, MailProgressHandler progressHandler) throws IOException, MailException { 
    469470        // Preprocess the returned text to clean up mid-field line breaks 
    470471        // This should all become unnecessary once execute() 
     
    474475        Vector rawList2 = new Vector(); 
    475476 
     477        if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_PROCESSING, 0, -1); } 
    476478        for (int i = 0; i < rawList.length; i++) { 
    477479            line = rawList[i]; 
     
    494496        int size = rawList2.size(); 
    495497 
     498        if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_PROCESSING, 0, size); } 
    496499        for (int i = 0; i < size; i++) { 
    497500            try { 
     
    567570                System.err.println("Parse error: " + exp); 
    568571            } 
     572            if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_PROCESSING, i, size); } 
    569573        } 
    570574 
    571575        FetchEnvelopeResponse[] result = new FetchEnvelopeResponse[envResponses.size()]; 
    572576        envResponses.copyInto(result); 
     577        if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_PROCESSING, size, size); } 
    573578 
    574579        return result; 
     
    588593        } 
    589594 
    590         String[] rawList = execute("UID FETCH", uid + " (BODYSTRUCTURE)"); 
     595        String[] rawList = execute("UID FETCH", uid + " (BODYSTRUCTURE)", null); 
    591596 
    592597        // Pre-process the returned text to clean up mid-field line breaks 
     
    632637     * @param uid Unique ID of the message 
    633638     * @param address Address of the body section (i.e. "1", "1.2") 
     639     * @param progressHandler the progress handler 
    634640     * @return Body text as a string 
    635641     */ 
    636     public String executeFetchBody(int uid, String address) 
     642    public String executeFetchBody(int uid, String address, MailProgressHandler progressHandler) 
    637643        throws IOException, MailException { 
    638644        if (EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 
     
    642648        } 
    643649 
    644         String[] rawList = execute("UID FETCH", uid + " (BODY[" + address + 
    645                 "])"); 
     650        String[] rawList = execute( 
     651                        "UID FETCH", 
     652                        uid + " (BODY[" + address + "])", 
     653                        progressHandler); 
    646654 
    647655        if (rawList.length <= 1) { 
     
    741749        buf.append(')'); 
    742750 
    743         String[] rawList = execute("UID STORE", buf.toString()); 
     751        String[] rawList = execute("UID STORE", buf.toString(), null); 
    744752 
    745753        if (rawList.length < 1) { 
     
    807815 
    808816    /** 
    809      * Execute the "LIST" command, and return a fully parsed response 
     817     * Execute the "LIST" command, and return a fully parsed response. 
     818     *  
    810819     * @param refName Reference name 
    811820     * @param mboxName Mailbox name or wildcards (i.e. "%") 
     821     * @param progressHandler the progress handler 
    812822     * @return Vector of ListResponse objects 
    813823     */ 
    814     public Vector executeList(String refName, String mboxName) 
     824    public Vector executeList(String refName, String mboxName, MailProgressHandler progressHandler) 
    815825        throws IOException, MailException { 
    816826        if (EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 
     
    823833        results = execute("LIST", 
    824834                "\"" + StringParser.addEscapedChars(refName) + "\" \"" + 
    825                 StringParser.addEscapedChars(mboxName) + "\""); 
     835                StringParser.addEscapedChars(mboxName) + "\"", progressHandler); 
    826836 
    827837        Vector retVec = new Vector(results.length); 
     
    837847        int line = 0; 
    838848 
     849        if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_PROCESSING, 0, -1); } 
     850         
    839851        while (line < results.length) { 
    840852            p = results[line].indexOf('{'); 
     
    855867        int resultsSize = resultsVec.size(); 
    856868 
     869        if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_PROCESSING, 0, resultsSize); } 
    857870        for (int i = 0; i < resultsSize; i++) { 
    858871            // Separate out the flag and argument strings 
     
    943956                // Prevent parse errors from being fatal 
    944957            } 
    945         } 
     958            if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_PROCESSING, i, resultsSize); } 
     959        } 
     960        if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_PROCESSING, resultsSize, resultsSize); } 
    946961 
    947962        return retVec; 
     
    959974                EventLogger.DEBUG_INFO); 
    960975        } 
    961         String[] replyText = execute("NOOP", null); 
     976        String[] replyText = execute("NOOP", null, null); 
    962977 
    963978        if ((replyText == null) || (replyText.length < 1)) { 
     
    10261041     * @param command IMAP command 
    10271042     * @param arguments Arguments for the commands 
     1043     * @param progressHandler the progress handler 
    10281044     * @return List of returned strings 
    10291045     */ 
    1030     protected String[] executeBatch(String command, String[] arguments) 
     1046    protected String[] executeBatch(String command, String[] arguments, MailProgressHandler progressHandler) 
    10311047        throws IOException, MailException { 
    10321048        String[] result = new String[arguments.length]; 
     
    10471063        } 
    10481064 
     1065        int preCount = connection.getBytesReceived(); 
    10491066        connection.sendRaw(commandBuf.toString()); 
     1067        int postCount = connection.getBytesReceived(); 
     1068        if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 
    10501069 
    10511070        String temp; 
     
    10541073 
    10551074        while (count < arguments.length) { 
     1075            preCount = postCount; 
    10561076            temp = connection.receive(); 
     1077            postCount = connection.getBytesReceived(); 
     1078            if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 
    10571079 
    10581080            String temp2 = temp.substring(temp.indexOf(" ") + 1); 
     
    10831105     * @return List of returned strings 
    10841106     */ 
    1085     protected String[] execute(String command, String arguments) 
     1107    protected String[] execute(String command, String arguments, MailProgressHandler progressHandler) 
    10861108        throws IOException, MailException { 
    10871109        String[] result = new String[0]; 
     
    10911113            ((arguments == null) ? "" : (" " + arguments))); 
    10921114 
     1115        int preCount = connection.getBytesReceived(); 
    10931116        String temp = connection.receive(); 
    1094  
     1117        int postCount = connection.getBytesReceived(); 
     1118        if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 
     1119         
    10951120        while (!temp.startsWith(tag)) { 
    10961121            Arrays.add(result, temp); 
     1122            preCount = postCount; 
    10971123            temp = connection.receive(); 
     1124            postCount = connection.getBytesReceived(); 
     1125            if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 
    10981126        } 
    10991127 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/mail/pop/PopClient.java

    r467 r471  
    4646import org.logicprobe.LogicMail.mail.IncomingMailClient; 
    4747import org.logicprobe.LogicMail.mail.MailException; 
     48import org.logicprobe.LogicMail.mail.MailProgressHandler; 
    4849import org.logicprobe.LogicMail.mail.MessageToken; 
    4950import org.logicprobe.LogicMail.message.FolderMessage; 
     
    132133    } 
    133134 
     135    /* (non-Javadoc) 
     136     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getAcctConfig() 
     137     */ 
    134138    public AccountConfig getAcctConfig() { 
    135139        return accountConfig; 
    136140    } 
    137141 
     142    /* (non-Javadoc) 
     143     * @see org.logicprobe.LogicMail.mail.MailClient#getConnectionConfig() 
     144     */ 
    138145    public ConnectionConfig getConnectionConfig() { 
    139146                return getAcctConfig(); 
    140147        } 
    141148 
     149    /* (non-Javadoc) 
     150     * @see org.logicprobe.LogicMail.mail.MailClient#open() 
     151     */ 
    142152    public boolean open() throws IOException, MailException { 
    143153        if(!openStarted) { 
     
    162172    } 
    163173 
     174    /* (non-Javadoc) 
     175     * @see org.logicprobe.LogicMail.mail.MailClient#close() 
     176     */ 
    164177    public void close() throws IOException, MailException { 
    165178        if(connection.isConnected()) { 
     
    182195    } 
    183196 
     197    /* (non-Javadoc) 
     198     * @see org.logicprobe.LogicMail.mail.MailClient#isConnected() 
     199     */ 
    184200    public boolean isConnected() { 
    185201        return connection.isConnected(); 
    186202    } 
    187203 
     204    /* (non-Javadoc) 
     205     * @see org.logicprobe.LogicMail.mail.MailClient#getUsername() 
     206     */ 
    188207    public String getUsername() { 
    189208        return username; 
    190209    } 
    191210 
     211    /* (non-Javadoc) 
     212     * @see org.logicprobe.LogicMail.mail.MailClient#setUsername(java.lang.String) 
     213     */ 
    192214    public void setUsername(String username) { 
    193215        this.username = username; 
    194216    } 
    195217 
     218    /* (non-Javadoc) 
     219     * @see org.logicprobe.LogicMail.mail.MailClient#getPassword() 
     220     */ 
    196221    public String getPassword() { 
    197222        return password; 
    198223    } 
    199224 
     225    /* (non-Javadoc) 
     226     * @see org.logicprobe.LogicMail.mail.MailClient#setPassword(java.lang.String) 
     227     */ 
    200228    public void setPassword(String password) { 
    201229        this.password = password; 
    202230    } 
    203231 
     232    /* (non-Javadoc) 
     233     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#hasFolders() 
     234     */ 
    204235    public boolean hasFolders() { 
    205236        return false; 
    206237    } 
    207238 
     239    /* (non-Javadoc) 
     240     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#hasUndelete() 
     241     */ 
    208242    public boolean hasUndelete() { 
    209243        return false; 
    210244    } 
    211245 
     246    /* (non-Javadoc) 
     247     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#hasIdle() 
     248     */ 
    212249    public boolean hasIdle() { 
    213250                return false; 
    214251        } 
    215252 
    216     public FolderTreeItem getFolderTree() throws IOException, MailException { 
     253    /* (non-Javadoc) 
     254     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getFolderTree(org.logicprobe.LogicMail.mail.MailProgressHandler) 
     255     */ 
     256    public FolderTreeItem getFolderTree(MailProgressHandler progressHandler) throws IOException, MailException { 
    217257        return null; 
    218258    } 
    219259 
    220     public void refreshFolderStatus(FolderTreeItem[] folders) throws IOException, MailException { 
    221         // Only one mailbox can exist, so we just pull the message counts 
     260    /* (non-Javadoc) 
     261     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#refreshFolderStatus(org.logicprobe.LogicMail.mail.FolderTreeItem[], org.logicprobe.LogicMail.mail.MailProgressHandler) 
     262     */ 
     263    public void refreshFolderStatus(FolderTreeItem[] folders, MailProgressHandler progressHandler) throws IOException, MailException { 
     264        // Only one mailbox can exist, so we just pull the message counts. 
     265        // Since this is a single operation with POP, there is no reason to 
     266        // provide more detailed status through the progress handler. 
    222267        activeMailbox.setMsgCount(popProtocol.executeStat()); 
    223268        if(folders.length == 1 && folders[0] != activeMailbox) { 
     
    226271    } 
    227272 
     273    /* (non-Javadoc) 
     274     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getInboxFolder() 
     275     */ 
    228276    public FolderTreeItem getInboxFolder() { 
    229277        return activeMailbox; 
    230278    } 
    231279     
     280    /* (non-Javadoc) 
     281     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getActiveFolder() 
     282     */ 
    232283    public FolderTreeItem getActiveFolder() { 
    233284        return activeMailbox; 
    234285    } 
    235286 
     287    /* (non-Javadoc) 
     288     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#setActiveFolder(org.logicprobe.LogicMail.mail.FolderTreeItem) 
     289     */ 
    236290    public void setActiveFolder(FolderTreeItem mailbox) throws IOException, MailException { 
    237291        // Mailbox cannot be changed, so we just pull the message counts 
     
    239293    } 
    240294 
     295    /* (non-Javadoc) 
     296     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#setActiveFolder(org.logicprobe.LogicMail.mail.MessageToken) 
     297     */ 
    241298    public void setActiveFolder(MessageToken messageToken) throws IOException, MailException { 
    242299        // Mailbox cannot be changed, so we just pull the message counts 
     
    244301    } 
    245302     
    246     public FolderMessage[] getFolderMessages(int firstIndex, int lastIndex) throws IOException, MailException { 
    247         FolderMessage[] folderMessages = new FolderMessage[(lastIndex - firstIndex)+1]; 
     303    /* (non-Javadoc) 
     304     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getFolderMessages(int, int, org.logicprobe.LogicMail.mail.MailProgressHandler) 
     305     */ 
     306    public FolderMessage[] getFolderMessages(int firstIndex, int lastIndex, MailProgressHandler progressHandler) throws IOException, MailException { 
     307        FolderMessage[] folderMessages = new FolderMessage[(lastIndex - firstIndex)+1]; 
    248308        int index = 0; 
    249309        String[] headerText; 
    250310        String uid; 
    251311        MessageEnvelope env; 
     312        int preCount; 
     313        int postCount = connection.getBytesReceived(); 
    252314        for(int i=firstIndex; i<=lastIndex; i++) { 
     315                preCount = postCount; 
    253316            headerText = popProtocol.executeTop(i, 0); 
    254317            uid = popProtocol.executeUidl(i); 
     
    257320                        new PopMessageToken(i, uid), 
    258321                        env, i, uid.hashCode()); 
     322            postCount = connection.getBytesReceived(); 
     323            if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 
    259324        } 
    260325        return folderMessages; 
    261326    } 
    262327 
    263     public FolderMessage[] getNewFolderMessages() throws IOException, MailException { 
     328    /* (non-Javadoc) 
     329     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getNewFolderMessages(org.logicprobe.LogicMail.mail.MailProgressHandler) 
     330     */ 
     331    public FolderMessage[] getNewFolderMessages(MailProgressHandler progressHandler) throws IOException, MailException { 
    264332        int count = MailSettings.getInstance().getGlobalConfig().getRetMsgCount(); 
    265333                int msgCount = activeMailbox.getMsgCount(); 
    266334        int firstIndex = Math.max(1, msgCount - count); 
    267         return getFolderMessages(firstIndex, activeMailbox.getMsgCount()); 
    268     } 
    269  
    270     public Message getMessage(MessageToken messageToken) throws IOException, MailException { 
     335        return getFolderMessages(firstIndex, activeMailbox.getMsgCount(), progressHandler); 
     336    } 
     337 
     338    /* (non-Javadoc) 
     339     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getMessage(org.logicprobe.LogicMail.mail.MessageToken, org.logicprobe.LogicMail.mail.MailProgressHandler) 
     340     */ 
     341    public Message getMessage(MessageToken messageToken, MailProgressHandler progressHandler) throws IOException, MailException { 
    271342        PopMessageToken popMessageToken = (PopMessageToken)messageToken; 
    272343         
     
    275346 
    276347        // Download the message text 
    277         String[] message = popProtocol.executeTop((popMessageToken.getMessageIndex()), maxLines); 
     348        String[] message = popProtocol.executeTop((popMessageToken.getMessageIndex()), maxLines, progressHandler); 
    278349         
    279350        Hashtable contentMap = new Hashtable(); 
     
    288359    } 
    289360 
     361    /* (non-Javadoc) 
     362     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#deleteMessage(org.logicprobe.LogicMail.mail.MessageToken, org.logicprobe.LogicMail.message.MessageFlags) 
     363     */ 
    290364    public void deleteMessage(MessageToken messageToken, MessageFlags messageFlags) throws IOException, MailException { 
    291365        PopMessageToken popMessageToken = (PopMessageToken)messageToken; 
     
    295369    } 
    296370 
     371    /* (non-Javadoc) 
     372     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#undeleteMessage(org.logicprobe.LogicMail.mail.MessageToken, org.logicprobe.LogicMail.message.MessageFlags) 
     373     */ 
    297374    public void undeleteMessage(MessageToken messageToken, MessageFlags messageFlags) throws IOException, MailException { 
    298375        // Undelete is not supported, so we do nothing here. 
    299376    } 
    300377 
     378    /* (non-Javadoc) 
     379     * @see org.logicprobe.LogicMail.mail.IncomingMailClient#noop() 
     380     */ 
    301381    public boolean noop() throws IOException, MailException { 
    302382        popProtocol.executeNoop(); 
     
    304384        } 
    305385 
     386        /* (non-Javadoc) 
     387         * @see org.logicprobe.LogicMail.mail.IncomingMailClient#idleModeBegin() 
     388         */ 
    306389        public void idleModeBegin() throws IOException, MailException { 
    307390                // Idle mode is not supported, so we do nothing here. 
    308391        } 
    309392 
     393        /* (non-Javadoc) 
     394         * @see org.logicprobe.LogicMail.mail.IncomingMailClient#idleModeEnd() 
     395         */ 
    310396        public void idleModeEnd() throws IOException, MailException { 
    311397                // Idle mode is not supported, so we do nothing here. 
    312398        } 
    313399 
     400        /* (non-Javadoc) 
     401         * @see org.logicprobe.LogicMail.mail.IncomingMailClient#idleModePoll() 
     402         */ 
    314403        public boolean idleModePoll() throws IOException, MailException { 
    315404                // Idle mode is not supported, so we do nothing here. 
    316405                return false; 
    317406        } 
    318  
    319407} 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/mail/pop/PopProtocol.java

    r303 r471  
    3737import org.logicprobe.LogicMail.AppInfo; 
    3838import org.logicprobe.LogicMail.mail.MailException; 
     39import org.logicprobe.LogicMail.mail.MailProgressHandler; 
    3940import org.logicprobe.LogicMail.util.Connection; 
    4041 
     
    122123     */ 
    123124    public String[] executeTop(int index, int lines) throws IOException, MailException { 
     125        return executeTop(index, lines, null); 
     126    } 
     127     
     128    /** 
     129     * Execute the "TOP" command 
     130     * @param index Message index 
     131     * @param lines Number of lines to retrieve 
     132     * @param progressHandler progress handler 
     133     */ 
     134    public String[] executeTop(int index, int lines, MailProgressHandler progressHandler) throws IOException, MailException { 
    124135        if(EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 
    125136            EventLogger.logEvent( 
     
    128139            EventLogger.DEBUG_INFO); 
    129140        } 
    130         return executeFollow("TOP " + index + " " + lines); 
     141        return executeFollow("TOP " + index + " " + lines, progressHandler); 
    131142    } 
    132143     
     
    188199     * 
    189200     * @param command The command to execute 
     201     * @param progressHandler progress handler 
    190202     * @return An array of lines containing the response 
    191203     */ 
    192     private String[] executeFollow(String command) throws IOException, MailException { 
     204    private String[] executeFollow(String command, MailProgressHandler progressHandler) throws IOException, MailException { 
     205        int preCount = connection.getBytesReceived(); 
    193206        execute(command); 
    194              
     207         
    195208        String buffer = connection.receive(); 
     209        int postCount = connection.getBytesReceived(); 
     210        if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 
     211 
    196212        String[] lines = new String[0]; 
    197213        while(buffer != null && !buffer.equals(".")) { 
    198214            Arrays.add(lines, buffer); 
     215            preCount = postCount; 
    199216            buffer = connection.receive(); 
     217            postCount = connection.getBytesReceived(); 
     218            if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 
    200219        } 
    201220        return lines; 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/ui/MessagePropertiesScreen.java

    r467 r471  
    3838import org.logicprobe.LogicMail.model.Address; 
    3939import org.logicprobe.LogicMail.model.MessageNode; 
     40import org.logicprobe.LogicMail.util.StringParser; 
    4041import org.logicprobe.LogicMail.util.UnicodeNormalizer; 
    4142 
     
    211212        if(partSize > 0) { 
    212213                buf.append(" ("); 
    213                 if(partSize < 1024) { 
    214                         buf.append(partSize); 
    215                         buf.append('B'); 
    216                 } 
    217                 else { 
    218                         partSize /= 1024; 
    219                         buf.append(partSize); 
    220                         buf.append("kB"); 
    221                 } 
     214                buf.append(StringParser.toDataSizeString(partSize)); 
    222215                buf.append(')'); 
    223216        } 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/util/Connection.java

    r449 r471  
    119119    private boolean useWiFi; 
    120120    private int fakeAvailable = -1; 
    121  
     121    private int bytesSent = 0; 
     122    private int bytesReceived = 0; 
     123     
    122124    /** 
    123125     * Provides a buffer used for incoming data. 
     
    193195        output = socket.openDataOutputStream(); 
    194196        localAddress = ((SocketConnection) socket).getLocalAddress(); 
    195  
     197        bytesSent = 0; 
     198        bytesReceived = 0; 
     199         
    196200        if (EventLogger.getMinimumLevel() >= EventLogger.INFORMATION) { 
    197201            String msg = "Connection established:\r\n" + "Socket: " + 
     
    305309    } 
    306310 
     311    /** 
     312     * Gets the number of bytes that have been sent since the 
     313     * connection was opened. 
     314     * <p> 
     315     * The counter is not synchronized, so it should only be 
     316     * called from the same thread as the send and receive 
     317     * methods. 
     318     * </p> 
     319     * @return bytes sent 
     320     */ 
     321    public int getBytesSent() { 
     322        return bytesSent; 
     323    } 
     324     
     325    /** 
     326     * Gets the number of bytes that have been received since the 
     327     * connection was opened. 
     328     * <p> 
     329     * The counter is not synchronized, so it should only be 
     330     * called from the same thread as the send and receive 
     331     * methods. 
     332     * </p> 
     333     * @return bytes received 
     334     */ 
     335    public int getBytesReceived() { 
     336        return bytesReceived; 
     337    } 
     338     
    307339    /** 
    308340     * Sends a string to the server. This method is used internally for 
     
    328360 
    329361            output.write(CRLF, 0, 2); 
     362            bytesSent += 2; 
    330363        } 
    331364        /** 
     
    356389                 * Write the string up to there and terminate it properly. 
    357390                 */ 
    358                 output.write((s.substring(i, j) + "\r\n").getBytes()); 
     391                byte[] buf = (s.substring(i, j) + "\r\n").getBytes(); 
     392                output.write(buf); 
     393                bytesSent += buf.length; 
    359394 
    360395                /** 
     
    386421        if (s == null) { 
    387422            output.write(CRLF, 0, 2); 
     423            bytesSent += 2; 
    388424        } else { 
    389             output.write((s + "\r\n").getBytes()); 
     425                byte[] buf = (s + "\r\n").getBytes(); 
     426            output.write(buf); 
     427            bytesSent += buf.length; 
    390428        } 
    391429 
     
    402440     */ 
    403441    public synchronized void sendRaw(String s) throws IOException { 
    404         byte[] bytes = s.getBytes(); 
     442        byte[] buf = s.getBytes(); 
    405443 
    406444        if (globalConfig.getConnDebug()) { 
     
    409447        } 
    410448 
    411         output.write(bytes, 0, bytes.length); 
    412  
     449        output.write(buf, 0, buf.length); 
     450        bytesSent += buf.length; 
     451         
    413452        output.flush(); 
    414453    } 
     
    487526            while (true) { 
    488527                int actual = input.read(buffer, count, 1); 
    489  
     528                 
    490529                /** 
    491530                 * If -1 is returned, the InputStream is already closed, 
     
    524563                // approach which screws up on mid-line LFs. (DK) 
    525564                else { 
     565                        bytesReceived += actual; 
     566                         
    526567                    byte b = buffer[count]; 
    527568                    readBytes++; 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/util/StringParser.java

    r446 r471  
    11761176        return result; 
    11771177    } 
     1178     
     1179    /** 
     1180     * Converts a numerical byte quantity into a nicer human-readable 
     1181     * unit representation. 
     1182     *  
     1183     * @param dataSize Size in bytes 
     1184     * @return Printable string 
     1185     */ 
     1186    public static String toDataSizeString(int dataSize) { 
     1187        StringBuffer buf = new StringBuffer(); 
     1188 
     1189        if(dataSize < 1024) { 
     1190                        buf.append(dataSize); 
     1191                        buf.append('B'); 
     1192                } 
     1193                else { 
     1194                        buf.append((int)(dataSize / 1024)); 
     1195                        buf.append('k'); 
     1196                } 
     1197         
     1198        return buf.toString(); 
     1199    } 
    11781200} 
  • trunk/LogicMailTests/src/org/logicprobe/LogicMail/mail/NetworkMailStoreTest.java

    r453 r471  
    345345                public FolderTreeItem getInboxFolder() { return inboxFolder; } 
    346346                public FolderTreeItem getActiveFolder() { return activeFolder; } 
    347                 public FolderMessage[] getFolderMessages(int firstIndex, int lastIndex) 
     347                public FolderMessage[] getFolderMessages(int firstIndex, int lastIndex, MailProgressHandler progressHandler) 
    348348                                throws IOException, MailException { this.firstIndex = firstIndex; this.lastIndex = lastIndex; return this.folderMessages; } 
    349                 public FolderMessage[] getNewFolderMessages() throws IOException, MailException { return null; } 
    350                 public FolderTreeItem getFolderTree() throws IOException, MailException { return this.folderTree; } 
    351                 public Message getMessage(MessageToken messageToken) 
     349                public FolderMessage[] getNewFolderMessages(MailProgressHandler progressHandler) throws IOException, MailException { return null; } 
     350                public FolderTreeItem getFolderTree(MailProgressHandler progressHandler) throws IOException, MailException { return this.folderTree; } 
     351                public Message getMessage(MessageToken messageToken, MailProgressHandler progressHandler) 
    352352                                throws IOException, MailException { this.messageToken = messageToken; return this.message; } 
    353                 public void refreshFolderStatus(FolderTreeItem[] folders) 
     353                public void refreshFolderStatus(FolderTreeItem[] folders, MailProgressHandler progressHandler) 
    354354                                throws IOException, MailException { folders[0].setMsgCount(refreshedMsgCount); } 
    355355                public void setActiveFolder(FolderTreeItem folderItem) 
  • trunk/LogicMailTests/src/org/logicprobe/LogicMail/mail/imap/ImapProtocolTest.java

    r435 r471  
    3636import j2meunit.framework.TestSuite; 
    3737 
     38import org.logicprobe.LogicMail.mail.MailProgressHandler; 
    3839import org.logicprobe.LogicMail.message.MessageEnvelope; 
    3940import org.logicprobe.LogicMail.util.StringParser; 
     
    154155                new String[] { "* LIST (\\HasChildren) \".\" \"INBOX\"" }); 
    155156 
    156             Vector result = instance.executeList("", "%"); 
     157            Vector result = instance.executeList("", "%", null); 
    157158            assertNotNull(result); 
    158159            assertEquals(1, result.size()); 
     
    181182                }); 
    182183 
    183             Vector result = instance.executeList("INBOX.", "%"); 
     184            Vector result = instance.executeList("INBOX.", "%", null); 
    184185            assertNotNull(result); 
    185186            assertEquals(2, result.size()); 
     
    216217                }); 
    217218 
    218             Vector result = instance.executeList("", "%"); 
     219            Vector result = instance.executeList("", "%", null); 
    219220            assertNotNull(result); 
    220221            assertEquals(2, result.size()); 
     
    252253                }); 
    253254 
    254             Vector result = instance.executeList("INBOX.", "%"); 
     255            Vector result = instance.executeList("INBOX.", "%", null); 
    255256            assertNotNull(result); 
    256257            assertEquals(2, result.size()); 
     
    287288                }); 
    288289 
    289             Vector result = instance.executeList("INBOX\\", "%"); 
     290            Vector result = instance.executeList("INBOX\\", "%", null); 
    290291            assertNotNull(result); 
    291292            assertEquals(2, result.size()); 
     
    322323                }); 
    323324 
    324             Vector result = instance.executeList("2007\\", "%"); 
     325            Vector result = instance.executeList("2007\\", "%", null); 
    325326            assertNotNull(result); 
    326327            assertEquals(2, result.size()); 
     
    363364                }); 
    364365 
    365             ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1); 
     366            ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1, null); 
    366367            assertNotNull(result); 
    367368            assertEquals(1, result.length); 
     
    447448                }); 
    448449 
    449             ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1); 
     450            ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1, null); 
    450451            assertNotNull(result); 
    451452            assertEquals(1, result.length); 
     
    531532                }); 
    532533 
    533             ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1); 
     534            ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1, null); 
    534535            assertNotNull(result); 
    535536            assertEquals(1, result.length); 
     
    618619                }); 
    619620 
    620             ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1); 
     621            ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1, null); 
    621622            assertNotNull(result); 
    622623            assertEquals(1, result.length); 
     
    858859        } 
    859860 
    860         protected String[] execute(String command, String arguments) { 
     861        protected String[] execute(String command, String arguments, MailProgressHandler progressHandler) { 
    861862            assertTrue("No expectations", !executeExpectations.isEmpty()); 
    862863 
Note: See TracChangeset for help on using the changeset viewer.