gnu.mail.providers.imap

Class IMAPFolder

Implemented Interfaces:
UIDFolder

public class IMAPFolder
extends Folder
implements UIDFolder

The folder class implementing the IMAP4rev1 mail protocol.

Nested Class Summary

Field Summary

protected char
delimiter
protected int
messageCount
protected int
newMessageCount
protected String
path
The folder path.
protected Flags
permanentFlags
protected boolean
subscribed
protected int
type
The type of this folder(HOLDS_MESSAGES or HOLDS_FOLDERS).
protected long
uidValidity

Fields inherited from class javax.mail.Folder

HOLDS_FOLDERS, HOLDS_MESSAGES, READ_ONLY, READ_WRITE, mode, store

Fields inherited from interface javax.mail.UIDFolder

LASTUID

Constructor Summary

IMAPFolder(Store store, String path)
Constructor.
IMAPFolder(Store store, String path, char delimiter)
Constructor.
IMAPFolder(Store store, String path, int type, char delimiter)
Constructor.

Method Summary

void
appendMessages(Message[] messages)
Appends the specified set of messages to this folder.
void
close(boolean expunge)
Closes this folder.
boolean
create(int type)
Create this folder.
boolean
delete(boolean flag)
Delete this folder.
boolean
equals(Object other)
boolean
exists()
Indicates whether this folder exists.
Message[]
expunge()
Expunges this folder.
void
fetch(Message[] messages, FetchProfile fp)
IMAP fetch routine.
Folder
getFolder(String name)
Returns a subfolder with the specified name.
String
getFullName()
Returns the full path of this folder.
Message
getMessage(int msgnum)
Returns the specified message number from this folder.
Message
getMessageByUID(long uid)
Get the Message corresponding to the given UID.
int
getMessageCount()
Returns the number of messages in this folder.
Message[]
getMessagesByUID(long start, long end)
Get the Messages specified by the given range.
Message[]
getMessagesByUID(long[] uids)
Get the Messages specified by the given array of UIDs.
String
getName()
Returns the name of this folder.
int
getNewMessageCount()
Returns the number of new messages in this folder.
Folder
getParent()
Returns the parent folder of this folder.
Flags
getPermanentFlags()
Returns the permanent flags for this folder.
Quota[]
getQuota()
Returns the quotas for this folder.
char
getSeparator()
Returns the path separator charcter.
int
getType()
Returns the type of this folder.
long
getUID(Message message)
Get the UID for the specified message.
long
getUIDValidity()
Returns the UIDValidity value associated with this folder.
boolean
hasNewMessages()
Indicates whether this folder contains new messages.
boolean
isOpen()
Indicates whether this folder is open.
boolean
isSubscribed()
Returns true if this Folder is subscribed.
Folder[]
list(String pattern)
Returns the subfolders for this folder.
Folder[]
listSubscribed(String pattern)
Returns the subscribed subfolders for this folder.
void
open(int mode)
Opens this folder.
boolean
renameTo(Folder folder)
Rename this folder.
Message[]
search(SearchTerm term)
IMAP search function.
Message[]
search(SearchTerm term, Message[] msgs)
IMAP search function.
void
setSubscribed(boolean flag)
Subscribe or unsubscribe this Folder.

Methods inherited from class javax.mail.Folder

addConnectionListener, addFolderListener, addMessageChangedListener, addMessageCountListener, appendMessages, close, copyMessages, create, delete, exists, expunge, fetch, getDeletedMessageCount, getFolder, getFullName, getMessage, getMessageCount, getMessages, getMessages, getMessages, getMode, getName, getNewMessageCount, getParent, getPermanentFlags, getSeparator, getStore, getType, getURLName, getUnreadMessageCount, hasNewMessages, isOpen, isSubscribed, list, list, listSubscribed, listSubscribed, notifyConnectionListeners, notifyFolderListeners, notifyFolderRenamedListeners, notifyMessageAddedListeners, notifyMessageChangedListeners, notifyMessageRemovedListeners, open, removeConnectionListener, removeFolderListener, removeMessageChangedListener, removeMessageCountListener, renameTo, search, search, setFlags, setFlags, setFlags, setSubscribed, toString

Field Details

delimiter

protected char delimiter


messageCount

protected int messageCount


newMessageCount

protected int newMessageCount


path

protected String path
The folder path.


permanentFlags

protected Flags permanentFlags


subscribed

protected boolean subscribed


type

protected int type
The type of this folder(HOLDS_MESSAGES or HOLDS_FOLDERS).


uidValidity

protected long uidValidity

Constructor Details

IMAPFolder

protected IMAPFolder(Store store,
                     String path)
Constructor.


IMAPFolder

protected IMAPFolder(Store store,
                     String path,
                     char delimiter)
Constructor.


IMAPFolder

protected IMAPFolder(Store store,
                     String path,
                     int type,
                     char delimiter)
Constructor.

Method Details

appendMessages

public void appendMessages(Message[] messages)
            throws MessagingException
Appends the specified set of messages to this folder. Only MimeMessages are accepted.


close

public void close(boolean expunge)
            throws MessagingException
Closes this folder.
Overrides:
close in interface Folder

Parameters:
expunge - if the folder is to be expunged before it is closed

Throws:
MessagingException - if a messaging error occurred


create

public boolean create(int type)
            throws MessagingException
Create this folder.
Overrides:
create in interface Folder


delete

public boolean delete(boolean flag)
            throws MessagingException
Delete this folder.
Overrides:
delete in interface Folder


equals

public boolean equals(Object other)


exists

public boolean exists()
            throws MessagingException
Indicates whether this folder exists.
Overrides:
exists in interface Folder

Throws:
MessagingException - if a messaging error occurred


expunge

public Message[] expunge()
            throws MessagingException
Expunges this folder. This deletes all the messages marked as deleted.
Overrides:
expunge in interface Folder

Throws:
MessagingException - if a messaging error occurred


fetch

public void fetch(Message[] messages,
                  FetchProfile fp)
            throws MessagingException
IMAP fetch routine. This executes the fetch for the specified message numbers and updates the messages according to the message statuses returned.


getFolder

public Folder getFolder(String name)
            throws MessagingException
Returns a subfolder with the specified name.
Overrides:
getFolder in interface Folder


getFullName

public String getFullName()
Returns the full path of this folder.
Overrides:
getFullName in interface Folder


getMessage

public Message getMessage(int msgnum)
            throws MessagingException
Returns the specified message number from this folder. The message is only retrieved once from the server. Subsequent getMessage() calls to the same message are cached. Since POP3 does not provide a mechanism for retrieving only part of the message(headers, etc), the entire message is retrieved.
Overrides:
getMessage in interface Folder

Throws:
MessagingException - if a messaging error occurred


getMessageByUID

public Message getMessageByUID(long uid)
            throws MessagingException
Get the Message corresponding to the given UID. If no such message exists, null is returned.
Specified by:
getMessageByUID in interface UIDFolder

Parameters:
uid - UID for the desired message


getMessageCount

public int getMessageCount()
            throws MessagingException
Returns the number of messages in this folder.
Overrides:
getMessageCount in interface Folder

Throws:
MessagingException - if a messaging error occurred


getMessagesByUID

public Message[] getMessagesByUID(long start,
                                  long end)
            throws MessagingException
Get the Messages specified by the given range. The special value LASTUID can be used for the end parameter to indicate the last available UID.
Specified by:
getMessagesByUID in interface UIDFolder

Parameters:
start - start UID
end - end UID


getMessagesByUID

public Message[] getMessagesByUID(long[] uids)
            throws MessagingException
Get the Messages specified by the given array of UIDs. If any UID is invalid, null is returned for that entry.

Note that the returned array will be of the same size as the specified array of UIDs, and null entries may be present in the array to indicate invalid UIDs.

Specified by:
getMessagesByUID in interface UIDFolder

Parameters:
uids - array of UIDs


getName

public String getName()
Returns the name of this folder.
Overrides:
getName in interface Folder


getNewMessageCount

public int getNewMessageCount()
            throws MessagingException
Returns the number of new messages in this folder.
Overrides:
getNewMessageCount in interface Folder

Throws:
MessagingException - if a messaging error occurred


getParent

public Folder getParent()
            throws MessagingException
Returns the parent folder of this folder.
Overrides:
getParent in interface Folder


getPermanentFlags

public Flags getPermanentFlags()
Returns the permanent flags for this folder.
Overrides:
getPermanentFlags in interface Folder


getQuota

public Quota[] getQuota()
            throws MessagingException
Returns the quotas for this folder.


getSeparator

public char getSeparator()
            throws MessagingException
Returns the path separator charcter.
Overrides:
getSeparator in interface Folder


getType

public int getType()
            throws MessagingException
Returns the type of this folder.
Overrides:
getType in interface Folder

Throws:
MessagingException - if a messaging error occurred


getUID

public long getUID(Message message)
            throws MessagingException
Get the UID for the specified message. Note that the message must belong to this folder. Else NoSuchElementException is thrown.
Specified by:
getUID in interface UIDFolder

Parameters:
message - Message from this folder

Returns:
UID for this message


getUIDValidity

public long getUIDValidity()
            throws MessagingException
Returns the UIDValidity value associated with this folder.

Clients typically compare this value against a UIDValidity value saved from a previous session to insure that any cached UIDs not stale.

Specified by:
getUIDValidity in interface UIDFolder


hasNewMessages

public boolean hasNewMessages()
            throws MessagingException
Indicates whether this folder contains new messages.
Overrides:
hasNewMessages in interface Folder

Throws:
MessagingException - if a messaging error occurred


isOpen

public boolean isOpen()
Indicates whether this folder is open.
Overrides:
isOpen in interface Folder


isSubscribed

public boolean isSubscribed()
Returns true if this Folder is subscribed.

This method can be invoked on a closed Folder.

The default implementation provided here just returns true.

Overrides:
isSubscribed in interface Folder


list

public Folder[] list(String pattern)
            throws MessagingException
Returns the subfolders for this folder.
Overrides:
list in interface Folder


listSubscribed

public Folder[] listSubscribed(String pattern)
            throws MessagingException
Returns the subscribed subfolders for this folder.
Overrides:
listSubscribed in interface Folder


open

public void open(int mode)
            throws MessagingException
Opens this folder.
Overrides:
open in interface Folder

Throws:
MessagingException - if a messaging error occurred


renameTo

public boolean renameTo(Folder folder)
            throws MessagingException
Rename this folder.
Overrides:
renameTo in interface Folder


search

public Message[] search(SearchTerm term)
            throws MessagingException
IMAP search function.
Overrides:
search in interface Folder


search

public Message[] search(SearchTerm term,
                        Message[] msgs)
            throws MessagingException
IMAP search function.


setSubscribed

public void setSubscribed(boolean flag)
            throws MessagingException
Subscribe or unsubscribe this Folder. Not all Stores support subscription.

This method can be invoked on a closed Folder.

The implementation provided here just throws the MethodNotSupportedException.

Overrides:
setSubscribed in interface Folder