Jwma

dtw.webmail.model
Class JwmaFolderImpl

java.lang.Object
  |
  +--dtw.webmail.model.JwmaFolderImpl
All Implemented Interfaces:
JwmaFolder, JwmaInboxInfo, JwmaTrashInfo

public class JwmaFolderImpl
extends java.lang.Object
implements JwmaFolder, JwmaTrashInfo, JwmaInboxInfo

Class implementing the JwmaFolder model. It also implements the JwmaTrashInfo and the JwmaInboxInfo models, because both are just simplified interfaces to a folder.

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

Field Summary
protected  JwmaMessage m_ActualMessage
           
protected  javax.mail.FetchProfile m_DraftProfile
           
protected  javax.mail.Folder m_Folder
           
protected  JwmaMessageInfoListImpl m_MessageInfoList
           
protected  java.lang.String m_Name
           
protected  boolean m_OnlineCounting
           
protected  java.lang.String m_Path
           
protected  JwmaStoreImpl m_Store
           
protected  dtw.webmail.model.JwmaFolderList m_Subfolders
           
protected  int m_Type
           
 
Fields inherited from interface dtw.webmail.model.JwmaFolder
TYPE_ALL, TYPE_FOLDER, TYPE_FOLDER_CONTAINER, TYPE_MAILBOX, TYPE_MESSAGE_CONTAINER, TYPE_MIXED
 
Method Summary
 void addIfSubfolder(JwmaFolderImpl folder)
          Adds a folder to the cached list of subfolders, if it is a subfolder of this folder.
 boolean checkMessageExistence(int number)
          Tests if a message with the given number exists in this folder.
static JwmaFolderImpl createJwmaFolderImpl(JwmaStoreImpl store, javax.mail.Folder f)
          Creates a JwmaFolderImpl instance from the given Folder.
static JwmaFolderImpl createJwmaFolderImpl(JwmaStoreImpl store, java.lang.String fullname)
          Creates a JwmaFolderImpl instance from the given Folder.
static JwmaFolderImpl createLight(javax.mail.Folder folder)
          Creates a JwmaFolderImpl instance from the given Folder.
 int deleteActualMessage()
          Deletes the actual message from this folder.
 void deleteAllMessages()
          Deletes all messages from this folder.
 void deleteMessage(int number)
          Deletes the given message from this folder.
 void deleteMessages(int[] numbers)
          Deletes the messages with the given numbers.
 boolean equals(java.lang.Object o)
          Tests if this folder instance equals a given object.
 JwmaMessage getActualMessage()
          Returns the actual message.
 JwmaMessage getDraftMessage(int num)
           
 javax.mail.Folder getFolder()
          Returns this folder's wrapped mail folder instance.
 JwmaMessage getJwmaMessage(int num)
          Returns a JwmaMessage instance that wraps the mailmessage with the given number.
 int getMessageCount()
          Returns an int representing the count of messages in the Inbox.
 JwmaMessageInfoListImpl getMessageInfoList()
          Returns the JwmaMessageInfoListImpl instance that contains a list of stored JwmaMessageInfoImpl references wrapping information about the messages in the wrapped mailfolder.
 java.lang.String getName()
          Basic info
 int getNewMessageCount()
          Returns an int representing the count of new messages in the Inbox.
 int getNextMessageNumber()
          Returns the number of the next message (relative to the actual) in this folder, observing the actual sorting.
 java.lang.String getPath()
          Returns a String representing the path of this folder object.
 int getPreviousMessageNumber()
          Returns the number of the previous message (relative to the actual) in this folder, observing the actual sorting.
 int[] getReadMessages()
          Returns the numbers of all read messages within this instance.
 int getType()
          Returns an int representing the type of this folder.
 int getUnreadMessageCount()
          Returns an int representing the count of unread messages in the Inbox.
 boolean hasMessages()
          Messages related
 boolean hasNewMessages()
          Tests if the Inbox contains new messages.
 boolean hasSubfolders()
          Tests if this folder contains subfolders.
 boolean hasUnreadMessages()
          Tests if the Inbox contains new messages, based on the flag for read messages.
 boolean isEmpty()
          Tests if the trash is empty.
 boolean isOnlineCounting()
          Tests if this folder returns an online count of the contained messages.
 boolean isSubfolder(java.lang.String folder, java.lang.String possiblesubfolder)
          Tests if a folder is a subfolder of another folder, by using their respective paths.
 boolean isSubscribed()
          Tests if this folder is subscribed.
 boolean isType(int type)
          Tests if this folder is of a given type.
 JwmaMessageInfo[] listMessageInfos()
          Returns an array of JwmaMessageInfo[] listing the info's of all messages in this folder.
 JwmaFolder[] listSubfolders()
          Convenience method that returns aJwmaFolder[] containing all subfolders within this folder.
 JwmaFolder[] listSubfolders(int type)
          Returns aJwmaFolder[] containing all subfolders of the given type within this folder.
 JwmaFolder[] listSubfolders(int type, boolean subscribed)
          Returns aJwmaFolder[] containing all subfolders of the given type within this folder, observing subscription.
 int moveActualMessage(java.lang.String destfolder)
          Moves the actual message to the given destination folder.
 void moveMessage(int number, java.lang.String destfolder)
          Moves the given message to the given destination folder.
 void moveMessages(int[] numbers, java.lang.String destfolder)
          Moves the messages with the given numbers to the given destination folder.
 void prepare()
          Prepares this folder instance.
 void removeIfSubfolder(java.lang.String path)
          Removes a folder from the cached list of subfolders, if it is a subfolder of this folder.
 void removeIfSubfolder(java.lang.String[] folders)
          Removes all folder from the cached list of subfolders, if they are a subfolder of this folder.
 void setOnlineCounting(boolean b)
          Sets the online counting flag.
 void setSubscribed(boolean b)
           
 void update(JwmaStoreImpl store)
          Updates this JwmaFolderImpl instance by setting the store instance reference and calling update().
 void writeMessagePart(javax.mail.Part part, java.io.OutputStream out)
          Writes the given message part from the given message to the given output stream.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_Store

protected JwmaStoreImpl m_Store

m_Folder

protected javax.mail.Folder m_Folder

m_Subfolders

protected dtw.webmail.model.JwmaFolderList m_Subfolders

m_MessageInfoList

protected JwmaMessageInfoListImpl m_MessageInfoList

m_Name

protected java.lang.String m_Name

m_Path

protected java.lang.String m_Path

m_Type

protected int m_Type

m_ActualMessage

protected JwmaMessage m_ActualMessage

m_OnlineCounting

protected boolean m_OnlineCounting

m_DraftProfile

protected javax.mail.FetchProfile m_DraftProfile
Method Detail

getName

public java.lang.String getName()
Basic info

Specified by:
getName in interface JwmaFolder
Returns:
the name of this folder as String.

getPath

public java.lang.String getPath()
Description copied from interface: JwmaFolder
Returns a String representing the path of this folder object.

Specified by:
getPath in interface JwmaFolder
Returns:
the path of this folder as String.

getType

public int getType()
Description copied from interface: JwmaFolder
Returns an int representing the type of this folder.

Specified by:
getType in interface JwmaFolder
Returns:
the type of this folder object as int.

isType

public boolean isType(int type)
Description copied from interface: JwmaFolder
Tests if this folder is of a given type.

Specified by:
isType in interface JwmaFolder
Returns:
true if this folder is of the given type, false otherwise.

isSubscribed

public boolean isSubscribed()
Description copied from interface: JwmaFolder
Tests if this folder is subscribed.

Specified by:
isSubscribed in interface JwmaFolder
Returns:
true if subscribed, false otherwise.

setSubscribed

public void setSubscribed(boolean b)
                   throws JwmaException
JwmaException

getFolder

public javax.mail.Folder getFolder()
Returns this folder's wrapped mail folder instance.

Returns:
wrapped instance as javax.mail.Folder.

isOnlineCounting

public boolean isOnlineCounting()
Tests if this folder returns an online count of the contained messages. Online count means that it will request the count from the JavaMail folder implementation instance, instead of returning the size of the cached list of messages.

Returns:
boolean true if online counting, false otherwise.

setOnlineCounting

public void setOnlineCounting(boolean b)
Sets the online counting flag. This will cause this folder to return the count of messages as obtained from the JavaMail folder implementation instance, instead of returning the size of the cached list of messages.


addIfSubfolder

public void addIfSubfolder(JwmaFolderImpl folder)
Adds a folder to the cached list of subfolders, if it is a subfolder of this folder.

Parameters:
folder - a JwmaFolderImpl instance.

removeIfSubfolder

public void removeIfSubfolder(java.lang.String path)
Removes a folder from the cached list of subfolders, if it is a subfolder of this folder.

Parameters:
path - a String representing the path of a folder.

removeIfSubfolder

public void removeIfSubfolder(java.lang.String[] folders)
Removes all folder from the cached list of subfolders, if they are a subfolder of this folder. This is a convenience method, it iterates over the array and calls removeIfSubfolder(String)

Parameters:
folders - a String[] containing paths of folders.
See Also:
removeIfSubfolder(String)

isSubfolder

public boolean isSubfolder(java.lang.String folder,
                           java.lang.String possiblesubfolder)
Tests if a folder is a subfolder of another folder, by using their respective paths. A folder is a subfolder if the path starts with the path of the folder it is tested against.

Parameters:
folder - path of a folder as String.
possiblesubfolder - path of a possible subfolder of the folder as String.
Returns:
boolean that is true, if possiblesubfolder is a subfolder of folder, false otherwise.

listSubfolders

public JwmaFolder[] listSubfolders(int type)
Description copied from interface: JwmaFolder
Returns aJwmaFolder[] containing all subfolders of the given type within this folder.

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

Specified by:
listSubfolders in interface JwmaFolder
Returns:
a JwmaFolder[] containing all subfolders of the given type within this folder. The array will be empty if there are none.

listSubfolders

public JwmaFolder[] listSubfolders()
Description copied from interface: JwmaFolder
Convenience method that returns aJwmaFolder[] containing all subfolders within this folder.

If this folder does not contain any subfolder, then this method returns an empty array. Otherwise it contains one JwmaFolder for each subfolder.

Specified by:
listSubfolders in interface JwmaFolder
Returns:
a JwmaFolder[] containing all subfolders of this folder. The array will be empty if there are none.

listSubfolders

public JwmaFolder[] listSubfolders(int type,
                                   boolean subscribed)
Description copied from interface: JwmaFolder
Returns aJwmaFolder[] containing all subfolders of the given type within this folder, observing subscription.

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

Specified by:
listSubfolders in interface JwmaFolder
Returns:
a JwmaFolder[] containing all subfolders of the given type within this folder. The array will be empty if there are none.

hasSubfolders

public boolean hasSubfolders()
Description copied from interface: JwmaFolder
Tests if this folder contains subfolders.

Specified by:
hasSubfolders in interface JwmaFolder
Returns:
true if this folder contains subfolders, false otherwise.

hasMessages

public boolean hasMessages()
Messages related

Specified by:
hasMessages in interface JwmaFolder
Returns:
true if this folder contains messages, false otherwise.

getNewMessageCount

public int getNewMessageCount()
Description copied from interface: JwmaInboxInfo
Returns an int representing the count of new messages in the Inbox.

Note: method returns -1 if it fails to retrieve the actual new messages count.

Specified by:
getNewMessageCount in interface JwmaInboxInfo
Returns:
the number of new messages in the Inbox.

hasNewMessages

public boolean hasNewMessages()
Description copied from interface: JwmaInboxInfo
Tests if the Inbox contains new messages.

Specified by:
hasNewMessages in interface JwmaInboxInfo
Returns:
true if the Inbox contains new messages, false otherwise.

getUnreadMessageCount

public int getUnreadMessageCount()
Description copied from interface: JwmaInboxInfo
Returns an int representing the count of unread messages in the Inbox.

This method is based on the flag for read messages It returns -1 if it fails to retrieve the actual message count.

Specified by:
getUnreadMessageCount in interface JwmaInboxInfo
Returns:
the number of unread messages in the Inbox.

hasUnreadMessages

public boolean hasUnreadMessages()
Description copied from interface: JwmaInboxInfo
Tests if the Inbox contains new messages, based on the flag for read messages.

Specified by:
hasUnreadMessages in interface JwmaInboxInfo
Returns:
true if the Inbox contains unread messages, false otherwise.

getMessageCount

public int getMessageCount()
Description copied from interface: JwmaInboxInfo
Returns an int representing the count of messages in the Inbox.

Note: method returns -1 if it fails to retrieve the actual messages count.

Specified by:
getMessageCount in interface JwmaInboxInfo
Returns:
the number of messages in this Inbox.

isEmpty

public boolean isEmpty()
Description copied from interface: JwmaTrashInfo
Tests if the trash is empty.

Specified by:
isEmpty in interface JwmaTrashInfo
Returns:
true if the trash is empty, false otherwise.

getActualMessage

public JwmaMessage getActualMessage()
Returns the actual message. The actual message is a reference to the message wrapper instance of the message that was requested last.

Returns:
the JwmaMessage instance wrapping the last requested message.

getReadMessages

public int[] getReadMessages()
                      throws JwmaException
Returns the numbers of all read messages within this instance.

Returns:
array of int's representing the message numbers of all read messages.
Throws:
JwmaException - if retrieving the numbers from the mailfolder fails.

getNextMessageNumber

public int getNextMessageNumber()
Returns the number of the next message (relative to the actual) in this folder, observing the actual sorting. The method returns -1 if the actual message is the last message in this folder.

Returns:
the number of the next message as int or -1 if the actual message is the last message in this folder.

getPreviousMessageNumber

public int getPreviousMessageNumber()
Returns the number of the previous message (relative to the actual) in this folder, observing the actual sorting. The method returns -1 if the actual message is the first message in this folder.

Returns:
the number of the previous message as int or -1 if the actual message is the first message in this folder.

checkMessageExistence

public boolean checkMessageExistence(int number)
Tests if a message with the given number exists in this folder.

Returns:
true if it exists, false otherwise.

getJwmaMessage

public JwmaMessage getJwmaMessage(int num)
                           throws JwmaException
Returns a JwmaMessage instance that wraps the mailmessage with the given number.

Parameters:
num - the number of the message to be retrieved as int.
Returns:
the JwmaMessage instance wrapping the retrieved message.
Throws:
JwmaException - if the message does not exist, or cannot be retrieved from the store.

getDraftMessage

public JwmaMessage getDraftMessage(int num)
                            throws JwmaException
JwmaException

listMessageInfos

public JwmaMessageInfo[] listMessageInfos()
Returns an array of JwmaMessageInfo[] listing the info's of all messages in this folder. The method actually delegates the job to the associated JwmaMessageInfoListImpl instance.

Specified by:
listMessageInfos in interface JwmaFolder
Returns:
an array of JwmaMessageInfo instances.
See Also:
JwmaMessageInfoListImpl.listMessageInfos()

getMessageInfoList

public JwmaMessageInfoListImpl getMessageInfoList()
Returns the JwmaMessageInfoListImpl instance that contains a list of stored JwmaMessageInfoImpl references wrapping information about the messages in the wrapped mailfolder.

Returns:
the list containing the JwmaMessageInfoImpl references.

deleteActualMessage

public int deleteActualMessage()
                        throws JwmaException
Deletes the actual message from this folder.

Returns:
the number of the next message or -1 if there is none.
Throws:
JwmaException - if it fails to delete the message from the store.

deleteMessage

public void deleteMessage(int number)
                   throws JwmaException
Deletes the given message from this folder. Note that this is a convenience method that creates an array with a single entry, and calls deleteMessage(int[]).

Parameters:
number - the number of the message to be deleted as int.
Throws:
JwmaException - if it fails to delete the given message.
See Also:
deleteMessages(int[])

deleteAllMessages

public void deleteAllMessages()
                       throws JwmaException
Deletes all messages from this folder. Note that this is a convenience method that creates an array with a all message numbers, and calls deleteMessage(int[]). *

Throws:
JwmaException - if it fails to delete any of the messages.
See Also:
deleteMessages(int[])

deleteMessages

public void deleteMessages(int[] numbers)
                    throws JwmaException
Deletes the messages with the given numbers.

Parameters:
numbers - the messages to be deleted as int[].
Throws:
JwmaException - if it fails to delete any of the given messages.

moveActualMessage

public int moveActualMessage(java.lang.String destfolder)
                      throws JwmaException
Moves the actual message to the given destination folder.

Parameters:
destfolder - the path of the destination folder as String.
Returns:
the number of the next message, or -1 if there is none.
Throws:
JwmaException - if it fails to move the message.
See Also:
moveMessage(int,String)

moveMessage

public void moveMessage(int number,
                        java.lang.String destfolder)
                 throws JwmaException
Moves the given message to the given destination folder. Note that this is actually a convenience method. It wraps the message number into an array and calls moveMessages(int[],String).

Parameters:
destfolder - the path of the destination folder as String.
Returns:
the number of the next message, or -1 if there is none.
Throws:
JwmaException - if it fails to move the message.
See Also:
moveMessages(int[],String)

moveMessages

public void moveMessages(int[] numbers,
                         java.lang.String destfolder)
                  throws JwmaException
Moves the messages with the given numbers to the given destination folder.

Parameters:
numbers - the messages to be moved as int[].
destfolder - the destination folder path as String.
Throws:
JwmaException - if it fails to move if the destination folder does not exist, or if any of the given messages cannot be moved.

writeMessagePart

public void writeMessagePart(javax.mail.Part part,
                             java.io.OutputStream out)
                      throws java.io.IOException,
                             JwmaException
Writes the given message part from the given message to the given output stream.

Parameters:
part - the part to be written to the output stream.
out - the OutputStream to be written to.
Throws:
java.io.IOException - if an I/O related error occurs.
JwmaException - if the message part does not exist, or cannot be retrieved from the message.

equals

public boolean equals(java.lang.Object o)
Tests if this folder instance equals a given object. Overrides the superclass behaviour to compare the folder's paths in case the given object is a JwmaFolderImpl.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to compare this folder with.
Returns:
true if the paths are equal, false otherwise, or when the object is not an instance of JwmaFolderImpl.

prepare

public void prepare()
             throws JwmaException
Prepares this folder instance. This method fills in values from the wrapped mailfolder instance and creates the cached subfolder list and the cached messages list.

Throws:
JwmaException - if it fails to retrieve values from the wrapped instance, or if it fails to create the subfolder list.

update

public void update(JwmaStoreImpl store)
            throws JwmaException
Updates this JwmaFolderImpl instance by setting the store instance reference and calling update(). This method can be used on a primarily lightweight created folder, to get it fully prepared for extended use.

Parameters:
store - the reference to the store this folder belongs to.
Throws:
JwmaException - if the update() method fails.
See Also:
prepare()

createJwmaFolderImpl

public static JwmaFolderImpl createJwmaFolderImpl(JwmaStoreImpl store,
                                                  javax.mail.Folder f)
                                           throws JwmaException
Creates a JwmaFolderImpl instance from the given Folder.

Parameters:
f - mail Folder this instance will "wrap".
Returns:
the newly created instance.
Throws:
JwmaException - if it fails to create the new instance.

createJwmaFolderImpl

public static JwmaFolderImpl createJwmaFolderImpl(JwmaStoreImpl store,
                                                  java.lang.String fullname)
                                           throws JwmaException
Creates a JwmaFolderImpl instance from the given Folder.

Returns:
the newly created instance.
Throws:
JwmaException - if it fails to create the new instance.

createLight

public static JwmaFolderImpl createLight(javax.mail.Folder folder)
                                  throws JwmaException
Creates a JwmaFolderImpl instance from the given Folder.

Parameters:
folder - mail Folder this instance will "wrap".
Returns:
the newly created instance.
Throws:
JwmaException - if it fails to create the new instance.

Jwma

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