public class

DefaultFolder

extends Folder
java.lang.Object
   ↳ com.google.code.javax.mail.Folder
     ↳ com.google.code.com.sun.mail.pop3.DefaultFolder

Class Overview

The POP3 DefaultFolder. Only contains the "INBOX" folder.

Summary

[Expand]
Inherited Constants
From class com.google.code.javax.mail.Folder
[Expand]
Inherited Fields
From class com.google.code.javax.mail.Folder
Public Methods
void appendMessages(Message[] msgs)
Append given Messages to this folder.
void close(boolean expunge)
Close this GmailFolder.
boolean create(int type)
Create this folder on the Store.
boolean delete(boolean recurse)
Delete this GmailFolder.
boolean exists()
Tests if this folder physically exists on the Store.
Message[] expunge()
Expunge (permanently remove) messages marked DELETED.
Folder getFolder(String name)
Return the GmailFolder object corresponding to the given name.
String getFullName()
Returns the full name of this GmailFolder.
Message getMessage(int msgno)
Get the Message object corresponding to the given message number.
int getMessageCount()
Get total number of messages in this GmailFolder.
String getName()
Returns the name of this GmailFolder.
Folder getParent()
Returns the parent folder of this folder.
Flags getPermanentFlags()
Get the permanent flags supported by this GmailFolder.
char getSeparator()
Return the delimiter character that separates this GmailFolder's pathname from the names of immediate subfolders.
int getType()
Returns the type of this GmailFolder, that is, whether this folder can hold messages or subfolders or both.
boolean hasNewMessages()
Returns true if this GmailFolder has new messages since the last time this indication was reset.
boolean isOpen()
Indicates whether this GmailFolder is in the 'open' state.
Folder[] list(String pattern)
Returns a list of Folders belonging to this GmailFolder's namespace that match the specified pattern.
void open(int mode)
Open this GmailFolder.
boolean renameTo(Folder f)
Rename this GmailFolder.
Folder[] xlist(String pattern)
Protected Methods
Folder getInbox()
[Expand]
Inherited Methods
From class com.google.code.javax.mail.Folder
From class java.lang.Object

Public Methods

public void appendMessages (Message[] msgs)

Append given Messages to this folder. This method can be invoked on a closed GmailFolder. An appropriate MessageCountEvent is delivered to any MessageCountListener registered on this folder when the messages arrive in the folder.

GmailFolder implementations must not abort this operation if a Message in the given message array turns out to be an expunged Message.

Parameters
msgs Array of Messages to be appended

public void close (boolean expunge)

Close this GmailFolder. This method is valid only on open Folders.

A CLOSED ConnectionEvent is delivered to any ConnectionListeners registered on this GmailFolder. Note that the folder is closed even if this method terminates abnormally by throwing a MessagingException.

Parameters
expunge Expunges all deleted messages if this flag is true

public boolean create (int type)

Create this folder on the Store. When this folder is created, any folders in its path that do not exist are also created.

If the creation is successful, a CREATED FolderEvent is delivered to any FolderListeners registered on this GmailFolder and this Store.

Parameters
type The type of this folder.
Returns
  • true if the creation succeeds, else false.

public boolean delete (boolean recurse)

Delete this GmailFolder. This method will succeed only on a closed GmailFolder.

The recurse flag controls whether the deletion affects subfolders or not. If true, all subfolders are deleted, then this folder itself is deleted. If false, the behaviour is dependent on the folder type and is elaborated below:

  • The folder can contain only messages: (type == HOLDS_MESSAGES).
    All messages within the folder are removed. The folder itself is then removed. An appropriate FolderEvent is generated by the Store and this folder.

  • The folder can contain only subfolders: (type == HOLDS_FOLDERS).
    If this folder is empty (does not contain any subfolders at all), it is removed. An appropriate FolderEvent is generated by the Store and this folder.
    If this folder contains any subfolders, the delete fails and returns false.

  • The folder can contain subfolders as well as messages:
    If the folder is empty (no messages or subfolders), it is removed. If the folder contains no subfolders, but only messages, then all messages are removed. The folder itself is then removed. In both the above cases, an appropriate FolderEvent is generated by the Store and this folder.

    If the folder contains subfolders there are 3 possible choices an implementation is free to do:

    1. The operation fails, irrespective of whether this folder contains messages or not. Some implementations might elect to go with this simple approach. The delete() method returns false.
    2. Any messages within the folder are removed. Subfolders are not removed. The folder itself is not removed or affected in any manner. The delete() method returns true. And the exists() method on this folder will return true indicating that this folder still exists.
      An appropriate FolderEvent is generated by the Store and this folder.
    3. Any messages within the folder are removed. Subfolders are not removed. The folder itself changes its type from HOLDS_FOLDERS | HOLDS_MESSAGES to HOLDS_FOLDERS. Thus new messages cannot be added to this folder, but new subfolders can be created underneath. The delete() method returns true indicating success. The exists() method on this folder will return true indicating that this folder still exists.
      An appropriate FolderEvent is generated by the Store and this folder.

Parameters
recurse
Returns
  • true if the GmailFolder is deleted successfully

public boolean exists ()

Tests if this folder physically exists on the Store. This method can be invoked on a closed GmailFolder.

Returns
  • true if the folder exists, otherwise false

public Message[] expunge ()

Expunge (permanently remove) messages marked DELETED. Returns an array containing the expunged message objects. The getMessageNumber method on each of these message objects returns that Message's original (that is, prior to the expunge) sequence number. A MessageCountEvent containing the expunged messages is delivered to any MessageCountListeners registered on the folder.

Expunge causes the renumbering of Message objects subsequent to the expunged messages. Clients that use message numbers as references to messages should be aware of this and should be prepared to deal with the situation (probably by flushing out existing message number caches and reloading them). Because of this complexity, it is better for clients to use Message objects as references to messages, rather than message numbers. Any expunged Messages objects still have to be pruned, but other Messages in that folder are not affected by the expunge.

After a message is expunged, only the isExpunged and getMessageNumber methods are still valid on the corresponding Message object; other methods may throw MessageRemovedException

Returns
  • array of expunged Message objects

public Folder getFolder (String name)

Return the GmailFolder object corresponding to the given name. Note that this folder does not physically have to exist in the Store. The exists() method on a GmailFolder indicates whether it really exists on the Store.

In some Stores, name can be an absolute path if it starts with the hierarchy delimiter. Otherwise, it is interpreted relative to this GmailFolder.

GmailFolder objects are not cached by the Store, so invoking this method on the same name multiple times will return that many distinct GmailFolder objects.

This method can be invoked on a closed GmailFolder.

Parameters
name Name of the GmailFolder
Returns
  • GmailFolder object

public String getFullName ()

Returns the full name of this GmailFolder. If the folder resides under the root hierarchy of this Store, the returned name is relative to the root. Otherwise an absolute name, starting with the hierarchy delimiter, is returned.

This method can be invoked on a closed GmailFolder.

Returns
  • full name of the GmailFolder

public Message getMessage (int msgno)

Get the Message object corresponding to the given message number. A Message object's message number is the relative position of this Message in its GmailFolder. Messages are numbered starting at 1 through the total number of message in the folder. Note that the message number for a particular Message can change during a session if other messages in the GmailFolder are deleted and the GmailFolder is expunged.

Message objects are light-weight references to the actual message that get filled up on demand. Hence GmailFolder implementations are expected to provide light-weight Message objects.

Unlike GmailFolder objects, repeated calls to getMessage with the same message number will return the same Message object, as long as no messages in this folder have been expunged.

Since message numbers can change within a session if the folder is expunged , clients are advised not to use message numbers as references to messages. Use Message objects instead.

Parameters
msgno The message number
Returns
  • the Message object

public int getMessageCount ()

Get total number of messages in this GmailFolder.

This method can be invoked on a closed folder. However, note that for some folder implementations, getting the total message count can be an expensive operation involving actually opening the folder. In such cases, a provider can choose not to support this functionality in the closed state, in which case this method must return -1.

Clients invoking this method on a closed folder must be aware that this is a potentially expensive operation. Clients must also be prepared to handle a return value of -1 in this case.

Returns
  • total number of messages. -1 may be returned by certain implementations if this method is invoked on a closed folder.

public String getName ()

Returns the name of this GmailFolder.

This method can be invoked on a closed GmailFolder.

Returns
  • name of the GmailFolder

public Folder getParent ()

Returns the parent folder of this folder. This method can be invoked on a closed GmailFolder. If this folder is the top of a folder hierarchy, this method returns null.

Note that since GmailFolder objects are not cached, invoking this method returns a new distinct GmailFolder object.

Returns
  • Parent folder

public Flags getPermanentFlags ()

Get the permanent flags supported by this GmailFolder. Returns a Flags object that contains all the flags supported.

The special flag Flags.Flag.USER indicates that this GmailFolder supports arbitrary user-defined flags.

The supported permanent flags for a folder may not be available until the folder is opened.

Returns
  • permanent flags, or null if not known

public char getSeparator ()

Return the delimiter character that separates this GmailFolder's pathname from the names of immediate subfolders. This method can be invoked on a closed GmailFolder.

Returns
  • Hierarchy separator character

public int getType ()

Returns the type of this GmailFolder, that is, whether this folder can hold messages or subfolders or both. The returned value is an integer bitfield with the appropriate bits set. This method can be invoked on a closed folder.

Returns
  • integer with appropriate bits set

public boolean hasNewMessages ()

Returns true if this GmailFolder has new messages since the last time this indication was reset. When this indication is set or reset depends on the GmailFolder implementation (and in the case of IMAP, depends on the server). This method can be used to implement a lightweight "check for new mail" operation on a GmailFolder without opening it. (For example, a thread that monitors a mailbox and flags when it has new mail.) This method should indicate whether any messages in the GmailFolder have the RECENT flag set.

Note that this is not an incremental check for new mail, i.e., it cannot be used to determine whether any new messages have arrived since the last time this method was invoked. To implement incremental checks, the GmailFolder needs to be opened.

This method can be invoked on a closed GmailFolder that can contain Messages.

Returns
  • true if the Store has new Messages

public boolean isOpen ()

Indicates whether this GmailFolder is in the 'open' state.

Returns
  • true if this GmailFolder is in the 'open' state.

public Folder[] list (String pattern)

Returns a list of Folders belonging to this GmailFolder's namespace that match the specified pattern. Patterns may contain the wildcard characters "%", which matches any character except hierarchy delimiters, and "*", which matches any character.

As an example, given the folder hierarchy:

    Personal/
       Finance/
          Stocks
          Bonus
          StockOptions
       Jokes
 
list("*") on "Personal" will return the whole hierarchy.
list("%") on "Personal" will return "Finance" and "Jokes".
list("Jokes") on "Personal" will return "Jokes".
list("Stock*") on "Finance" will return "Stocks" and "StockOptions".

GmailFolder objects are not cached by the Store, so invoking this method on the same pattern multiple times will return that many distinct GmailFolder objects.

This method can be invoked on a closed GmailFolder.

Parameters
pattern The match pattern
Returns
  • array of matching GmailFolder objects. An empty array is returned if no matching Folders exist.

public void open (int mode)

Open this GmailFolder. This method is valid only on Folders that can contain Messages and that are closed.

If this folder is opened successfully, an OPENED ConnectionEvent is delivered to any ConnectionListeners registered on this GmailFolder.

The effect of opening multiple connections to the same folder on a specifc Store is implementation dependent. Some implementations allow multiple readers, but only one writer. Others allow multiple writers as well as readers.

Parameters
mode Open the GmailFolder READ_ONLY or READ_WRITE

public boolean renameTo (Folder f)

Rename this GmailFolder. This method will succeed only on a closed GmailFolder.

If the rename is successful, a RENAMED FolderEvent is delivered to FolderListeners registered on this folder and its containing Store.

Parameters
f A folder representing the new name for this GmailFolder
Returns
  • true if the GmailFolder is renamed successfully

public Folder[] xlist (String pattern)

Parameters
pattern

Protected Methods

protected Folder getInbox ()