Changeset 618


Ignore:
Timestamp:
01/19/10 21:41:34 (2 years ago)
Author:
octorian
Message:

UI and model implementations for basic Copy-To/Move-To. (Still some issues that need to be resolved at the IMAP level, and when dealing with cached-but-unloaded messages)

Location:
trunk/LogicMail/src/org/logicprobe/LogicMail
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/LogicMail/src/org/logicprobe/LogicMail/model/MailboxNode.java

    r591 r618  
    4444import org.logicprobe.LogicMail.AppInfo; 
    4545import org.logicprobe.LogicMail.mail.FolderTreeItem; 
     46import org.logicprobe.LogicMail.mail.MailStoreRequestCallback; 
    4647import org.logicprobe.LogicMail.mail.MessageToken; 
    4748import org.logicprobe.LogicMail.message.Message; 
     
    411412         * Copies a message into this mailbox from another mailbox within the same account. 
    412413         * This method will request the underlying mail store to copy the message 
    413          * on the server side.  If the mail store does not support this operation, then 
    414          * this method will have no effect. 
     414         * on the server side. 
     415     * <p> 
     416     * If the mail store does not support this operation, then this method will 
     417     * have no effect. 
     418     * </p> 
    415419         *  
    416420         * @param messageNode Message to copy into this mailbox 
     
    426430        } 
    427431 
     432    /** 
     433     * Moves a message into this mailbox from another mailbox within the same account. 
     434     * This method will request the underlying mail store to copy the message 
     435     * on the server side.  If and only if the copy is successful, the source message 
     436     * will be marked as deleted. 
     437     * <p> 
     438     * If the mail store does not support this operation, then this method will 
     439     * have no effect. 
     440     * </p> 
     441     *  
     442     * @param messageNode Message to copy into this mailbox 
     443     */ 
     444        public void moveMessageInto(MessageNode messageNode) { 
     445            // Sanity check 
     446            if(!(this.hasAppend 
     447                    && this.hasCopy() 
     448                    && messageNode.getParent().getParentAccount() == this.parentAccount)) { 
     449                return; 
     450            } 
     451            parentAccount.getMailStore().requestMessageCopy( 
     452                    messageNode.getMessageToken(), 
     453                    this.folderTreeItem, 
     454                    new MoveMessageIntoCallback(messageNode)); 
     455        } 
     456         
     457        /** 
     458         * Callback to handle the result of the copy operation dispatched 
     459         * from <code>moveMessageInto(messageNode)</code>.  If that operation 
     460         * succeeds, then a request is dispatched to mark the original message 
     461         * as deleted.  If it fails, then nothing happens. 
     462         */ 
     463        private class MoveMessageIntoCallback implements MailStoreRequestCallback { 
     464            private MessageNode messageNode; 
     465             
     466            /** 
     467         * Instantiates a new callback for handling the result 
     468         * of the copy operation involved in a message move. 
     469         *  
     470         * @param messageNode the source message node 
     471         */ 
     472        public MoveMessageIntoCallback(MessageNode messageNode) { 
     473                this.messageNode = messageNode; 
     474            } 
     475             
     476        public void mailStoreRequestComplete() { 
     477            // If the move request succeeded, then dispatch a request 
     478            // to have the original message marked as deleted. 
     479            parentAccount.getMailStore().requestMessageDelete( 
     480                    messageNode.getMessageToken(), 
     481                    MessageNode.createMessageFlags(messageNode.getFlags())); 
     482        } 
     483 
     484        public void mailStoreRequestFailed(Throwable exception) { 
     485            // Do nothing if the request failed 
     486        } 
     487        } 
     488         
    428489        /** 
    429490         * Adds a mailbox to this mailbox. 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/ui/MessageActions.java

    r615 r618  
    200200         
    201201        // Move-To is currently only supported if the underlying mail store 
    202         // supports protocol-level copy, since it is the only safe way to 
    203         // ensure no message data is lost. 
     202        // supports protocol-level copy, and then only between folders on that 
     203        // mail store.  These limitations have been chosen because it is the 
     204        // simplest way to be absolutely sure that a user cannot mess up their 
     205        // data with a message move. 
    204206        if(mailboxNode.hasCopy()) { 
    205207            menu.add(moveToItem); 
     
    378380    public void copyToMailbox(MessageNode messageNode) { 
    379381        if(messageNode.hasMessageContent()) { 
     382            // Normal case where the message has been loaded within the 
     383            // data model and all copy options should be made available. 
    380384                AccountNode[] accountNodes = MailManager.getInstance().getMailRootNode().getAccounts(); 
    381385                MailboxSelectionDialog dialog = new MailboxSelectionDialog( 
     
    390394                        if(selectedMailbox.hasCopy() 
    391395                                        && selectedMailbox.getParentAccount() == messageNode.getParent().getParentAccount()) { 
     396                            // The source and destination are on the same mail store, 
     397                            // and that mail store supports protocol-level copy. 
    392398                                selectedMailbox.copyMessageInto(messageNode); 
    393399                        } 
    394400                        else { 
     401                            // Protocol-level copy is not possible, so just append 
     402                            // to the destination mailbox. 
    395403                                selectedMailbox.appendMessage(messageNode); 
    396404                        } 
    397405                } 
    398406        } 
     407        else if(messageNode.getParent().hasCopy()) { 
     408            // Alternate case where the message has not been loaded, but is 
     409            // on a mail store that supports protocol-level copy.  In this 
     410            // situation, only other mailboxes on the same mail store are 
     411            // to be considered valid destinations. 
     412            MailboxSelectionDialog dialog = new MailboxSelectionDialog( 
     413                    resources.getString(LogicMailResource.MESSAGE_SELECT_FOLDER_COPY_TO), 
     414                    new AccountNode[] { messageNode.getParent().getParentAccount() }); 
     415            dialog.setSelectedMailboxNode(messageNode.getParent()); 
     416            dialog.addUnselectableNode(messageNode.getParent()); 
     417            dialog.doModal(); 
     418             
     419            MailboxNode selectedMailbox = dialog.getSelectedMailboxNode(); 
     420            if(selectedMailbox != null && selectedMailbox != messageNode.getParent()) { 
     421                selectedMailbox.copyMessageInto(messageNode); 
     422            } 
     423        } 
    399424    } 
    400425     
     
    405430     */ 
    406431    public void moveToMailbox(MessageNode messageNode) { 
    407         if(messageNode.hasMessageContent()) { 
    408                 AccountNode[] accountNodes = MailManager.getInstance().getMailRootNode().getAccounts(); 
     432        if(messageNode.getParent().hasCopy()) { 
    409433                MailboxSelectionDialog dialog = new MailboxSelectionDialog( 
    410434                                resources.getString(LogicMailResource.MESSAGE_SELECT_FOLDER_MOVE_TO), 
    411                                 accountNodes); 
     435                                new AccountNode[] { messageNode.getParent().getParentAccount() }); 
    412436                dialog.setSelectedMailboxNode(messageNode.getParent()); 
    413437                dialog.addUnselectableNode(messageNode.getParent()); 
     
    415439                 
    416440                MailboxNode selectedMailbox = dialog.getSelectedMailboxNode(); 
    417                 if(selectedMailbox != null && selectedMailbox != messageNode.getParent()) { 
    418                         selectedMailbox.appendMessage(messageNode); 
    419                         //TODO: Move To Folder should delete after append 
    420                         //This should only be executed after the append was successful 
    421                         //messageNode.deleteMessage(); 
    422                 } 
     441            if(selectedMailbox != null && selectedMailbox != messageNode.getParent()) { 
     442                selectedMailbox.moveMessageInto(messageNode); 
     443            } 
    423444        } 
    424445    } 
Note: See TracChangeset for help on using the changeset viewer.