📄 boxlist.java
字号:
try { // Delete user boxes ((PersistentBox)mailBoxes.elementAt(i)).deleteAllMailsFromBoxAndDB(true); } catch (Exception ex) { exception = true; if (DEBUG) { System.out.println("DEBUG BoxList.deleteAllUserBoxes - exception " + ex); ex.printStackTrace(); } } } // for cycle if (exception) { mujMail.alert.setAlert(this, null, Lang.get(Lang.EXP_DB_CANNOT_DEL_HEADER), MyAlert.DEFAULT, AlertType.ERROR); } } /** * Shows edit form for user mail box. * Allows setting user folder properties like name of retrieved accounts. * * @param index Index of mailbox in {@link #mailBoxes} vector */ public void editUserMailBoxSettings(int index) { if (index < 0 || index >= mailBoxes.size()) { if (DEBUG) { System.out.println("DEBUG BoxList.editUserMailBoxSettings(int) - unknown MailBox" + index); } return; } InBox box = (InBox)mailBoxes.elementAt(index); // This shows new edit form UserMailBoxEditForm editForm = new UserMailBoxEditForm(box); } /** * Edits or adds information about user box in persisten database * * @param recordID if -1 adding new box into database, otherwise position of database record to edit * @param newBoxFolderName Data to by stored in db. User box folder name. * @param newBoxDBName Data to by stored in db. User box database name (prefix). * @return recordID where adding (update take place) * @throws mujmail.MyException If stroring failed, not existing database, not existing record, not enoght space * Note: recordID can be retrieve from inbox by calling {@link InBox#getUserBoxListDBRecID()} */ protected synchronized int changeStoredUserBoxInfo(int recordID, String newBoxFolderName, String newBoxDBName) throws MyException { if (DEBUG) { System.out.println("BoxList.changeStoredUserBoxInfo( recordID=" + recordID + ", newBoxFolderName=" + newBoxFolderName + ", newBoxDBName=" + newBoxDBName + ")"); } ByteArrayOutputStream buffer = new ByteArrayOutputStream(); DataOutputStream stream = new DataOutputStream(buffer); RecordStore rs = null; try { stream.writeUTF(newBoxFolderName); stream.writeUTF(newBoxDBName); stream.flush(); stream.close(); rs = Functions.openRecordStore(dbName, true); // Adding new db entry of editting existing if (recordID == -1) { recordID = rs.addRecord(buffer.toByteArray(), 0, buffer.size()); } else { rs.setRecord(recordID, buffer.toByteArray(), 0, buffer.size()); } } catch (Exception ex) { if (DEBUG) { System.out.println("BoxList.changeStoredUserBoxInfo(...) exception"); ex.printStackTrace(); } if (rs != null) Functions.closeRecordStore(rs); throw new MyException(MyException.DB_CANNOT_SAVE, newBoxFolderName); } finally { if (rs != null) Functions.closeRecordStore(rs); } return recordID; } /** * Remove mailbox from system. * Remove all it's databases, remove from runtime user mailbox lists. * * @param index Index of mailbox to remove in {@link #mailBoxes} vector */ public synchronized void removeUserMailBox(int index) { // Ensure that removing mailbox managed by this instance if (index < 0 || index >= mailBoxes.size()) { if (DEBUG) { System.out.println("DEBUG BoxList.removeUserMailBox(InBox) - unknown MailBox"); } return; } InBox toRemove = (InBox)mailBoxes.elementAt(index); // Remove mailBox databases toRemove.removeAllDBs(); // Remove from runtime representation mailBoxes.removeElementAt(index); // Remove from presistent database "MailBoxesList" try { RecordStore rs = RecordStore.openRecordStore(dbName, true); rs.deleteRecord( toRemove.getUserBoxListDBRecID()); rs.closeRecordStore(); } catch (Exception ex) { if (DEBUG) { System.out.println("DEBUG - BoxList.removeUserMailBox " + toRemove + " removing from DB failed"); ex.printStackTrace(); } mujMail.getAlert().setAlert(this, null, Lang.get(Lang.ALRT_DELETING) + Lang.get(Lang.FAILED), MyAlert.DEFAULT, AlertType.ERROR); } sort(); } /** * Check if given box retrieves specified account and return proof. * <p> * It takes care about deriving accounts. So if exist derieved account * (to given) if return derived as proof. * * @param box Box whose accounts check * @param ma Mail account to check * @return null if not retrieved, proofing primary or derived account */ static private MailAccount retrievesBoxAccount(InBox box, MailAccount ma) { // Check all accounts if direct case or indirect derived case for(Enumeration e = box.getAccounts().elements(); e.hasMoreElements();) { MailAccount boxAcc = (MailAccount)e.nextElement(); if ( ma == boxAcc) { return boxAcc; } else if (boxAcc instanceof MailAccountDerived && ((MailAccountDerived)boxAcc).getSourceAccount() == ma) { return boxAcc; // Derived account } } return null; // not found } /** Class that represents edit form for user mailboxes */ private class UserMailBoxEditForm extends Form implements CommandListener{ private Command ok; private TextField userBoxName; /** Box that we are edditting */ private InBox editedBox; /** Choice group with account list */ private ChoiceGroup accountSelector; /** Holds string for users */ private StringItem imapFolderString; /** Holds count of accounts shown in chice box */ private int accountsShown; /** Windows that was shown before this form and * that will be restored after end of mailbox settings. */ private Displayable previousScreen; /** * Create and show form for setting user mail box properties. * After saving changes return to original screen. * @param ib Box that we are editting */ public UserMailBoxEditForm(InBox ib) { //super( (create?Lang.get(Lang.ABT_ABOUT):Lang.get(Lang.ABT_ABOUT)) ); super("Folder settings"); editedBox = ib; ok = new Command("OK", Command.OK, 0); addCommand(ok); // Entry for folder name userBoxName = new TextField(Lang.get(Lang.TB_FOLDER_NAME), ib.getName(), 64, TextField.ANY); accountSelector = new ChoiceGroup(Lang.get(Lang.TB_RETRIVE_ACCOUNTS), Choice.MULTIPLE); imapFolderString = new StringItem(Lang.get(Lang.TB_IMAP_FOLDERS), null); setCommandListener(this); // Wait until all accounts are loaded mujMail.getAccountSettings().waitForAccountsLoading(); append(userBoxName); append(accountSelector); boolean anyIMAPAccount = false; // Mark if any Imap account found // Counts primary accounts for(Enumeration e = mujMail.getMailAccounts().elements(); e.hasMoreElements();) { MailAccount ma = (MailAccount)e.nextElement(); accountsShown++; int pos = accountSelector.append(ma.getEmail(), null); // Check if current user box uses this account for retrieve mails (and check it) MailAccount retAc = retrievesBoxAccount(ib, ma); if (retAc != null) { accountSelector.setSelectedIndex(pos, true); } else { retAc = ma; } if (retAc.isIMAP()) { if (!anyIMAPAccount) { append(imapFolderString); } // add textbox for imap folder settings append( new TextField( ma.getEmail(), retAc.getIMAPPprimaryBox(), 1000, TextField.ANY)); anyIMAPAccount = true; } } // store original windows and show this form MujMail.MyDisplay disp = mujMail.getDisplay(); previousScreen = disp.getCurrent(); disp.setCurrent(this); } /** Pernamently saves new setting of user folder into databases */ void updateUserBoxSettings() { try { // A) update name editedBox.setName(userBoxName.getString()); // Store new name into database changeStoredUserBoxInfo( editedBox.getUserBoxListDBRecID(), userBoxName.getString(), editedBox.getDBFileName()); //TODO Wait to time when editedBox not busy ... no retrieve task take place // Change accounts to be retrieved Vector /*<MailAccount>*/ accounts = new Vector/*<MailAccount>*/(); boolean[] flags = new boolean[accountsShown]; accountSelector.getSelectedFlags(flags); Hashtable accList = mujMail.getMailAccounts(); for(int i = 0; i < accountsShown; i++) { if (flags[i]) { // selected account MailAccount ma = (MailAccount)accList.get(accountSelector.getString(i)); if (ma.isIMAP()) { // retrieve folder strings // Iterate over form elements and found text with imap folders for this (ma) account String imapFolders = "INBOX"; for( int i1 = 3; i1 < size(); i1++) { Item item = this.get(i1); if ((item instanceof TextField) && ((TextField)item).getLabel().equals(ma.getEmail())) { imapFolders = ((TextField)item).getString(); } } MailAccount newMa = new MailAccountDerived(ma, imapFolders); accounts.addElement(newMa); } else { // POP3 accounts.addElement(ma); } } } editedBox.saveBoxRetrieveAccounts(accounts); } catch (Exception ex) { if (BoxList.DEBUG) { System.out.println("DEBUG BoxList.updateUserBoxSettings - exception"); ex.printStackTrace(); } mujMail.alert.setAlert(this, null, Lang.get(Lang.ALRT_SAVING) + Lang.get(Lang.FAILED) + ": " + ex, MyAlert.DEFAULT, AlertType.ERROR); } Functions.sort(mailBoxes, new MailBoxNameComparator()); // Show menu and update databases in background mujMail.getMenu().refresh(Menu.FOLDERS, false); } public void commandAction(Command c, Displayable d) { if (BoxList.DEBUG) { System.out.println("DEBUG BoxList.UserMailBoxEditForm.commandAction(command=" + c + ", Displayable=" + d + ")"); } if (c == ok) { updateUserBoxSettings(); mujMail.getDisplay().setCurrent(previousScreen); } } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -