⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jwmastoreimpl.java

📁 java windows mda and reveus
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
      if (!checkFolderExistence(destfolder)) {        throw new JwmaException(            "jwma.store.movefolder.destination.missing", true        );      }      //ensure basically valid destination      Folder dest = getFolder(destfolder);      if (!(dest.getType() == JwmaFolderImpl.TYPE_FOLDER          || dest.getType() == JwmaFolderImpl.TYPE_MIXED)) {        throw new JwmaException(            "jwma.store.movefolder.destination.foul", true        );      }      //create list that does not contain any special folder      List folders = getFolders(foldernames);      //      for (Iterator iter = folders.iterator(); iter.hasNext();) {        Folder oldfolder = (Folder) iter.next();        Folder newfolder = getFolder(            destfolder + getFolderSeparator() + oldfolder.getName()        );        if (newfolder.exists()) {          throw new JwmaException(              "jwma.store.movefolder.destination.exists", true              //" (@ "+              //newfolder.getFullName()+              //")"          );        }        //move but ensure a parent is not moved into        // one of its childs        if (!newfolder.getFullName().regionMatches(            0, oldfolder.getFullName(),            0, oldfolder.getFullName().length())) {          //UW does not change subscriptions on moving!          if (oldfolder.isSubscribed()) {            oldfolder.setSubscribed(false);          }          oldfolder.renameTo(newfolder);          newfolder.setSubscribed(true);        } else {          throw new JwmaException(              "jwma.store.movefolder.destination.subfolder", true          );        }      }      //update the cached list      m_Folders.rebuild();      m_ActualFolder.removeIfSubfolder(foldernames);    } catch (MessagingException mex) {      throw new JwmaException(          "jwma.store.movefolder.failed", true      ).setException(mex);    }  }//moveFolders  public void updateFolderSubscription(String[] foldernames, boolean subscribe)      throws JwmaException {    //create list that does not contain any special folder    try {      List folders = getFolders(foldernames);      for (Iterator iter = folders.iterator(); iter.hasNext();) {        ((Folder) iter.next()).setSubscribed(subscribe);      }    } catch (Exception ex) {      log.error("updateFolderSubscription()", ex);      throw new JwmaException("jwma.store.updatesubscription.failed"          , true).setException(ex);    }  }//updateFolderSubscription  public void unsubscribeFolders() {  }//unsubscribeFolders  /**   * An utility method that collects all non special   * folders of a given array of folder paths, into   * a list of jvax.mail.Folder instances.   */  private List getFolders(String[] foldernames)      throws MessagingException, JwmaException {    ArrayList folders = new ArrayList(foldernames.length);    Folder f = null;    for (int i = 0; i < foldernames.length; i++) {      f = getFolder(foldernames[i]);      //add if existant and NOT the trash folder      if (f.exists() && !isSpecialFolder(foldernames[i])) {        folders.add(f);      }    }    return folders;  }//getFolders  /**   * Tests if a given path is a special jwma folder.   */  private boolean isSpecialFolder(String fullname) {    return (        fullname.equals(m_RootFolder.getFullName())        || fullname.equals(m_InboxFolder.getPath())        || fullname.equals(m_TrashFolder.getPath())        || fullname.equals(m_DraftFolder.getFullName())        || (m_Session.getPreferences().isAutoArchiveSent() &&        fullname.equals(m_SentMailFolder.getFullName()))        || (m_Session.getPreferences().isAutoMoveRead() &&        fullname.equals(m_ReadMailFolder.getFullName()))        );  }//isSpecialFolder  /*** end folder management methods *************************/  /*** Storeinfo implementation **********************************/  public JwmaFolder[] listFolders(int type) {    return m_Folders.createFolderArray(m_Folders.sublist(type, c_SubscribedOnly));  }//listFolders  public JwmaFolder[] listFolders(int type, boolean subscribed) {    String[] excludes = {      m_RootFolder.getFullName(),      m_InboxFolder.getPath(),      m_TrashFolder.getPath(),      m_DraftFolder.getFullName(),      ((m_Session.getPreferences().isAutoArchiveSent())? m_SentMailFolder.getFullName():""),      ((m_Session.getPreferences().isAutoMoveRead())? m_ReadMailFolder.getFullName():"")    };    return m_Folders.createFolderArray(m_Folders.sublist(type, excludes, subscribed));  }//listFolders  public JwmaFolder[] listFolderMoveTargets() {    //sublist with actual folder filtered    return m_Folders.createFolderArray(        m_Folders.sublist(JwmaFolder.TYPE_FOLDER_CONTAINER, m_ActualFolder, c_SubscribedOnly)    );  }//listFolderMoveTargets  public JwmaFolder[] listMessageMoveTargets() {    //sublist with actual folder filtered    return m_Folders.createFolderArray(        m_Folders.sublist(JwmaFolder.TYPE_MESSAGE_CONTAINER, m_ActualFolder, c_SubscribedOnly)    );  }//listMessageMoveTargets  /*** End display methods ***********************************/  /*** Utility methods ***************************************/  /**   * Returns a reference to the associated preferences.   *   * @return the associated preferences <tt>JwmaPreferences</tt>.   *   * @see dtw.webmail.model.JwmaPreferences   */  public JwmaPreferences getPreferences() {    return (JwmaPreferences) m_Session.getPreferences();  }//getPreferences  /**   * Tests if the store is mixed mode, which means it can   * hold folders that hold messages and subfolders at once.   *   * @return true if store is supporting mixed mode, false   *         otherwise.   */  public boolean isMixedMode() {    return m_PostOffice.isType(PostOffice.TYPE_MIXED);  }//isMixedMode  public char getFolderSeparator() {    return m_FolderSeparator;  }//getFolderSeparator  /**   * Sets the folder separator character.   *   * @param the folder separator as <tt>char</tt>.   */  protected void setFolderSeparator(char c) {    m_FolderSeparator = c;  }//setFolderSeparator  /**   * Cleans up the store.   * <p>   * This method performs some of the do-automatic functions   * within jwma:   * <ol>   *   <li>Move read messages from the inbox to the read messages folder,   *     if the feature is enabled.   *	 </li>   *	 <li>Empty the trashbin.</li>   * </ol>   *   * @throws JwmaException if cleanup routines fail to perform error free.   */  public boolean cleanup() throws JwmaException {    //perform auto features like set in users prefs    JwmaPreferencesImpl prefs = m_Session.getPreferences();    //1. automove read from Inbox to readmessagesfolder if set    if (prefs.isAutoMoveRead()) {      //move the read messages      m_InboxFolder.moveMessages(          m_InboxFolder.getReadMessages(),          m_ReadMailFolder.getFullName()      );    }    //2. autoempty trash if set    if (prefs.isAutoEmpty()) {      m_TrashFolder.update(this);      m_TrashFolder.deleteAllMessages();      return (m_TrashFolder.getMessageCount() != 0);    }    return true;  }//cleanup  /**   * Closes the associated mail store.   */  public void close() {    try {      //close store      m_Store.close();    } catch (MessagingException mex) {      log.error(JwmaKernel.getReference().getLogMessage("jwma.store.closefailed"), mex);    }  }//close  /**   * Prepares all special folders.   */  public void prepare()      throws JwmaException {    log.debug("prepare()");    try {      JwmaPreferencesImpl prefs = m_Session.getPreferences();      //if empty or null string, set store default      //folder as root      if (prefs.getRootFolder() == null || prefs.getRootFolder().equals("")) {        m_RootFolder = m_Store.getDefaultFolder();      } else {        m_RootFolder = m_Store.getFolder(prefs.getRootFolder());        if (!m_RootFolder.exists()) {          m_RootFolder = m_Store.getDefaultFolder();        }      }      //ensure the root folder exists      if (!m_RootFolder.exists()) {        throw new JwmaException("jwma.store.rootfolder");      } else {        prefs.setRootFolder(m_RootFolder.getFullName());        log.debug("Prepare set root folder to:" + prefs.getRootFolder());      }      //set folder separator      setFolderSeparator(m_RootFolder.getSeparator());      //build folder list      m_Folders = JwmaFolderList.createStoreList(m_RootFolder);      //buildFolderList(m_RootFolder.list());      //Inbox the folder that contains the incoming mail      //this has to exist, regarding to the IMAP specification      m_InboxFolder = getJwmaFolder("INBOX");      //ensure always fresh counts      m_InboxFolder.setOnlineCounting(true);      //Trash      setTrashFolder(prefs.getTrashFolder());      //Draft      setDraftFolder(prefs.getDraftFolder());      //read-mail archive      setReadMailFolder(prefs.getReadMailArchive());      //sent-mail archive      setSentMailFolder(prefs.getSentMailArchive());      //store JwmaFolderImpl of root as last, to set the actual folder      //to root      m_JwmaRootFolder = getJwmaFolder(m_RootFolder.getFullName());    } catch (MessagingException ex) {      log.debug("prepare()", ex);      throw new JwmaException(          "jwma.store.prepare"      ).setException(ex);    }  }//prepare  /**   * Tests if a folder with the given path exists   * on the store.   * <p>   * Note that the method checks against the cached folder list.   *   * @param path the path of the folder as <tt>String</tt>.   *   * @return true if a folder with this path exists on the store,   *         false otherwise.   *   * @throws  JwmaException if the folder already exists, or if it fails   *			to create the folder.   *   */  public boolean checkFolderExistence(String path)      throws JwmaException {    if (path.equals(m_RootFolder.getFullName())        || path.equals("INBOX")) {      return true;    }    return m_Folders.contains(path);  }//checkFolderExistence  /**   * Creates a new <tt>JwmaStoreImpl</tt> instance.   * <p>   * The method will also prepare the store for use.   *   * @param session the actual <tt>JwmaSession</tt>.   * @param mstore the mail store that should be wrapped.   *   * @return the newly created <tt>JwmaStoreImpl</tt> instance.   *   * @throws JwmaException if preparing the store for use fails.   *   * @see #prepare()   * @see dtw.webmail.JwmaSession   * @see javax.mail.Store   */  public static JwmaStoreImpl createJwmaStoreImpl(JwmaSession session, Store mstore)      throws JwmaException {    JwmaStoreImpl store = new JwmaStoreImpl(session, mstore);    //prepare this store    store.prepare();    return store;  }//createJwmaStoreImpl}//JwmaStoreImpl

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -