Jwma

dtw.webmail.model
Class JwmaStoreImpl

java.lang.Object
  |
  +--dtw.webmail.model.JwmaStoreImpl
All Implemented Interfaces:
JwmaStoreInfo

public class JwmaStoreImpl
extends java.lang.Object
implements JwmaStoreInfo

Class implementing a wrapper for the mail store. Offers methods and utilities to manage the store.

Version:
0.9.7 07/02/2003
Author:
Dieter Wimberger

Field Summary
static boolean c_SubscribedOnly
           
 
Method Summary
 void archiveSentMail(javax.mail.Message message)
          Put's a message into the read-mail archive, if archivation is enabled.
 boolean checkFolderExistence(java.lang.String path)
          Tests if a folder with the given path exists on the store.
 boolean cleanup()
          Cleans up the store.
 void close()
          Closes the associated mail store.
 void createFolder(java.lang.String fullname, int type)
          Creates a new folder on the store.
static JwmaStoreImpl createJwmaStoreImpl(JwmaSession session, javax.mail.Store mstore)
          Creates a new JwmaStoreImpl instance.
 void deleteFolder(java.lang.String fullname)
          Deletes a given folders from the store.
 void deleteFolders(java.lang.String[] folders)
          Deletes the given folders from the store.
 JwmaFolderImpl getActualFolder()
          Returns the actual folder.
 javax.mail.Folder getDraftFolder()
          Returns the draft folder.
 javax.mail.Folder getFolder(java.lang.String fullname)
          Returns a Folder with a given path from the mail store.
 char getFolderSeparator()
          Returns the folder separator in use as char.
 JwmaInboxInfo getInboxInfo()
          Returns the JwmaInboxInfo instance that can be used to retrieve information about the store's INBOX folder (i.e.
 JwmaPreferences getPreferences()
          Returns a reference to the associated preferences.
 javax.mail.Folder getReadMailFolder()
          Returns the read mail archive folder.
 javax.mail.Folder getSentMailFolder()
          Returns the sent mail archive folder.
 javax.mail.Folder getTrashFolder()
          Returns the trash folder.
 JwmaTrashInfo getTrashInfo()
          Returns the JwmaTrashInfo instance that can be used to retrieve information about the store's trash folder (i.e.
 boolean isMixedMode()
          Tests if the store is mixed mode, which means it can hold folders that hold messages and subfolders at once.
 JwmaFolder[] listFolderMoveTargets()
          Returns a JwmaFolder[] containing all folders of the store, that can hold folders, excluding this folder.
 JwmaFolder[] listFolders(int type)
          Storeinfo implementation
 JwmaFolder[] listFolders(int type, boolean subscribed)
          Returns a JwmaFolder[] containing all folders on the store of a given type.
 JwmaFolder[] listMessageMoveTargets()
          Returns a JwmaFolder[] containing all folders of the store, that can hold messages, excluding this folder.
 void moveFolder(java.lang.String foldername, java.lang.String destfolder)
          Moves the given folder on the store.
 void moveFolders(java.lang.String[] foldernames, java.lang.String destfolder)
          Moves the given folders to the given destination folder.
 void prepare()
          Prepares all special folders.
 JwmaFolder resetToRootFolder()
          Resets the actual folder to the root folder.
 JwmaFolder setActualFolder(java.lang.String path)
          Sets a new actual folder from a given path.
protected  void setDraftFolder(javax.mail.Folder f)
          Sets the draft folder.
 void setDraftFolder(java.lang.String name)
          Sets the draft folder from a name or path given as String.
protected  void setFolderSeparator(char c)
          Sets the folder separator character.
protected  void setReadMailFolder(javax.mail.Folder f)
          Sets the read mail archive folder.
 void setReadMailFolder(java.lang.String name)
          Sets the read mail archive folder from a name or path given as String.
protected  void setSentMailFolder(javax.mail.Folder f)
          Sets the sent mail archive folder.
 void setSentMailFolder(java.lang.String name)
          Sets the sent mail archive folder from a name or path given as String.
 void setTrashFolder(java.lang.String name)
          Sets the trash folder from a name or path given as String.
 void unsubscribeFolders()
           
 void updateFolderSubscription(java.lang.String[] foldernames, boolean subscribe)
           
 void updateRootFolder(java.lang.String path)
          Updates the root folder, if the path differs from the actual root folder path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

c_SubscribedOnly

public static final boolean c_SubscribedOnly
See Also:
Constant Field Values
Method Detail

getActualFolder

public JwmaFolderImpl getActualFolder()
Returns the actual folder.

Returns:
the actual folder as JwmaFolderImpl.
See Also:
JwmaFolderImpl

getInboxInfo

public JwmaInboxInfo getInboxInfo()
Returns the JwmaInboxInfo instance that can be used to retrieve information about the store's INBOX folder (i.e. where new messages should be arriving).

Returns:
the store's INBOX folder as JwmaInboxInfo.
See Also:
JwmaInboxInfo

getTrashInfo

public JwmaTrashInfo getTrashInfo()
                           throws JwmaException
Returns the JwmaTrashInfo instance that can be used to retrieve information about the store's trash folder (i.e. where deleted messages end up first).

Returns:
the store's trash folder as JwmaTrashInfo.
JwmaException
See Also:
JwmaTrashInfo

getTrashFolder

public javax.mail.Folder getTrashFolder()
Returns the trash folder.

The type of this folder will be JwmaFolderImpl.TYPE_MESSAGE_CONTAINER.

Returns:
the trash folder as Folder.
See Also:
Folder

setTrashFolder

public void setTrashFolder(java.lang.String name)
                    throws JwmaException
Sets the trash folder from a name or path given as String.

This method will check and modify the name as follows:

  1. name is null or an empty string:
    ++ "trash"
  2. name does not start with :
    ++name
The method will finally set the newly created folder name in the associated preferences.

Parameters:
name - the name or full name of the draft folder as String.
Throws:
JwmaException - if it fails to set the draft folder and create a JwmaFolder instance with it.

getDraftFolder

public javax.mail.Folder getDraftFolder()
Returns the draft folder.

The type of this folder will be JwmaFolderImpl.TYPE_MESSAGE_CONTAINER.

Returns:
the draft folder as Folder.
See Also:
Folder

setDraftFolder

protected void setDraftFolder(javax.mail.Folder f)
Sets the draft folder.

The type of this folder should be JwmaFolderImpl.TYPE_MESSAGE_CONTAINER.

Parameters:
f - the draft folder as Folder.
See Also:
Folder

setDraftFolder

public void setDraftFolder(java.lang.String name)
                    throws JwmaException
Sets the draft folder from a name or path given as String.

This method will check and modify the name as follows:

  1. name is null or an empty string:
    ++ "draft"
  2. name does not start with :
    ++name
The method will finally set the newly created folder name in the associated preferences.

Parameters:
name - the name or full name of the draft folder as String.
Throws:
JwmaException - if it fails to set the draft folder and create a JwmaFolder instance with it.

getSentMailFolder

public javax.mail.Folder getSentMailFolder()
Returns the sent mail archive folder.

The type of this folder will be JwmaFolderImpl.TYPE_MESSAGE_CONTAINER.

Returns:
the sent mail archive folder as Folder.
See Also:
Folder

setSentMailFolder

protected void setSentMailFolder(javax.mail.Folder f)
Sets the sent mail archive folder.

The type of this folder will be JwmaFolderImpl.TYPE_MESSAGE_CONTAINER.

Parameters:
f - the sent mail archive folder as Folder.
See Also:
Folder

setSentMailFolder

public void setSentMailFolder(java.lang.String name)
                       throws JwmaException
Sets the sent mail archive folder from a name or path given as String.

This method will first check if the automatic archivation of sent messages is activated. If, then it checks and modifies the name as follows:

  1. name is null or an empty string:
    ++ "sent-mail"
  2. name does not start with :
    ++name
The method will finally set the newly created folder name in the associated preferences.

Parameters:
name - the name or full name of the sent-mail archive folder as String.
Throws:
JwmaException - if it fails to set the sent-mail folder and create a JwmaFolder instance with it.

getReadMailFolder

public javax.mail.Folder getReadMailFolder()
Returns the read mail archive folder.

The type of this folder will be JwmaFolderImpl.TYPE_MESSAGE_CONTAINER.

Returns:
the read mail archive folder as JwmaFolderImpl.
See Also:
JwmaFolderImpl

setReadMailFolder

protected void setReadMailFolder(javax.mail.Folder f)
Sets the read mail archive folder.

The type of this folder will be JwmaFolderImpl.TYPE_MESSAGE_CONTAINER.

Parameters:
f - the read mail archive folder as Folder.
See Also:
Folder

setReadMailFolder

public void setReadMailFolder(java.lang.String name)
                       throws JwmaException
Sets the read mail archive folder from a name or path given as String.

This method will first check if the automatic archivation of read messages is activated. If, then it checks and modifies the name as follows:

  1. name is null or an empty string:
    ++ "sent-mail"
  2. name does not start with :
    ++name
The method will finally set the newly created folder name in the associated preferences.

Parameters:
name - the name or full name of the sent-mail archive folder as String.
Throws:
JwmaException - if it fails to set the read-mail folder and create a JwmaFolder instance with it.

updateRootFolder

public void updateRootFolder(java.lang.String path)
                      throws JwmaException
Updates the root folder, if the path differs from the actual root folder path.

Parameters:
path - the path of the new root folder as String.
JwmaException

archiveSentMail

public void archiveSentMail(javax.mail.Message message)
                     throws JwmaException
Put's a message into the read-mail archive, if archivation is enabled.

Parameters:
message - the Message to be archived.
Throws:
JwmaException - if it fails to archive the message.
See Also:
Message

resetToRootFolder

public JwmaFolder resetToRootFolder()
                             throws JwmaException
Resets the actual folder to the root folder.

Returns:
the prepared root folder as JwmaFolder.
JwmaException

setActualFolder

public JwmaFolder setActualFolder(java.lang.String path)
                           throws JwmaException
Sets a new actual folder from a given path.

Returns:
the new actual folder as JwmaFolder.
Throws:
JwmaException - if it fails to set the new folder and create a JwmaFolder instance with it.

getFolder

public javax.mail.Folder getFolder(java.lang.String fullname)
                            throws JwmaException
Returns a Folder with a given path from the mail store.

Returns:
the folder as Folder.
Throws:
JwmaException - if a folder with the given path does not exist on the store or a MessagingException occurs.

createFolder

public void createFolder(java.lang.String fullname,
                         int type)
                  throws JwmaException
Creates a new folder on the store.

Throws:
JwmaException - if the folder already exists, or if it fails to create the folder.

deleteFolders

public void deleteFolders(java.lang.String[] folders)
                   throws JwmaException
Deletes the given folders from the store.

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 deleteFolder()

Parameters:
folders - an array of strings; each String 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 Also:
deleteFolder(String)

deleteFolder

public void deleteFolder(java.lang.String fullname)
                  throws JwmaException
Deletes a given folders from the store.

Note that this method will not remove the folder if it is a special folder.

Parameters:
fullname - the folder's path as String.
Throws:
JwmaException - if a folder does not exist, or if an error occurs when deleting.

moveFolder

public void moveFolder(java.lang.String foldername,
                       java.lang.String destfolder)
                throws JwmaException
Moves the given folder on the store.

Note that this method is a convenience method it creates a single entry array and calls moveFolders().

Parameters:
foldername - the full path of the folder as String.
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 Also:
moveFolders(String[],String)

moveFolders

public void moveFolders(java.lang.String[] foldernames,
                        java.lang.String destfolder)
                 throws JwmaException
Moves the given folders to the given destination folder.

Parameters:
foldernames - an array of strings; each String representing the full path of a valid folder of the actual store.
destfolder - the full path of a valid folder of the actual store.
Returns:
the new actual folder as JwmaFolder.
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.

updateFolderSubscription

public void updateFolderSubscription(java.lang.String[] foldernames,
                                     boolean subscribe)
                              throws JwmaException
JwmaException

unsubscribeFolders

public void unsubscribeFolders()

listFolders

public JwmaFolder[] listFolders(int type)
Storeinfo implementation

Specified by:
listFolders in interface JwmaStoreInfo
Returns:
a JwmaFolder[] naming all folders of given type on the store. The array will be empty if there are no such folders.
See Also:
JwmaFolder

listFolders

public JwmaFolder[] listFolders(int type,
                                boolean subscribed)
Description copied from interface: JwmaStoreInfo
Returns a JwmaFolder[] containing all folders on the store of a given type. Note that this method will observe subscription if the passed in parameter is true.

If the store does not contain any folders of the given type, then this method returns an empty array. Otherwise it contains one JwmaFolder for each folder on the store of the given type.

Specified by:
listFolders in interface JwmaStoreInfo
Parameters:
type - the type of folder as int.
subscribed - true if observe subscription, false otherwise.
Returns:
a JwmaFolder[] naming all folders of given type on the store. The array will be empty if there are no such folders.
See Also:
JwmaFolder

listFolderMoveTargets

public JwmaFolder[] listFolderMoveTargets()
Description copied from interface: JwmaStoreInfo
Returns a JwmaFolder[] containing all folders of the store, that can hold folders, excluding this folder.

If the store does not contain any folders, then this method returns an empty array (which means something is wrong!;). Otherwise it contains one JwmaFolder for each folder on the store, excluding this folder.

Specified by:
listFolderMoveTargets in interface JwmaStoreInfo
Returns:
a JwmaFolder[] containing all folders in the store that can hold folders, excluding this one. The array will be empty if there are no such folders.
See Also:
JwmaFolder

listMessageMoveTargets

public JwmaFolder[] listMessageMoveTargets()
Description copied from interface: JwmaStoreInfo
Returns a JwmaFolder[] containing all folders of the store, that can hold messages, excluding this folder.

If the store does not contain any folders, then this method returns an empty array (which means something is wrong!;). Otherwise it contains one JwmaFolder for each folder on the store, excluding this folder.

Specified by:
listMessageMoveTargets in interface JwmaStoreInfo
Returns:
a JwmaFolder[] containing all folders in the store that can hold messages, excluding this one. The array will be empty if there are no such folders.
See Also:
JwmaFolder

getPreferences

public JwmaPreferences getPreferences()
Returns a reference to the associated preferences.

Returns:
the associated preferences JwmaPreferences.
See Also:
JwmaPreferences

isMixedMode

public boolean isMixedMode()
Tests if the store is mixed mode, which means it can hold folders that hold messages and subfolders at once.

Specified by:
isMixedMode in interface JwmaStoreInfo
Returns:
true if store is supporting mixed mode, false otherwise.

getFolderSeparator

public char getFolderSeparator()
Description copied from interface: JwmaStoreInfo
Returns the folder separator in use as char.

Specified by:
getFolderSeparator in interface JwmaStoreInfo
Returns:
the folder separator character.

setFolderSeparator

protected void setFolderSeparator(char c)
Sets the folder separator character.


cleanup

public boolean cleanup()
                throws JwmaException
Cleans up the store.

This method performs some of the do-automatic functions within jwma:

  1. Move read messages from the inbox to the read messages folder, if the feature is enabled.
  2. Empty the trashbin.

Throws:
JwmaException - if cleanup routines fail to perform error free.

close

public void close()
Closes the associated mail store.


prepare

public void prepare()
             throws JwmaException
Prepares all special folders.

JwmaException

checkFolderExistence

public boolean checkFolderExistence(java.lang.String path)
                             throws JwmaException
Tests if a folder with the given path exists on the store.

Note that the method checks against the cached folder list.

Parameters:
path - the path of the folder as String.
Returns:
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.

createJwmaStoreImpl

public static JwmaStoreImpl createJwmaStoreImpl(JwmaSession session,
                                                javax.mail.Store mstore)
                                         throws JwmaException
Creates a new JwmaStoreImpl instance.

The method will also prepare the store for use.

Parameters:
session - the actual JwmaSession.
mstore - the mail store that should be wrapped.
Returns:
the newly created JwmaStoreImpl instance.
Throws:
JwmaException - if preparing the store for use fails.
See Also:
prepare(), JwmaSession, Store

Jwma

Copyright © 2000-2003 jwma team (All Rights Reserved.)