Java Reference
In-Depth Information
Folder folder = null ;
try {
// Connect to the server and open the folder
folder = session . getFolder ( server );
// work with the folder...
} catch ( MessagingException | IOException ex ) {
ex . printStackTrace ();
} finally {
// Close the connection
// but don't remove the messages from the server
if ( folder != null && folder . isOpen ()) {
try {
folder . close ( false );
} catch ( MessagingException e ) {
// ignore;
}
}
}
Basic Folder Info
The Folder class has eight methods that return basic information about a folder:
public abstract String getName ()
public abstract String getFullName ()
public URLName getURLName () throws MessagingException
public abstract Folder getParent () throws MessagingException
public abstract int getType () throws MessagingException
public int getMode () throws IllegalStateException
public Store getStore ()
public abstract char getSeparator ()
throws FolderNotFoundException , MessagingException
The getName() method returns the name of the folder, such as “Reader Mail”, whereas
the getFullName() method returns the complete hierarchical name from the root, such
as “books/JNP4E/Reader Mail”. In this example, the slash character is the separator
between nested folders. The separator can vary from implementation to implementa‐
tion, but the getSeparator() method always tells you what it is.
The getURLName() method includes the server; for instance, “imap://
elharo@mail.ibiblio.org/books/JNP4E/Reader%20Mail”.
The getParent() method returns the name of the folder that contains this folder; e.g.,
“JNP4E” for the previous Reader Mail example.
The getType() method returns an int indicating whether the folder can contain mes‐
sages and/or other folders. If it can contain messages but not folders, getType() returns
the named constant Folder.HOLDS_MESSAGES . If it can contain folders but not messages,
getType() returns the named constant Folder.HOLDS_FOLDERS . If it can contain both
Search WWH ::




Custom Search