001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016:
017: package org.columba.mail.gui.config.accountwizard;
018:
019: import net.javaprog.ui.wizard.DataModel;
020: import net.javaprog.ui.wizard.WizardModelEvent;
021: import net.javaprog.ui.wizard.WizardModelListener;
022:
023: import org.columba.mail.config.AccountItem;
024: import org.columba.mail.config.ImapItem;
025: import org.columba.mail.config.MailConfig;
026: import org.columba.mail.config.PopItem;
027: import org.columba.mail.folder.FolderCreationException;
028: import org.columba.mail.folder.FolderFactory;
029: import org.columba.mail.folder.IMailFolder;
030: import org.columba.mail.folder.imap.IMAPRootFolder;
031: import org.columba.mail.gui.tree.FolderTreeModel;
032: import org.columba.mail.gui.util.WelcomeMessage;
033: import org.columba.mail.mailchecking.MailCheckingManager;
034: import org.columba.mail.pop3.POP3ServerCollection;
035: import org.columba.ristretto.message.Address;
036:
037: class AccountCreator implements WizardModelListener {
038: protected DataModel data;
039:
040: public AccountCreator(DataModel data) {
041: this .data = data;
042: }
043:
044: public void wizardFinished(WizardModelEvent e) {
045: String type = (String) data.getData("IncomingServer.type");
046: AccountItem account = MailConfig.getInstance().getAccountList()
047: .addEmptyAccount(type.toLowerCase());
048:
049: if (account == null) {
050: // this should not happen, the templates seem to be missing
051: throw new RuntimeException("Account templates missing!");
052: }
053:
054: account.setName((String) data.getData("Identity.accountName"));
055: account.getIdentity().setAddress(
056: (Address) data.getData("Identity.address"));
057:
058: IMailFolder folder = null;
059: if (type.equals("POP3")) {
060: PopItem pop = account.getPopItem();
061: pop.setString("host", (String) data
062: .getData("IncomingServer.host"));
063: pop.setString("user", (String) data
064: .getData("IncomingServer.login"));
065: POP3ServerCollection.getInstance().add(account);
066:
067: folder = FolderTreeModel.getInstance().getFolder("101");
068: } else {
069: ImapItem imap = account.getImapItem();
070: imap.setString("host", (String) data
071: .getData("IncomingServer.host"));
072: imap.setString("user", (String) data
073: .getData("IncomingServer.login"));
074:
075: // TODO (@author fdietz): All this code for creating a new
076: // IMAPRootFolder should
077: // be moved to a FolderFactory
078: // -> this way "path" would be handled in the factory, too
079: // parent directory for mail folders
080: // for example: ".columba/mail/"
081: // String path =
082: // MailConfig.getInstance().getConfigDirectory().getPath();
083:
084: try {
085: // IMAPRootFolder parentFolder = FolderFactory.getInstance()
086: // .createIMAPRootFolder(account);
087: // IMailFolder inbox = FolderFactory.getInstance()
088: // .createIMAPFolder(parentFolder, "INBOX");
089:
090: IMailFolder inbox = FolderFactory.getInstance()
091: .createIMAPRootFolder(account);
092: folder = inbox;
093: } catch (FolderCreationException e1) {
094: e1.printStackTrace();
095: }
096:
097: // try {
098: // IMAPRootFolder parentFolder = new IMAPRootFolder(account, path);
099: // ((IMailFolder)
100: // FolderTreeModel.getInstance().getRoot()).add(parentFolder);
101: // ((IMailFolder) FolderTreeModel.getInstance().getRoot())
102: // .getConfiguration().getRoot().addElement(
103: // parentFolder.getConfiguration().getRoot());
104: //
105: // IMailFolder inbox = new IMAPFolder("INBOX", "IMAPFolder",
106: // path);
107: // parentFolder.add(inbox);
108: // parentFolder.getConfiguration().getRoot().addElement(
109: // inbox.getConfiguration().getRoot());
110: // folder = inbox;
111: // } catch (Exception e1) {
112: // // TODO Auto-generated catch block
113: // e1.printStackTrace();
114: // }
115:
116: }
117:
118: // add welcome message to new account inbox
119: try {
120: Address adr = (Address) data.getData("Identity.address");
121: WelcomeMessage.addWelcomeMessage(folder, adr.toString(),
122: new Integer(account.getUid()).toString());
123: } catch (Exception e1) {
124: e1.printStackTrace();
125: }
126:
127: // add account to mail-checking manager
128: MailCheckingManager.getInstance().add(account);
129:
130: // notify all observers
131: MailCheckingManager.getInstance().update();
132:
133: account.getSmtpItem().setString("host",
134: (String) data.getData("OutgoingServer.host"));
135:
136: // generally we can just use the same login for both servers
137: account.getSmtpItem().setString("user",
138: (String) data.getData("IncomingServer.login"));
139: }
140:
141: public void stepShown(WizardModelEvent e) {
142: }
143:
144: public void wizardCanceled(WizardModelEvent e) {
145: }
146:
147: public void wizardModelChanged(WizardModelEvent e) {
148: }
149: }
|