1 17 package org.columba.mail.config; 18 19 20 import org.columba.core.config.DefaultItem; 21 import org.columba.core.xml.XmlElement; 22 import org.columba.ristretto.parser.ParserException; 23 24 public class AccountItem extends DefaultItem { 25 26 29 public static final int POP3_ACCOUNT = 0, 30 IMAP_ACCOUNT = 1, 31 UNKNOWN_TYPE = -1; 32 33 private AccountItem defaultAccount; 34 private Identity identity; 36 private PopItem pop; 37 private ImapItem imap; 38 private OutgoingItem smtp; 39 private SecurityItem pgp; 40 private SpecialFoldersItem folder; 41 private SpamItem spam; 42 43 private int accountType = UNKNOWN_TYPE; 44 45 public AccountItem(XmlElement e) { 46 super(e); 47 48 if (e.getElement("/popserver") != null) 49 { 50 accountType = POP3_ACCOUNT; 51 } 52 else if (e.getElement("/imapserver") != null) 53 { 54 accountType = IMAP_ACCOUNT; 55 } 56 else 57 accountType = UNKNOWN_TYPE; 58 59 } 60 61 67 68 public final String getAccountTypeDescription() 69 { 70 switch(accountType) 71 { 72 case POP3_ACCOUNT: 73 return "POP3"; 74 case IMAP_ACCOUNT: 75 return "IMAP"; 76 default: 77 return "UNKNOWN"; 78 } 79 } 80 81 public final int getAccountType() 82 { 83 return accountType; 84 } 85 86 public boolean isPopAccount() 87 { 88 return (accountType == POP3_ACCOUNT); 89 } 90 91 public SpecialFoldersItem getSpecialFoldersItem() { 92 if (folder == null) { 93 folder = new SpecialFoldersItem(getRoot().getElement("specialfolders")); 94 } 95 96 if (folder.getBoolean("use_default_account")) { 97 SpecialFoldersItem item = MailConfig.getInstance().getAccountList() 99 .getDefaultAccount() 100 .getSpecialFoldersItem(); 101 102 return item; 103 } 104 105 return folder; 106 } 107 108 private AccountItem getDefaultAccount() { 109 if (defaultAccount == null) { 110 defaultAccount = MailConfig.getInstance().getAccountList() 111 .getDefaultAccount(); 112 } 113 114 return defaultAccount; 115 } 116 117 public PopItem getPopItem() { 118 if (pop == null) { 119 pop = new PopItem(getRoot().getElement("popserver")); 120 } 121 122 if (pop.getBoolean("use_default_account")) { 123 PopItem item = MailConfig.getInstance().getAccountList() 125 .getDefaultAccount().getPopItem(); 126 127 return item; 128 } 129 130 return pop; 131 } 132 133 public IncomingItem getIncomingItem() { 134 if( isPopAccount() ) { 135 return getPopItem(); 136 } else { 137 return getImapItem(); 138 } 139 } 140 141 public OutgoingItem getSmtpItem() { 142 if (smtp == null) { 143 smtp = new OutgoingItem(getRoot().getElement("smtpserver")); 144 } 145 146 if (smtp.getBoolean("use_default_account")) { 147 return getDefaultAccount().getSmtpItem(); 149 } 150 151 return smtp; 152 } 153 154 public SpamItem getSpamItem() { 155 if ( spam == null) { 156 XmlElement parent = getRoot().getElement("spam"); 157 if ( parent == null) parent = getRoot().addSubElement("spam"); 159 160 spam = new SpamItem(parent); 161 } 162 163 if (spam.getBoolean("use_default_account")) { 164 return getDefaultAccount().getSpamItem(); 166 } 167 168 return spam; 169 } 170 171 public SecurityItem getPGPItem() { 172 if (pgp == null) { 173 pgp = new SecurityItem(getRoot().getElement("pgp")); 174 } 175 176 if (pgp.getBoolean("use_default_account")) { 177 SecurityItem item = MailConfig.getInstance().getAccountList() 179 .getDefaultAccount().getPGPItem(); 180 181 return item; 182 } 183 184 return pgp; 185 } 186 187 public ImapItem getImapItem() { 188 if (imap == null) { 189 imap = new ImapItem(getRoot().getElement("imapserver")); 190 } 191 192 if (imap.getBoolean("use_default_account")) { 193 ImapItem item = MailConfig.getInstance().getAccountList() 195 .getDefaultAccount() 196 .getImapItem(); 197 198 return item; 199 } 200 201 return imap; 202 } 203 204 207 public Identity getIdentity() { 208 if (identity == null) { 209 XmlElement e = getRoot().getElement("identity"); 210 if (Boolean.valueOf(e.getAttribute("use_default_account", "false")) 211 .booleanValue()) { 212 return MailConfig.getInstance().getAccountList().getDefaultAccount() 214 .getIdentity(); 215 } else { 216 try { 217 identity = new Identity(e); 218 } catch (ParserException ex) { 219 ex.printStackTrace(); 220 } 221 } 222 } 223 224 return identity; 225 } 226 227 public void setName(String str) { 228 setString("name", str); 229 } 230 231 public String getName() { 232 return get("name"); 233 } 234 235 public void setUid(int i) { 236 setInteger("uid", i); 237 } 238 239 public int getUid() { 240 return getInteger("uid"); 241 } 242 243 public boolean isDefault() { 244 if (MailConfig.getInstance().getAccountList().getDefaultAccountUid() == getUid()) { 245 return true; 246 } 247 248 return false; 249 } 250 251 252 public boolean equals(Object obj) { 253 if (this == obj) { 254 return true; } 256 257 if ((obj == null) || !(obj instanceof AccountItem)) { 258 return false; 259 } 260 261 266 return super.equals(obj); 267 } 268 269 270 public int hashCode() { 271 276 return super.hashCode(); 277 } 278 } 279 | Popular Tags |