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

📄 jwmastoreimpl.java

📁 java windows mda and reveus
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*** * jwma Java WebMail * Copyright (c) 2000-2003 jwma team * * jwma is free software; you can distribute and use this source * under the terms of the BSD-style license received along with * the distribution. ***/package dtw.webmail.model;import dtw.webmail.JwmaKernel;import dtw.webmail.JwmaSession;import dtw.webmail.util.config.PostOffice;import org.apache.log4j.Logger;import javax.mail.Folder;import javax.mail.Message;import javax.mail.MessagingException;import javax.mail.Store;import java.util.ArrayList;import java.util.Date;import java.util.Iterator;import java.util.List;/** * Class implementing a wrapper for the mail store. * Offers methods and utilities to manage the store. * * @author Dieter Wimberger * @version 0.9.7 07/02/2003 */public class JwmaStoreImpl implements JwmaStoreInfo {  //logging  private static Logger log = Logger.getLogger(JwmaStoreImpl.class);  public static final boolean c_SubscribedOnly = true;  //instance attributes & associations  private PostOffice m_PostOffice;  private JwmaSession m_Session;  private Store m_Store;  private Folder m_RootFolder;  private JwmaFolderImpl m_TrashFolder;  private Folder m_SentMailFolder;  private Folder m_DraftFolder;  private Folder m_ReadMailFolder;  private JwmaFolderImpl m_JwmaRootFolder;  private JwmaFolderImpl m_ActualFolder;  private JwmaFolderImpl m_InboxFolder;  private char m_FolderSeparator;  private JwmaFolderList m_Folders;  /**   * Constructs a <tt>JwmaStoreImpl</tt> instance.   *   * @param session the <tt>JwmaSession</tt> instance this store   *        belongs to.   * @param mstore the mail <tt>Store</tt> this instance should wrap.   */  private JwmaStoreImpl(JwmaSession session, Store mstore) {    m_Store = mstore;    m_Session = session;    m_PostOffice = session.getPostOffice();  }//JwmaStoreImpl  /*** jwma special folders **********************************/  /**   * Returns the actual folder.   *   * @return the actual folder as <tt>JwmaFolderImpl</tt>.   *   * @see dtw.webmail.model.JwmaFolderImpl   */  public JwmaFolderImpl getActualFolder() {    return m_ActualFolder;  }//getActualFolder  /**   * Sets the actual folder.   *   * @param f the actual folder as <tt>JwmaFolderImpl</tt>.   *   *   * @see dtw.webmail.model.JwmaFolderImpl.   */  private void setActualFolder(JwmaFolderImpl f) {    m_ActualFolder = f;  }//setActualFolder  /**   * Returns the <tt>JwmaInboxInfo</tt> instance that   * can  be used to retrieve information about the store's   * INBOX folder (i.e. where new messages should be arriving).   *   * @return the store's INBOX folder as <tt>JwmaInboxInfo</tt>.   *   * @see dtw.webmail.model.JwmaInboxInfo   */  public JwmaInboxInfo getInboxInfo() {    return (JwmaInboxInfo) m_InboxFolder;  }//getInboxInfo  /**   * Returns the <tt>JwmaTrashInfo</tt> instance that   * can  be used to retrieve information about the store's   * trash folder (i.e. where deleted messages end up first).   *   * @return the store's trash folder as <tt>JwmaTrashInfo</tt>.   *   * @see dtw.webmail.model.JwmaTrashInfo   */  public JwmaTrashInfo getTrashInfo()      throws JwmaException {    return ((JwmaTrashInfo) m_TrashFolder);  }//getTrashInfo  /**   * Returns the trash folder.   * <p>   * The type of this folder will be   * <tt>JwmaFolderImpl.TYPE_MESSAGE_CONTAINER</tt>.   *   * @return the trash folder as <tt>Folder</tt>.   *   * @see javax.mail.Folder   */  public Folder getTrashFolder() {    return m_TrashFolder.getFolder();  }//getTrashFolder  /**   * Sets the trash folder from a name or path   * given as <tt>String</tt>.   * <p>   * This method will check and modify the   * name as follows:   * <ol>   *   <li>name is null or an empty string:<br>   *		 <root folder path>+<folder separator>+ "trash"   *	 </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 draft folder   *        as <tt>String</tt>.   *   * @throws JwmaException if it fails to set the draft folder and   *         create a JwmaFolder instance with it.   */  public void setTrashFolder(String name)      throws JwmaException {    try {      if (name == null || name.length() == 0) {        name = m_RootFolder.getFullName() +            getFolderSeparator() + "trash";      } else if (!name.startsWith(m_RootFolder.getFullName())) {        //Note: causes this special folder to be subfolder of root always.        int lastindex = name.lastIndexOf(getFolderSeparator());        if (lastindex > 0) {          name = name.substring(lastindex, name.length());        }        name = m_RootFolder.getFullName() + getFolderSeparator() + name;      }      Folder trash = getFolder(name);      if (!trash.exists()) {        if (!trash.create(JwmaFolderImpl.TYPE_MAILBOX)) {          name = m_RootFolder.getFullName() + getFolderSeparator() + "jwma-trash";          trash = getFolder(name);          if (!trash.exists() && !trash.create(JwmaFolderImpl.TYPE_MAILBOX)) {            throw new JwmaException("jwma.store.trashfolder");          }        }        log.debug("setTrashFolder(): Created trash folder=" + name);      }      //ensure subscription      trash.setSubscribed(true);      m_Session.getPreferences().setTrashFolder(trash.getName());      m_TrashFolder = JwmaFolderImpl.createLight(trash);      //ensure always fresh counts      m_TrashFolder.setOnlineCounting(true);    } catch (MessagingException ex) {      throw new JwmaException(ex.getMessage()).setException(ex);    }  }//setDraftFolder  /**   * Returns the draft folder.   * <p>   * The type of this folder will be   * <tt>JwmaFolderImpl.TYPE_MESSAGE_CONTAINER</tt>.   *   * @return the draft folder as <tt>Folder</tt>.   *   * @see javax.mail.Folder   */  public Folder getDraftFolder() {    return m_DraftFolder;  }//getDraftFolder  /**   * Sets the draft folder.   * <p>   * The type of this folder should be   * <tt>JwmaFolderImpl.TYPE_MESSAGE_CONTAINER</tt>.   *   * @param f the draft folder as <tt>Folder</tt>.   *   * @see javax.mail.Folder   */  protected void setDraftFolder(Folder f) {    m_DraftFolder = f;  }//setDraftFolder  /**   * Sets the draft folder from a name or path   * given as <tt>String</tt>.   * <p>   * This method will check and modify the   * name as follows:   * <ol>   *   <li>name is null or an empty string:<br>   *		 <root folder path>+<folder separator>+ "draft"   *	 </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 draft folder   *        as <tt>String</tt>.   *   * @throws JwmaException if it fails to set the draft folder and   *         create a JwmaFolder instance with it.   */  public void setDraftFolder(String name)      throws JwmaException {    try {      if (name == null || name.length() == 0) {        name = m_RootFolder.getFullName() +            getFolderSeparator() + "draft";      } else if (!name.startsWith(m_RootFolder.getFullName())) {        //Note: causes this special folder to be subfolder of root always.        int lastindex = name.lastIndexOf(getFolderSeparator());        if (lastindex > 0) {          name = name.substring(lastindex, name.length());        }        name = m_RootFolder.getFullName() + getFolderSeparator() + name;      }      m_DraftFolder = getFolder(name);      if (!m_DraftFolder.exists()) {        if (!m_DraftFolder.create(JwmaFolderImpl.TYPE_MAILBOX)) {          name = m_RootFolder.getFullName() + getFolderSeparator() + "jwma-draft";          m_DraftFolder = getFolder(name);          if (!m_DraftFolder.exists() && !m_DraftFolder.create(JwmaFolderImpl.TYPE_MAILBOX)) {            throw new JwmaException("jwma.store.draftfolder");          }        }        log.debug("setDraftFolder(): Created draft folder=" + name);      }      //ensure subscription      m_DraftFolder.setSubscribed(true);      m_Session.getPreferences().setDraftFolder(m_DraftFolder.getName());    } catch (MessagingException ex) {      throw new JwmaException(ex.getMessage()).setException(ex);    }  }//setDraftFolder  /**   * Returns the sent mail archive folder.   * <p>   * The type of this folder will be   * <tt>JwmaFolderImpl.TYPE_MESSAGE_CONTAINER</tt>.   *   * @return the sent mail archive folder as <tt>Folder</tt>.   *   * @see javax.mail.Folder   */  public Folder getSentMailFolder() {    return m_SentMailFolder;  }//getSentMailFolder  /**   * Sets the sent mail archive folder.   * <p>   * The type of this folder will be   * <tt>JwmaFolderImpl.TYPE_MESSAGE_CONTAINER</tt>.   *   * @param f the sent mail archive folder as <tt>Folder</tt>.   *   * @see javax.mail.Folder   */  protected void setSentMailFolder(Folder f) {    m_SentMailFolder = f;  }//setSentMailFolder  /**   * Sets the sent mail archive folder from a name or path   * given as <tt>String</tt>.   * <p>   * This method will first check if the automatic archivation of   * sent 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 sent-mail folder and   *         create a JwmaFolder instance with it.   */  public void setSentMailFolder(String name)      throws JwmaException {    try {      if (m_Session.getPreferences().isAutoArchiveSent()) {        if (name == null || name.length() == 0) {          name = m_RootFolder.getFullName() +              getFolderSeparator() + "sent-mail";        } else if (!name.startsWith(m_RootFolder.getFullName())) {          //Note: causes this special folder to be subfolder of root always.          int lastindex = name.lastIndexOf(getFolderSeparator());          if (lastindex > 0) {            name = name.substring(lastindex, name.length());          }          name = m_RootFolder.getFullName() + getFolderSeparator() + name;        }        m_SentMailFolder = getFolder(name);        if (!m_SentMailFolder.exists()) {          boolean success = m_SentMailFolder.create(JwmaFolderImpl.TYPE_MAILBOX);          log.debug("setSentMailFolder(): Created sent-mail folder=" + name + ":" + success);        } else {          log.debug("setSentMailFolder(): Set sent-mail folder=" + name);        }        m_SentMailFolder.setSubscribed(true);        m_Session.getPreferences().setSentMailArchive(m_SentMailFolder.getName());      }    } catch (MessagingException ex) {      throw new JwmaException(ex.getMessage()).setException(ex);    }

⌨️ 快捷键说明

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