📄 accountsettings.java
字号:
} } else { //#ifdef MUJMAIL_SSL delete(4); //#endif // Protocol ports customization if (protocolType.isSelected(0)) { // pop3s->pop3 if (portOld == CONST_PORT_POPS) inboxPort.setString( Integer.toString(CONST_PORT_POP) ); } else { // imaps->imap if (portOld == CONST_PORT_IMAPS) inboxPort.setString( Integer.toString(CONST_PORT_IMAP) ); } } } // Showing and removing server mailbox names as needed if ( item == copyToServer) { int ctsIndex = -1; // CopyToServer ChoiceGroup index for ( int i = 0; i < size(); i++) if (this.get(i).getLabel().equals(Lang.get(Lang.AS_COPY_TO_SERVER))) ctsIndex = i; // remove all visible, then adds visible one ... its necessary not to change order of if (copyToSrvSentFolderNameVisible == true) { int index = -1; // CopyToServer ChoiceGroup index for ( int i = 0; i < size(); i++) if (this.get(i).getLabel().equals(Lang.get(Lang.AS_COPY_TO_SRV_SENT_MAILBOX))) index = i; delete(index); copyToSrvSentFolderNameVisible = false; } if (copyToSrvTrashFolderNameVisible == true) { int index = -1; // CopyToServer ChoiceGroup index for ( int i = 0; i < size(); i++) if (this.get(i).getLabel().equals(Lang.get(Lang.AS_COPY_TO_SRV_TRASH_MAILBOX))) index = i; delete(index); copyToSrvTrashFolderNameVisible = false; } if (copyToServer.isSelected(0)) { ctsIndex +=1; insert(ctsIndex,copyToSrvSentFolderName); copyToSrvSentFolderNameVisible = true; } if (copyToServer.isSelected(1)) { ctsIndex +=1; insert(ctsIndex,copyToSrvTrashFolderName); copyToSrvTrashFolderNameVisible = true; } } if (item == inboxServer) { if (inboxServer.getString().equalsIgnoreCase(MailAccount.CONST_GMAIL_IMAP_SERVER)) { if (copyToSrvSentFolderName.getString().equalsIgnoreCase(MailAccount.CONST_IMAP_SERVER_SENTBOX)) copyToSrvSentFolderName.setString( MailAccount.CONST_GMAIL_SENTBOX); if (copyToSrvTrashFolderName.getString().equalsIgnoreCase(MailAccount.CONST_IMAP_SERVER_TRASHBOX)) copyToSrvTrashFolderName.setString( MailAccount.CONST_GMAIL_TRASHBOX); } else { if (copyToSrvSentFolderName.getString().equalsIgnoreCase(MailAccount.CONST_GMAIL_SENTBOX)) copyToSrvSentFolderName.setString(MailAccount.CONST_IMAP_SERVER_SENTBOX); if (copyToSrvTrashFolderName.getString().equalsIgnoreCase(MailAccount.CONST_GMAIL_TRASHBOX )) copyToSrvTrashFolderName.setString(MailAccount.CONST_IMAP_SERVER_TRASHBOX ); } } } /** * @return true while loading accounts from database. */ public boolean isBusy() { return busy; } /** * A method that shows a form for editing an account * @param accountID Identification of the account */ public void showAccount(String accountID) { MailAccount account; if (accountID != null && !accountID.equals("DEFAULT_INIT")) { editting = true; account = (MailAccount) mujMail.getMailAccounts().get(accountID); } else { editting = false; account = new MailAccountPrimary( MailAccount.IMAP, "your_email@gmail.com", true, "imap.gmail.com", (short) 993, "your_email@gmail.com", "", true, (byte) 1, true, false, MailAccount.CONST_IMAP_SERVER_SENTBOX, MailAccount.CONST_IMAP_SERVER_TRASHBOX); } // clear form deleteAll(); copyToSrvSentFolderNameVisible = false; copyToSrvTrashFolderNameVisible = false; active.setSelectedIndex(0, account.isActive()); email.setString(account.getEmail()); protocolType.setSelectedIndex(account.getType(), true); SSL.setSelectedIndex(0,account.isSSL()); //#ifdef MUJMAIL_SSL sslTypeChooser.setSelectedType(account.getSSLType()); //#endif inboxServer.setString(account.getServer()); inboxPort.setString(String.valueOf(account.getPort())); inboxAuthName.setString(account.getUserName()); inboxAuthPass.setString(account.getPassword()); IMAP_boxes.setString(account.getIMAPPprimaryBox()); copyToServer.setSelectedIndex(0, account.isCopyToSrvSent()); copyToServer.setSelectedIndex(1,account.isCopyToSrvTrash()); copyToSrvSentFolderName.setString(account.getCopyToSrvSentFolderName()); copyToSrvTrashFolderName.setString(account.getCopyToSrvTrashFolderName()); // append all needed append(active); append(email); append(protocolType); append(SSL); append(inboxServer); append(inboxPort); append(inboxAuthName); append(inboxAuthPass); if (account.getType() == MailAccount.IMAP ) append(IMAP_boxes); //#ifdef MUJMAIL_SSL if (account.isSSL()) { sslTypeChooser.insertToForm(); } //#endif if (protocolType.getSelectedIndex() == 1) { append(copyToServer); if (copyToServer.isSelected(0)) { append(copyToSrvSentFolderName); copyToSrvSentFolderNameVisible = true; } if (copyToServer.isSelected(1)) { append(copyToSrvTrashFolderName); copyToSrvTrashFolderNameVisible = true; } } // init with default values mujMail.getDisplay().setCurrent(this); if (accountID != null && accountID.equals("DEFAULT_INIT")) { mujMail.alert.setAlert(this, this, Lang.get(Lang.ALRT_AS_SET_DEFAULT_ACCOUNT), MyAlert.DEFAULT, AlertType.INFO); } } /** * Connects to "ACCOUNTS" <code>RecordStore</code> and returns a count of records in it. * <p>It is used before <code>loadAccounts()</code> method is called. * * @return Account count stored in persistent database */ public int getNumAccounts() { RecordStore rs; int numAccounts = 0; try { rs = RecordStore.openRecordStore("ACCOUNTS", true); numAccounts = rs.getNumRecords(); rs.closeRecordStore(); } catch (RecordStoreException ex) { ex.printStackTrace(); } return numAccounts; } /** * This procedure serves to save new or edited Account from the form to the * <code> RecordStore </code> and refreshes the <code> Account </code> array * as well. * @param accountID name of account * @param account Account to save into database. If null content of current form is used. */ public void saveAccount(String accountID, MailAccount account) { //the following check is done only in case a new account is //created using the account form; should not be performed //for settings synchronization (account == null) condition //achieves this if (!editting && account == null && mujMail.getMailAccounts().containsKey(email.getString())) { mujMail.alert.setAlert(this, this, Lang.get(Lang.ALRT_AS_ALREADY_EXITS) + email.getString(), MyAlert.DEFAULT, AlertType.INFO); return; } /** * Initialize a new account in case Ok is pressed * in AccountSettings form (in this case account is NULL) */ if (account == null) { account = new MailAccountPrimary(); account.setActive( active.isSelected(0) ); account.setEmail( email.getString() ); account.setSSL(SSL.isSelected(0)); //#ifdef MUJMAIL_SSL account.setSSLType((byte) sslTypeChooser.getSSLTypeNumberChosen()); //#endif account.setType((byte) protocolType.getSelectedIndex()); account.setServer(inboxServer.getString()); try { account.setPort(Short.parseShort(inboxPort.getString())); } catch (Exception ex) { inboxPort.setString("110"); mujMail.alert.setAlert(this, this, Lang.get(Lang.ALRT_SAVING) + account.getEmail() + Lang.get(Lang.FAILED) + ": " + ex, MyAlert.DEFAULT, AlertType.ERROR); return; } account.setUserName(inboxAuthName.getString()); account.setPassword(inboxAuthPass.getString()); if (account.getType() == MailAccount.POP3) { account.setProtocol(new POP3(account)); } else { account.setIMAPPrimaryBox( IMAP_boxes.getString() ); account.setProtocol(new IMAP4(account)); } account.setCopyToSrvSent(copyToServer.isSelected(0)); account.setCopyToSrvTrash(copyToServer.isSelected(1)); account.setCopyToSrvSentFolderName(copyToSrvSentFolderName.getString()); account.setCopyToSrvTrashFolderName(copyToSrvTrashFolderName.getString()); } // save to RecordStore try { RecordStore rs = RecordStore.openRecordStore("ACCOUNTS", true); //this variable is used when the account is restored //through Restore settings command boolean accountExists = mujMail.getMailAccounts().containsKey(account.getEmail()); try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); DataOutputStream stream = new DataOutputStream(buffer); if (editting) { account.setRecordID( ((MailAccount) mujMail.getMailAccounts().get(accountID)).getRecordID() ); } else if (accountExists) { account.setRecordID( ((MailAccount) mujMail.getMailAccounts().get(account.getEmail())).getRecordID() ); } stream.writeByte(account.getAccountClassType()); stream.writeBoolean(account.isActive()); stream.writeUTF(account.getEmail()); stream.writeByte(account.getType()); stream.writeBoolean(account.isSSL()); //#ifdef MUJMAIL_SSL stream.writeByte(account.getSSLType());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -