Ignore:
Timestamp:
09/06/10 21:30:20 (17 months ago)
Author:
octorian
Message:

Cleanup of inappropriate getAccountConfig() calls

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

Legend:

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

    r701 r704  
    333333            else { 
    334334                accountUid = StringParser.toHexString( 
    335                                 ((NetworkAccountNode)mailboxNode.getParentAccount()).getAccountConfig().getUniqueId()).toLowerCase(); 
     335                                ((NetworkAccountNode)mailboxNode.getParentAccount()).getUniqueId()).toLowerCase(); 
    336336                mailboxUid = StringParser.toHexString( 
    337337                                mailboxNode.getUniqueId()).toLowerCase(); 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/model/MailManager.java

    r703 r704  
    212212        // for new accounts. 
    213213        NetworkAccountNode[] existingAccounts = mailRootNode.getNetworkAccounts(); 
    214         NetworkAccountNode[] newAccounts = getNewNetworkAccountNodes(existingAccounts); 
     214        NetworkAccountNode[] newAccounts = getNewNetworkAccountNodes(); 
    215215 
    216216        // Remove and replace all account nodes from the root node. 
     
    234234    } 
    235235 
    236         private NetworkAccountNode[] getNewNetworkAccountNodes(NetworkAccountNode[] existingAccounts) { 
     236        private NetworkAccountNode[] getNewNetworkAccountNodes() { 
    237237            Vector newAccounts = new Vector(); 
    238238 
    239239            int num = mailSettings.getNumAccounts(); 
    240             boolean accountExists; 
    241240            for(int i=0; i<num; i++) { 
    242241                AccountConfig accountConfig = mailSettings.getAccountConfig(i); 
    243                 accountExists = false; 
    244                 for(int j=0; j<existingAccounts.length; j++) { 
    245                     if(accountConfig == existingAccounts[j].getAccountConfig()) { 
    246                         accountExists = true; 
    247                         newAccounts.addElement(existingAccounts[j]); 
    248                         break; 
    249                     } 
     242                NetworkAccountNode existingAccountNode = mailRootNode.findAccountForConfig(accountConfig); 
     243 
     244                if(existingAccountNode != null) { 
     245                    newAccounts.addElement(existingAccountNode); 
    250246                } 
    251                 if(!accountExists) { 
     247                else { 
    252248                    AccountNode newAccountNode = new NetworkAccountNode((NetworkMailStore) MailFactory.createMailStore(accountConfig)); 
    253249                    newAccountNode.load(); 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/model/MessageNodeReader.java

    r701 r704  
    331331            NetworkAccountNode[] accounts = MailManager.getInstance().getMailRootNode().getNetworkAccounts(); 
    332332            for(int i=0; i<accounts.length; i++) { 
    333                 long accountId = accounts[i].getAccountConfig().getUniqueId(); 
     333                long accountId = accounts[i].getUniqueId(); 
    334334 
    335335                if(accountId == sendingAccountId) { 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/model/MessageNodeWriter.java

    r701 r704  
    191191                    if(outgoingMessage.getSendingAccount() != null && outgoingMessage.getSendingAccount() instanceof NetworkAccountNode) { 
    192192                        table.put(HEADER_KEY_OUTGOING_SENDING_ACCOUNT, 
    193                                 new Long(((NetworkAccountNode)outgoingMessage.getSendingAccount()).getAccountConfig().getUniqueId())); 
     193                                new Long(((NetworkAccountNode)outgoingMessage.getSendingAccount()).getUniqueId())); 
    194194                    } 
    195195                    if(outgoingMessage.getMailSender() != null && outgoingMessage.getMailSender() instanceof NetworkMailSender) { 
     
    204204                    AccountNode replyToAccount = outgoingMessage.getReplyToAccount(); 
    205205                    if(replyToAccount instanceof NetworkAccountNode) { 
    206                         table.put(HEADER_KEY_OUTGOING_REPLYTO_ACCOUNT, new Long(((NetworkAccountNode)replyToAccount).getAccountConfig().getUniqueId())); 
     206                        table.put(HEADER_KEY_OUTGOING_REPLYTO_ACCOUNT, new Long(((NetworkAccountNode)replyToAccount).getUniqueId())); 
    207207                    } 
    208208                    } 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/model/NetworkAccountNode.java

    r701 r704  
    3232 
    3333import org.logicprobe.LogicMail.conf.AccountConfig; 
     34import org.logicprobe.LogicMail.conf.IdentityConfig; 
    3435import org.logicprobe.LogicMail.mail.AbstractMailSender; 
    3536import org.logicprobe.LogicMail.mail.FolderTreeItem; 
     
    8283     
    8384    /** 
     85     * Gets the unique ID for this account. 
     86     * This is primarily intended for use as an offline reference in places 
     87     * where an object reference is not practical. 
     88     * 
     89     * @return the unique ID 
     90     */ 
     91    public long getUniqueId() { 
     92        return this.accountConfig.getUniqueId(); 
     93    } 
     94     
     95    /** 
    8496     * Gets the account configuration. 
    8597     * 
    8698     * @return The account configuration 
    8799     */ 
    88     public AccountConfig getAccountConfig() { 
     100    AccountConfig getAccountConfig() { 
    89101        return this.accountConfig; 
     102    } 
     103     
     104    /** 
     105     * Gets the identity configuration. 
     106     * If no identity configuration is available, a usable placeholder will be 
     107     * returned to prevent the result from being null. 
     108     *  
     109     * @return The identity configuration 
     110     */ 
     111    public IdentityConfig getIdentityConfig() { 
     112        IdentityConfig identityConfig = this.accountConfig.getIdentityConfig(); 
     113        if(identityConfig == null) { 
     114            identityConfig = new IdentityConfig(); 
     115            identityConfig.setEmailAddress( 
     116                    this.accountConfig.getServerUser() 
     117                    + '@' + 
     118                    this.accountConfig.getServerName()); 
     119        } 
     120        return identityConfig; 
    90121    } 
    91122     
     
    135166    public boolean hasIdentity() { 
    136167        return this.accountConfig.getIdentityConfig() != null; 
     168    } 
     169     
     170    /** 
     171     * Gets the sent message mailbox. 
     172     *  
     173     * @return The sent message mailbox 
     174     */ 
     175    public MailboxNode getSentMailbox() { 
     176        return this.accountConfig.getSentMailbox(); 
     177    } 
     178     
     179    /** 
     180     * Gets the draft message mailbox. 
     181     *  
     182     * @return The draft message mailbox 
     183     */ 
     184    public MailboxNode getDraftMailbox() { 
     185        return this.accountConfig.getDraftMailbox(); 
    137186    } 
    138187     
  • trunk/LogicMail/src/org/logicprobe/LogicMail/model/OutboxMailboxNode.java

    r701 r704  
    3838 
    3939import org.logicprobe.LogicMail.AppInfo; 
    40 import org.logicprobe.LogicMail.conf.AccountConfig; 
    4140import org.logicprobe.LogicMail.mail.AbstractMailSender; 
    4241import org.logicprobe.LogicMail.mail.AbstractMailStore; 
     
    339338            // Store to the Sent folder 
    340339            if(outgoingMessageNode.getSendingAccount() != null) { 
    341                 AccountConfig sendingAccountConfig = ((NetworkAccountNode)outgoingMessageNode.getSendingAccount()).getAccountConfig(); 
    342  
     340                NetworkAccountNode sendingAccount = (NetworkAccountNode)outgoingMessageNode.getSendingAccount(); 
     341                 
    343342                // Append to the Sent message folder, if available 
    344                 MailboxNode sentMailbox = sendingAccountConfig.getSentMailbox(); 
     343                MailboxNode sentMailbox = sendingAccount.getSentMailbox(); 
    345344                if(sentMailbox != null && sentMailbox.hasAppend()) { 
    346345                    MessageFlags initialFlags = new MessageFlags(); 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/ui/AccountConfigScreen.java

    r701 r704  
    5959import org.logicprobe.LogicMail.model.AccountNode; 
    6060import org.logicprobe.LogicMail.model.MailManager; 
     61import org.logicprobe.LogicMail.model.MailRootNode; 
    6162import org.logicprobe.LogicMail.model.MailboxNode; 
    62 import org.logicprobe.LogicMail.model.NetworkAccountNode; 
    6363 
    6464/** 
     
    450450        // Build an array containing the current account node, if it already exists, 
    451451        // and any local account nodes. 
    452         AccountNode[] accountNodes = MailManager.getInstance().getMailRootNode().getAccounts(); 
    453         Vector accountNodeVector = new Vector(); 
    454         for(int i=0; i<accountNodes.length; i++) { 
    455             if(accountNodes[i].getStatus() == AccountNode.STATUS_LOCAL || 
    456                     ((NetworkAccountNode)accountNodes[i]).getAccountConfig() == accountConfig) { 
    457                 accountNodeVector.addElement(accountNodes[i]); 
    458             } 
    459         } 
    460         accountNodes = new AccountNode[accountNodeVector.size()]; 
     452        MailRootNode mailRootNode = MailManager.getInstance().getMailRootNode(); 
     453        Vector accountNodeVector = new Vector(2); 
     454        accountNodeVector.addElement(mailRootNode.getLocalAccount()); 
     455         
     456        AccountNode currentAccountNode = mailRootNode.findAccountForConfig(accountConfig); 
     457        if(currentAccountNode != null) { 
     458            accountNodeVector.addElement(currentAccountNode); 
     459        } 
     460         
     461        AccountNode[] accountNodes = new AccountNode[accountNodeVector.size()]; 
    461462        accountNodeVector.copyInto(accountNodes); 
    462463 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/ui/CompositionScreen.java

    r702 r704  
    5656import org.logicprobe.LogicMail.AppInfo; 
    5757import org.logicprobe.LogicMail.LogicMailResource; 
    58 import org.logicprobe.LogicMail.conf.AccountConfig; 
    5958import org.logicprobe.LogicMail.conf.IdentityConfig; 
    6059import org.logicprobe.LogicMail.conf.MailSettings; 
     
    10099    private MessageNode sourceMessageNode; 
    101100    private NetworkAccountNode accountNode; 
    102     private AccountConfig accountConfig; 
    103101    private UnicodeNormalizer unicodeNormalizer; 
    104102     
     
    171169    public CompositionScreen(NetworkAccountNode accountNode) { 
    172170        this.accountNode = accountNode; 
    173         this.accountConfig = accountNode.getAccountConfig(); 
    174         this.identityConfig = accountConfig.getIdentityConfig(); 
     171        this.identityConfig = accountNode.getIdentityConfig(); 
    175172        if(MailSettings.getInstance().getGlobalConfig().getUnicodeNormalization()) { 
    176173            unicodeNormalizer = UnicodeNormalizer.getInstance(); 
     
    203200                int composeType) { 
    204201        this.accountNode = accountNode; 
    205         this.accountConfig = accountNode.getAccountConfig(); 
    206         this.identityConfig = accountConfig.getIdentityConfig(); 
     202        this.identityConfig = accountNode.getIdentityConfig(); 
    207203        if(MailSettings.getInstance().getGlobalConfig().getUnicodeNormalization()) { 
    208204            unicodeNormalizer = UnicodeNormalizer.getInstance(); 
     
    431427 
    432428                boolean shouldClose = false; 
    433                 if(accountConfig.getDraftMailbox() != null) { 
     429                if(accountNode.getDraftMailbox() != null) { 
    434430                        int choice = Dialog.ask( 
    435431                                        resources.getString(LogicMailResource.COMPOSITION_PROMPT_SAVE_OR_DISCARD), 
     
    474470            menu.add(sendMenuItem); 
    475471        } 
    476         MailboxNode draftMailbox = accountConfig.getDraftMailbox(); 
     472        MailboxNode draftMailbox = accountNode.getDraftMailbox(); 
    477473        if(draftMailbox != null 
    478474                && ((subjectEditField.getText().length() > 0) 
     
    551547     
    552548    private void saveAsDraft() { 
    553         final MailboxNode draftMailbox = accountConfig.getDraftMailbox(); 
     549        final MailboxNode draftMailbox = accountNode.getDraftMailbox(); 
    554550        final MessageEnvelope envelope = generateEnvelope(); 
    555551        generateMessage(new Runnable() { 
     
    615611        // Set the sender and reply-to addresses 
    616612        // (this comes from identity settings) 
    617         if (identityConfig != null) { 
    618             env.from = new String[1]; 
    619  
    620             String fullName = identityConfig.getFullName(); 
    621  
    622             if ((fullName != null) && (fullName.length() > 0)) { 
    623                 env.from[0] = "\"" + fullName + "\"" + " <" + 
    624                     identityConfig.getEmailAddress() + ">"; 
    625             } else { 
    626                 env.from[0] = identityConfig.getEmailAddress(); 
    627             } 
    628  
    629             String replyToAddress = identityConfig.getReplyToAddress(); 
    630  
    631             if ((replyToAddress != null) && (replyToAddress.length() > 0)) { 
    632                 env.replyTo = new String[1]; 
    633                 env.replyTo[0] = replyToAddress; 
    634             } 
     613        env.from = new String[1]; 
     614 
     615        String fullName = identityConfig.getFullName(); 
     616 
     617        if ((fullName != null) && (fullName.length() > 0)) { 
     618            env.from[0] = "\"" + fullName + "\"" + " <" + 
     619            identityConfig.getEmailAddress() + ">"; 
    635620        } else { 
    636             // There are rare situations where the IdentityConfig could be null, 
    637             // such as if the user deleted their identity configuration without 
    638             // editing their account again to force the creation of a default identity. 
    639             // Eventually this should be prevented, but for now we will just elegantly 
    640             // handle the case of missing identity information. 
    641             env.from = new String[1]; 
    642             env.from[0] = accountConfig.getServerUser() + "@" + 
    643                 accountConfig.getServerName(); 
     621            env.from[0] = identityConfig.getEmailAddress(); 
     622        } 
     623 
     624        String replyToAddress = identityConfig.getReplyToAddress(); 
     625 
     626        if ((replyToAddress != null) && (replyToAddress.length() > 0)) { 
     627            env.replyTo = new String[1]; 
     628            env.replyTo[0] = replyToAddress; 
    644629        } 
    645630 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/ui/MessageActions.java

    r701 r704  
    4141 
    4242import org.logicprobe.LogicMail.LogicMailResource; 
    43 import org.logicprobe.LogicMail.conf.AccountConfig; 
    4443import org.logicprobe.LogicMail.conf.MailSettings; 
    4544import org.logicprobe.LogicMail.conf.OutgoingConfig; 
     
    272271        for(int i=0; i<accounts.length; i++) { 
    273272            if(accounts[i].hasMailSender()) { 
    274                         AccountConfig accountConfig = accounts[i].getAccountConfig(); 
    275                         if(accountConfig.getDraftMailbox() == messageNode.getParent()) { 
     273                        if(accounts[i].getDraftMailbox() == messageNode.getParent()) { 
    276274                                matchingAccounts.addElement(accounts[i]); 
    277275                        } 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/ui/MessageScreen.java

    r701 r704  
    6969import org.logicprobe.LogicMail.AppInfo; 
    7070import org.logicprobe.LogicMail.LogicMailResource; 
    71 import org.logicprobe.LogicMail.conf.AccountConfig; 
    7271import org.logicprobe.LogicMail.conf.MailSettings; 
    7372import org.logicprobe.LogicMail.message.ContentPart; 
     
    7574import org.logicprobe.LogicMail.message.MimeMessagePart; 
    7675import org.logicprobe.LogicMail.message.MimeMessagePartTransformer; 
     76import org.logicprobe.LogicMail.model.AccountNode; 
    7777import org.logicprobe.LogicMail.model.Address; 
    7878import org.logicprobe.LogicMail.model.MailboxNode; 
     
    9999    private MenuItem compositionItem; 
    100100         
    101         private AccountConfig accountConfig; 
    102101    private MessageNode messageNode; 
     102    private AccountNode parentAccount; 
    103103    private boolean isSentFolder; 
    104104    private boolean isOutgoingWithErrors; 
     
    112112    { 
    113113        this.messageNode = messageNode; 
    114         if(messageNode.getParent().getParentAccount() instanceof NetworkAccountNode) { 
    115             this.accountConfig = ((NetworkAccountNode)messageNode.getParent().getParentAccount()).getAccountConfig(); 
    116         } 
     114        this.parentAccount = messageNode.getParent().getParentAccount(); 
    117115         
    118116        if(MailSettings.getInstance().getGlobalConfig().getUnicodeNormalization()) { 
     
    171169        if(mailboxNode != null) { 
    172170            if(mailboxNode.getType() != MailboxNode.TYPE_OUTBOX) { 
    173                 String accountText = mailboxNode.getParentAccount().toString(); 
     171                String accountText = parentAccount.toString(); 
    174172                BasicEditField accountField = new BasicEditField( 
    175173                        resources.getString(LogicMailResource.MESSAGEPROPERTIES_ACCOUNT) + ' ', 
     
    307305            compositionItem = new MenuItem(resources, LogicMailResource.MENUITEM_COMPOSE_EMAIL, 400100, 2000) { 
    308306                public void run() { 
    309                     navigationController.displayComposition((NetworkAccountNode)messageNode.getParent().getParentAccount()); 
     307                    navigationController.displayComposition((NetworkAccountNode)parentAccount); 
    310308                } 
    311309            }; 
     
    324322        messageActions.makeMenu(menu, instance, messageNode, true); 
    325323         
    326         if(accountConfig != null && accountConfig.getOutgoingConfig() != null) { 
     324        if(parentAccount instanceof NetworkAccountNode 
     325                && ((NetworkAccountNode)parentAccount).hasMailSender()) { 
    327326            menu.add(compositionItem); 
    328327        } 
     
    633632                if((context & BrowserFieldManager.ACTION_SEND_EMAIL) != 0) { 
    634633                        String address = ((BrowserFieldManager)field).getSelectedToken(); 
    635                 navigationController.displayComposition((NetworkAccountNode)messageNode.getParent().getParentAccount(), address); 
     634                navigationController.displayComposition((NetworkAccountNode)parentAccount, address); 
    636635                } 
    637636        } 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/ui/NotificationHandler.java

    r701 r704  
    3737import org.logicprobe.LogicMail.AppInfo; 
    3838import org.logicprobe.LogicMail.LogicMailEventSource; 
    39 import org.logicprobe.LogicMail.conf.AccountConfig; 
    4039import org.logicprobe.LogicMail.model.AccountNode; 
    4140import org.logicprobe.LogicMail.model.AccountNodeEvent; 
     
    181180                         
    182181                        // Register the notification source, if necessary 
    183                         AccountConfig accountConfig = ((NetworkAccountNode)accountNodes[i]).getAccountConfig(); 
    184                         LogicMailEventSource eventSource = (LogicMailEventSource)eventSourceMap.get(accountConfig.getUniqueId()); 
    185                         if(eventSource == null || !eventSource.getAccountName().equals(accountConfig.getAcctName())) { 
     182                        long accountUniqueId = ((NetworkAccountNode)accountNodes[i]).getUniqueId(); 
     183                        String accountName = accountNodes[i].toString(); 
     184                        LogicMailEventSource eventSource = (LogicMailEventSource)eventSourceMap.get(accountUniqueId); 
     185                        if(eventSource == null || !eventSource.getAccountName().equals(accountName)) { 
    186186                                eventSource = 
    187                                         new LogicMailEventSource(accountConfig.getAcctName(), accountConfig.getUniqueId()); 
     187                                        new LogicMailEventSource(accountName, accountUniqueId); 
    188188                NotificationsManager.registerSource( 
    189189                                eventSource.getEventSourceId(), 
    190190                                eventSource, 
    191191                                NotificationsConstants.CASUAL); 
    192                 eventSourceMap.put(accountConfig.getUniqueId(), eventSource); 
     192                eventSourceMap.put(accountUniqueId, eventSource); 
    193193                        } 
    194194                } 
     
    219219 
    220220                        // Unregister the notification source 
    221                         long eventSourceKey = ((NetworkAccountNode)accountNode).getAccountConfig().getUniqueId(); 
     221                        long eventSourceKey = ((NetworkAccountNode)accountNode).getUniqueId(); 
    222222                        LogicMailEventSource eventSource = (LogicMailEventSource)eventSourceMap.get(eventSourceKey); 
    223223                        if(eventSource != null) { 
     
    263263         */ 
    264264        private void notifyNewMessages(MailboxNode mailboxNode) { 
    265                 long sourceId = AppInfo.GUID + ((NetworkAccountNode)mailboxNode.getParentAccount()).getAccountConfig().getUniqueId(); 
     265                long sourceId = AppInfo.GUID + ((NetworkAccountNode)mailboxNode.getParentAccount()).getUniqueId(); 
    266266                NotificationsManager.triggerImmediateEvent(sourceId, 0, this, null); 
    267267                setAppIcon(true); 
     
    275275                while(e.hasMoreElements()) { 
    276276                        AccountNode accountNode = (AccountNode)e.nextElement(); 
    277                         long sourceId = AppInfo.GUID + ((NetworkAccountNode)accountNode).getAccountConfig().getUniqueId(); 
     277                        long sourceId = AppInfo.GUID + ((NetworkAccountNode)accountNode).getUniqueId(); 
    278278                        NotificationsManager.cancelImmediateEvent(sourceId, 0, this, null); 
    279279                } 
Note: See TracChangeset for help on using the changeset viewer.