gnu.mail.providers.mbox

Class MboxFolder


public class MboxFolder
extends Folder

The folder class implementing a UNIX mbox-format mailbox.

Field Summary

Fields inherited from class javax.mail.Folder

HOLDS_FOLDERS, HOLDS_MESSAGES, READ_ONLY, READ_WRITE, mode, store

Constructor Summary

MboxFolder(Store store, File file, boolean inbox)
Constructor.

Method Summary

boolean
acquireLock()
Locks this mailbox.
void
appendMessages(Message[] m)
Appends messages to this folder.
void
close(boolean expunge)
Closes this folder.
boolean
create(int type)
Creates this folder in the store.
static String
decodeFrom(String line)
Returns the specified line with any From_ line encoding removed.
boolean
delete(boolean recurse)
Deletes this folder.
boolean
exists()
Indicates whether this folder exists.
Message[]
expunge()
Expunges this folder.
protected String
fromLine(MboxMessage message)
Returns the From_ line for the specified mbox message.
Folder
getFolder(String name)
Returns the subfolder of this folder with the specified name.
String
getFullName()
Returns the full name of this folder.
Message
getMessage(int msgnum)
Returns the specified message number from this folder.
int
getMessageCount()
Returns the number of messages in this folder.
Message[]
getMessages()
Returns the messages in this folder.
String
getName()
Returns the name of this folder.
Folder
getParent()
Returns the parent folder.
Flags
getPermanentFlags()
Returns the permanent flags for this folder.
char
getSeparator()
Returns the separator character.
int
getType()
Returns the type of this folder.
URLName
getURLName()
Return a URLName representing this folder.
boolean
hasNewMessages()
Indicates whether this folder contains new messages.
boolean
isOpen()
Indicates whether this folder is open.
Folder[]
list()
Returns the subfolders of this folder.
Folder[]
list(String pattern)
Returns the subfolders of this folder matching the specified pattern.
void
open(int mode)
Opens this folder.
boolean
releaseLock()
Unlocks this mailbox.
boolean
renameTo(Folder folder)
Renames 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

Constructor Details

MboxFolder

protected MboxFolder(Store store,
                     File file,
                     boolean inbox)
Constructor.

Method Details

acquireLock

public boolean acquireLock()
Locks this mailbox. This uses a dotlock-like mechanism - see createNewFile(). If the directory containing the mbox folder is not writable, we will not be able to open the mbox for writing either.


appendMessages

public void appendMessages(Message[] m)
            throws MessagingException
Appends messages to this folder. Only MimeMessages within the array will be appended, as we don't know how to retrieve internet content for other kinds.

Parameters:
m - an array of messages to be appended


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
Creates this folder in the store.
Overrides:
create in interface Folder


decodeFrom

public static String decodeFrom(String line)
Returns the specified line with any From_ line encoding removed.


delete

public boolean delete(boolean recurse)
            throws MessagingException
Deletes this folder.
Overrides:
delete in interface Folder


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


fromLine

protected String fromLine(MboxMessage message)
            throws MessagingException
Returns the From_ line for the specified mbox message. If this does not already exist(the message was appended to the folder since it was last opened), we will attempt to generate a suitable From_ line for it.


getFolder

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


getFullName

public String getFullName()
Returns the full name of this folder. 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.
Overrides:
getFullName in interface Folder


getMessage

public Message getMessage(int msgnum)
            throws MessagingException
Returns the specified message number from this folder.
Overrides:
getMessage in interface Folder

Throws:
MessagingException - if a messaging error occurred


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


getMessages

public Message[] getMessages()
            throws MessagingException
Returns the messages in this folder.
Overrides:
getMessages in interface Folder

Throws:
MessagingException - if a messaging error occurred


getName

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


getParent

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


getPermanentFlags

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


getSeparator

public char getSeparator()
            throws MessagingException
Returns the separator character.
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


getURLName

public URLName getURLName()
            throws MessagingException
Return a URLName representing this folder.
Overrides:
getURLName in interface Folder


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


list

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


list

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


open

public void open(int mode)
            throws MessagingException
Opens this folder. If the folder is opened for writing, a lock must be acquired on the mbox. If this fails a MessagingException is thrown.
Overrides:
open in interface Folder

Throws:
MessagingException - if a messaging error occurred


releaseLock

public boolean releaseLock()
Unlocks this mailbox. This deletes any associated lockfile if it exists. It returns false if an existing lockfile could not be deleted.


renameTo

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