📄 accountsettings.java
字号:
//#endif stream.writeUTF(account.getServer()); stream.writeShort(account.getPort()); stream.writeUTF(account.getUserName()); stream.writeUTF(account.getPassword()); if (account.getType() == MailAccount.IMAP) { stream.writeUTF(account.getIMAPPprimaryBox()); } stream.writeBoolean(account.isCopyToSrvSent()); stream.writeBoolean(account.isCopyToSrvTrash()); stream.writeUTF(account.getCopyToSrvSentFolderName()); stream.writeUTF(account.getCopyToSrvTrashFolderName()); stream.flush(); /*for now we dont use setRecord as it seems buggy if (editting) { rs.setRecord(account.recordID, buffer.toByteArray(), 0, buffer.size()); //even the accountID (email) was changed, remove the old one to update the new AccoundID mujMail.mailAccounts.remove(accountID); } else account.recordID = rs.addRecord(buffer.toByteArray(), 0, buffer.size()); */ int oldIndex = account.getRecordID(); account.setRecordID( rs.addRecord(buffer.toByteArray(), 0, buffer.size()) ); //Delete the existing record if the saving is //done from account form or from Sync class if (editting || accountExists) { rs.deleteRecord(oldIndex); //even the accountID (email) was changed, remove the old one to update the new AccoundID mujMail.getMailAccounts().remove(accountID); } mujMail.getMailAccounts().put(account.getEmail(), account); //change settings primary email account if necessary if (account.isActive() && !mujMail.getMailAccounts().containsKey(Settings.primaryEmail)) { Settings.primaryEmail = account.getEmail(); mujMail.getSettings().saveSettings(true); } else if (!account.isActive() && Settings.primaryEmail.equals(account.getEmail())) { Settings.primaryEmail = Settings.notSetPE; mujMail.getSettings().saveSettings(true); } // Active account list may be changed. Update Inbox retrieve account list mujMail.getInBox().actualizeActiveAccountList(); stream.close(); buffer.close(); } catch (Exception ex) { mujMail.alert.setAlert(this, this, Lang.get(Lang.ALRT_SAVING) + account.getEmail() + Lang.get(Lang.FAILED) + " " + ex, MyAlert.DEFAULT, AlertType.ERROR); } rs.closeRecordStore(); mujMail.mainMenu(); } catch (Exception ex) { mujMail.alert.setAlert(this, this, Lang.get(Lang.ALRT_SAVING) + account.getEmail() + Lang.get(Lang.FAILED) + " " + ex, MyAlert.DEFAULT, AlertType.ERROR); } } /** * Removes specified mail account from persistent <code>RecordStore</code> accounts database. * * @param accountID Account to remove * @param sure if false shows alert */ public void deleteAccount(String accountID, boolean sure) { if (!sure) { mujMail.alert.setAlert(this,mujMail.getMenu(), Lang.get(Lang.ALRT_SYS_DEL_CONFIRM) + accountID + "?", MyAlert.DEL_CONFIRM, AlertType.CONFIRMATION); return; } try { RecordStore rs = RecordStore.openRecordStore("ACCOUNTS", true); try { rs.deleteRecord(((MailAccount) mujMail.getMailAccounts().get(accountID)).getRecordID()); mujMail.getMailAccounts().remove(accountID); //if this account was primary account, reset primary account to default if (Settings.primaryEmail.equals(accountID)) { Settings.primaryEmail = Settings.notSetPE; mujMail.getSettings().saveSettings(true); } } catch (Exception ex) { mujMail.alert.setAlert(this, this, Lang.get(Lang.ALRT_DELETING) + accountID + Lang.get(Lang.FAILED) + " " + ex, MyAlert.DEFAULT, AlertType.ERROR); } rs.closeRecordStore(); } catch (Exception rse) { mujMail.alert.setAlert(this, this, Lang.get(Lang.ALRT_DELETING) + accountID + Lang.get(Lang.FAILED) + " " + rse, MyAlert.DEFAULT, AlertType.ERROR); } // refresh menu mujMail.mainMenu(); } /** * Removes all mail accounts from persistent <code>RecordStore</code> database. * * @param sure if false shows alert */ public void deleteAll(boolean sure) { if (!sure) { mujMail.alert.setAlert(this, null, Lang.get(Lang.ALRT_SYS_DEL_ALL_CONFIRM), MyAlert.DB_CLEAR_CONFIRM, AlertType.CONFIRMATION); return; } try { RecordStore.deleteRecordStore("ACCOUNTS"); } catch (Exception ex) { mujMail.alert.setAlert(this, null, Lang.get(Lang.ALRT_AD_DELETE) + Lang.get(Lang.FAILED) + " " + ex, MyAlert.DEFAULT, AlertType.ERROR); return; } Settings.primaryEmail = Settings.notSetPE; mujMail.getMailAccounts().clear(); mujMail.mainMenu(); } /** * Starts loading of account from persisten database. * * <p>Note: Loading of mail is done in separate thread. * <p>Note: */ public void loadAccounts() { accountsLoaded = false; Thread t = new Thread(this); t.start(); t.setPriority(Thread.MAX_PRIORITY); } /** * Load accounts in background. * Note: Used by {@link #loadAccounts()} */ public void run() { busy = true; try { // First run create primary mail accounts, second Derived accounts RecordStore rs = RecordStore.openRecordStore("ACCOUNTS", true); int id, sizeOfRecord; byte[] data = new byte[70]; try { if (DEBUG) System.out.println("DEBUG AccountSettings.run() - loading accounts"); RecordEnumeration en = rs.enumerateRecords(null, null, false); DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(data)); while (en.hasNextElement()) { try { id = en.nextRecordId(); sizeOfRecord = rs.getRecordSize(id); if (sizeOfRecord > data.length) { data = new byte[sizeOfRecord + 30]; inputStream = new DataInputStream(new ByteArrayInputStream(data)); } rs.getRecord(id, data, 0); inputStream.reset(); inputStream.readByte(); // Only primary accounts now MailAccount account = new MailAccountPrimary(); account.setRecordID( id ); account.setActive( inputStream.readBoolean() ); account.setEmail( inputStream.readUTF() ); account.setType( inputStream.readByte() ); account.setSSL(inputStream.readBoolean()); //#ifdef MUJMAIL_SSL account.setSSLType(inputStream.readByte()); //#endif account.setServer(inputStream.readUTF()); account.setPort(inputStream.readShort()); account.setUserName(inputStream.readUTF()); account.setPassword(inputStream.readUTF()); if (account.getType() == MailAccount.POP3) { account.setProtocol(new POP3(account)); } else { account.setIMAPPrimaryBox( inputStream.readUTF() ); account.setProtocol(new IMAP4(account)); } account.setCopyToSrvSent(inputStream.readBoolean()); account.setCopyToSrvTrash(inputStream.readBoolean()); account.setCopyToSrvSentFolderName(inputStream.readUTF()); account.setCopyToSrvTrashFolderName(inputStream.readUTF()); mujMail.getMailAccounts().put(account.getEmail(), account); } catch (Exception ex) { if (DEBUG) { System.out.println("Loading account failed"); System.out.println(ex); ex.printStackTrace(); } //try another one } } // end While inputStream.close(); } catch (Exception ex) { if (DEBUG) { ex.printStackTrace(); } mujMail.alert.setAlert(this, this, Lang.get(Lang.ALRT_AS_LOAD) + Lang.get(Lang.FAILED) + ": " + ex, MyAlert.DEFAULT, AlertType.ERROR); } catch (Error er) { if (DEBUG) { er.printStackTrace(); } mujMail.alert.setAlert(this, this, Lang.get(Lang.ALRT_AS_LOAD) + Lang.get(Lang.FAILED) + ": " + er, MyAlert.DEFAULT, AlertType.ERROR); } data = null; if (DEBUG) System.out.println("DEBUG AccountSettings.run() - loading accounts..successfull"); SMTP.getSMTPSingleton(mujMail).initAccount(); //now accounts should be ready? rs.closeRecordStore(); } catch (Exception ex) { if (DEBUG) { ex.printStackTrace(); } mujMail.alert.setAlert(this, this, Lang.get(Lang.ALRT_AS_LOAD) + Lang.get(Lang.FAILED) + ": " + ex, MyAlert.DEFAULT, AlertType.ERROR); } busy = false; if (DEBUG) { System.out.println("DEBUG AccountSettings.run() ... account successfully loaded"); } // Set accounts to be retrieved by inbox mujMail.getInBox().actualizeActiveAccountList(); synchronized(notifier) { accountsLoaded = true; notifier.notifyAll(); } } /** * Blocks and wait all accounts are loaded. * * <p>Note: Return immediately if all accounts were loaded before calling of this method. */ public void waitForAccountsLoading() { if (DEBUG) { System.out.println("DEBUG AccountSettings.waitForAccountsLoading .. in"); } try { synchronized(notifier) { if (accountsLoaded) return; notifier.wait(); } } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(); } if (DEBUG) { System.out.println("DEBUG AccountSettings.waitForAccountsLoading .. out"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -