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

📄 jwmastoreimpl.java

📁 java windows mda and reveus
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
  }//setSentMailFolder  /**   * Returns the read mail archive folder.   * <p>   * The type of this folder will be   * <tt>JwmaFolderImpl.TYPE_MESSAGE_CONTAINER</tt>.   *   * @return the read mail archive folder as <tt>JwmaFolderImpl</tt>.   * @see dtw.webmail.model.JwmaFolderImpl   */  public Folder getReadMailFolder() {    return m_ReadMailFolder;  }//getReadMailFolder  /**   * Sets the read mail archive folder.   * <p>   * The type of this folder will be   * <tt>JwmaFolderImpl.TYPE_MESSAGE_CONTAINER</tt>.   *   * @param f the read mail archive folder as <tt>Folder</tt>.   *   * @see javax.mail.Folder   */  protected void setReadMailFolder(Folder f) {    m_ReadMailFolder = f;  }//setReadMailFolder  /**   * Sets the read mail archive folder from a name or path   * given as <tt>String</tt>.   * <p>   * This method will first check if the automatic archivation of   * read messages is activated. If, then it checks and modifies the   * name as follows:   * <ol>   *   <li>name is null or an empty string:<br>   *		 <root folder path>+<folder separator>+ "sent-mail"   *	 </li>   *	 <li>name does not start with <root folder path>:<br>   *       <root folder path>+<folder separator>+name   *   </li>   * </ol>   * The method will finally set the newly created folder name in the   * associated preferences.   *   * @param name the name or full name of the sent-mail archive folder   *        as <tt>String</tt>.   *   * @throws JwmaException if it fails to set the read-mail folder and   *         create a JwmaFolder instance with it.   */  public void setReadMailFolder(String name)      throws JwmaException {    try {      if (m_Session.getPreferences().isAutoMoveRead()) {        if (name == null || name.length() == 0) {          name = m_RootFolder.getFullName() +              getFolderSeparator() + "read-mail";        } else if (!name.startsWith(m_RootFolder.getFullName())) {          int lastindex = name.lastIndexOf(getFolderSeparator());          if (lastindex > 0) {            name = name.substring(lastindex, name.length());          } //Note: causes this special folder to be subfolder of root always.          name = m_RootFolder.getFullName() + getFolderSeparator() + name;        }        m_ReadMailFolder = getFolder(name);        if (!m_ReadMailFolder.exists()) {          boolean success = m_ReadMailFolder.create(JwmaFolderImpl.TYPE_MAILBOX);          log.debug("setReadMailFolder(): Created read-mail folder=" + name + ":" + success);        }        m_ReadMailFolder.setSubscribed(true);        m_Session.getPreferences().setReadMailArchive(m_ReadMailFolder.getName());      }    } catch (MessagingException ex) {      throw new JwmaException(ex.getMessage()).setException(ex);    }  }//setReadMailFolder  /**   * Updates the root folder, if the path differs   * from the actual root folder path.   *   * @param path the path of the new root folder as <tt>String</tt>.   */  public void updateRootFolder(String path)      throws JwmaException {    if (!m_RootFolder.getFullName().equals(path)) {      m_Session.getPreferences().setRootFolder(path);      prepare();    }  }//updateRootFolder  /**   * Put's a message into the read-mail archive,   * if archivation is enabled.   *   * @param message the <tt>Message</tt> to be archived.   *   * @throws JwmaException if it fails to archive the message.   *   * @see javax.mail.Message   */  public void archiveSentMail(Message message)      throws JwmaException {    if (m_Session.getPreferences().isAutoArchiveSent()) {      Folder archive = null;      try {        //Set the sent date        message.setSentDate(new Date());        //get the folder        archive = getSentMailFolder();        //open it read write        archive.open(Folder.READ_WRITE);        //save the message in archive, append only works as array        Message[] tosave = {message};        //append it        archive.appendMessages(tosave);        //close without expunging        archive.close(false);      } catch (MessagingException mex) {        try {          if (archive.isOpen()) {            archive.close(false);          }        } catch (Exception unex) {          //ignore, will be closed anyway        }      }    }  }//archiveSentMail  /*** end jwma special folders ******************************/  /*** folder management methods *****************************/  /**   * Resets the actual folder to the root folder.   *   * @return the prepared root folder as <tt>JwmaFolder</tt>.   */  public JwmaFolder resetToRootFolder()      throws JwmaException {    //set as actual    setActualFolder(m_JwmaRootFolder);    m_JwmaRootFolder.update(this);    //return reference    return m_JwmaRootFolder;  }//resetToRootFolder  /**   * Sets a new actual folder from a given path.   *   * @return the new actual folder as <tt>JwmaFolder</tt>.   *   * @throws JwmaException if it fails to set the new folder and   *         create a JwmaFolder instance with it.   */  public JwmaFolder setActualFolder(String path)      throws JwmaException {    setActualFolder(JwmaFolderImpl        .createJwmaFolderImpl(this, getFolder(path)));    return getActualFolder();  }//setActualFolder  /**   * Returns a <tt>JwmaFolderImpl</tt> with the given path   * from the store.   *   * @return the folder as <tt>JwmaFolderImpl</tt> and set as actual   *         folder(!).   *   * @throws JwmaException if a folder with the given path does not exist   *         or an error occurs when creating the wrapper instance.   */  private JwmaFolderImpl getJwmaFolder(String fullname)      throws JwmaException {    setActualFolder(JwmaFolderImpl        .createJwmaFolderImpl(this, getFolder(fullname)));    return getActualFolder();  }//getJwmaFolder  /**   * Returns a <tt>Folder</tt> with a given path   * from the mail store.   *   * @return the folder as <tt>Folder</tt>.   *   * @throws JwmaException if a folder with the given path does not exist   *         on the store or a MessagingException occurs.   */  public Folder getFolder(String fullname)      throws JwmaException {    try {      //FIXME: Microsoft Exchange returns "" as Default Folder, but asking for the      //folder "" does not return any subfolders.      if (fullname.length() != 0) {        return m_Store.getFolder(fullname);      } else {        //assume to return the default folder...        return m_Store.getDefaultFolder();      }    } catch (MessagingException mex) {      throw new JwmaException(          "jwma.store.getfolder", true      ).setException(mex);    }  }//getFolder  /**   * Creates a new folder on the store.   *   * @throws JwmaException if the folder already exists, or if it fails   *         to create the folder.   */  public void createFolder(String fullname, int type)      throws JwmaException {    try {      //relative name to path      if (fullname.indexOf(getFolderSeparator()) == -1) {        //In case of the root folder being "" this can represent a problem        //The MS Exchange does not take /fullname as valid...        if (m_ActualFolder.getPath().length() > 0) {          fullname = m_ActualFolder.getPath() + getFolderSeparator() + fullname;        }      }      Folder newfolder = getFolder(fullname);      if (newfolder.exists()) {        throw new JwmaException(            "jwma.store.createfolder.exists", true        );      } else {        newfolder.create(type);        //ensure new folder is subscribed        newfolder.setSubscribed(true);        //update store list & subfolder list        JwmaFolderImpl folder = JwmaFolderImpl.createLight(newfolder);        m_Folders.addFolderToList(folder);        m_ActualFolder.addIfSubfolder(folder);      }    } catch (MessagingException mex) {      throw new JwmaException(          "jwma.store.createfolder.failed", true      ).setException(mex);    }  }//createFolder  /**   * Deletes the given folders from the store.   * <p>   * Note that this method will not remove any special folder from   * the store. Despite that, it is a convenience method, looping over   * the array and calling <tt>deleteFolder()</tt>   *   * @param folders an array of strings; each <tt>String</tt>   *        representing the full path of a valid folder of the   *        actual store.   *   * @throws JwmaException if a folder does not exist,   *         or if an error occurs when deleting.   *   * @see #deleteFolder(String)   */  public void deleteFolders(String[] folders)      throws JwmaException {    for (int i = 0; i < folders.length; i++) {      deleteFolder(folders[i]);    }  }//deleteFolders  /**   * Deletes a given folders from the store.   * <p>   * Note that this method will not remove the folder if it is a   * special folder.   *   * @param fullname the folder's path as <tt>String</tt>.   *   * @throws JwmaException if a folder does not exist,   *         or if an error occurs when deleting.   */  public void deleteFolder(String fullname)      throws JwmaException {    try {      Folder delfolder = getFolder(fullname);      //ensure not to delete jwma special folders      if (isSpecialFolder(fullname)) {        throw new JwmaException(            "jwma.store.deletefolder.systemfolder", true        );      } else {        //UW does not update subscriptions        delfolder.setSubscribed(false);        delfolder.delete(true);        //update cached store list        m_Folders.removeFolderFromList(fullname);        m_ActualFolder.removeIfSubfolder(fullname);      }    } catch (MessagingException mex) {      throw new JwmaException(          "jwma.store.deletefolder.failed", true      ).setException(mex);    }  }//deleteFolder  /**   * Moves the given folder on the store.   * <p>   * Note that this method is a convenience method   * it creates a single entry array and calls   * <tt>moveFolders()</tt>.   *   * @param foldername the full path of the folder as <tt>String</tt>.   * @param destfolder the full path of a valid folder on the   *        actual store.   *   * @throws JwmaException if a folder does not exist,   *         or if an error occurs when deleting.   *   * @see #moveFolders(String[],String)   */  public void moveFolder(String foldername, String destfolder)      throws JwmaException {    String[] folders = {foldername};    moveFolders(folders, destfolder);  }//moveFolder  /**   * Moves the given folders to the given destination folder.   *   * @param foldernames an array of strings; each <tt>String</tt>   *        representing the full path of a valid folder of the   *        actual store.   * @param destfolder the full path of a valid folder of the   *        actual store.   *   * @return the new actual folder as <tt>JwmaFolder</tt>.   *   * @throws JwmaException if the source folders or the destination folder   *         do not exist, the destination is a subfolder of a source folder,   *         the destination cannot contain any subfolders,   *         or if an error occurs when moving.   */  public void moveFolders(String[] foldernames, String destfolder)      throws JwmaException {    try {      //ensure existing destination folder

⌨️ 快捷键说明

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