Package gnu.mail.providers.mbox
Class MboxFolder
- java.lang.Object
-
- javax.mail.Folder
-
- gnu.mail.providers.mbox.MboxFolder
-
public class MboxFolder extends Folder
The folder class implementing a UNIX mbox-format mailbox.- Author:
- Chris Burdess
-
-
Field Summary
-
Fields inherited from class javax.mail.Folder
HOLDS_FOLDERS, HOLDS_MESSAGES, mode, READ_ONLY, READ_WRITE, store
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMboxFolder(Store store, java.io.File file, boolean inbox)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanacquireLock()Locks this mailbox.voidappendMessages(Message[] m)Appends messages to this folder.voidclose(boolean expunge)Closes this folder.booleancreate(int type)Creates this folder in the store.static java.lang.StringdecodeFrom(java.lang.String line)Returns the specified line with any From_ line encoding removed.booleandelete(boolean recurse)Deletes this folder.booleanexists()Indicates whether this folder exists.Message[]expunge()Expunges this folder.protected java.lang.StringfromLine(MboxMessage message)Returns the From_ line for the specified mbox message.FoldergetFolder(java.lang.String name)Returns the subfolder of this folder with the specified name.java.lang.StringgetFullName()Returns the full name of this folder.MessagegetMessage(int msgnum)Returns the specified message number from this folder.intgetMessageCount()Returns the number of messages in this folder.Message[]getMessages()Returns the messages in this folder.java.lang.StringgetName()Returns the name of this folder.FoldergetParent()Returns the parent folder.FlagsgetPermanentFlags()Returns the permanent flags for this folder.chargetSeparator()Returns the separator character.intgetType()Returns the type of this folder.URLNamegetURLName()Return a URLName representing this folder.booleanhasNewMessages()Indicates whether this folder contains new messages.booleanisOpen()Indicates whether this folder is open.Folder[]list()Returns the subfolders of this folder.Folder[]list(java.lang.String pattern)Returns the subfolders of this folder matching the specified pattern.voidopen(int mode)Opens this folder.booleanreleaseLock()Unlocks this mailbox.booleanrenameTo(Folder folder)Renames this folder.-
Methods inherited from class javax.mail.Folder
addConnectionListener, addFolderListener, addMessageChangedListener, addMessageCountListener, copyMessages, fetch, getDeletedMessageCount, getMessages, getMessages, getMode, getNewMessageCount, getStore, getUnreadMessageCount, isSubscribed, listSubscribed, listSubscribed, notifyConnectionListeners, notifyFolderListeners, notifyFolderRenamedListeners, notifyMessageAddedListeners, notifyMessageChangedListeners, notifyMessageRemovedListeners, removeConnectionListener, removeFolderListener, removeMessageChangedListener, removeMessageCountListener, search, search, setFlags, setFlags, setFlags, setSubscribed, toString
-
-
-
-
Constructor Detail
-
MboxFolder
protected MboxFolder(Store store, java.io.File file, boolean inbox)
Constructor.
-
-
Method Detail
-
getName
public java.lang.String getName()
Returns the name of this folder.
-
getFullName
public java.lang.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.- Specified by:
getFullNamein classFolder
-
getURLName
public URLName getURLName() throws MessagingException
Return a URLName representing this folder.- Overrides:
getURLNamein classFolder- Throws:
MessagingException
-
getType
public int getType() throws MessagingExceptionReturns the type of this folder.- Specified by:
getTypein classFolder- Throws:
MessagingException- if a messaging error occurred
-
exists
public boolean exists() throws MessagingExceptionIndicates whether this folder exists.- Specified by:
existsin classFolder- Throws:
MessagingException- if a messaging error occurred
-
hasNewMessages
public boolean hasNewMessages() throws MessagingExceptionIndicates whether this folder contains new messages.- Specified by:
hasNewMessagesin classFolder- Throws:
MessagingException- if a messaging error occurred
-
open
public void open(int mode) throws MessagingExceptionOpens this folder. If the folder is opened for writing, a lock must be acquired on the mbox. If this fails a MessagingException is thrown.- Specified by:
openin classFolder- Parameters:
mode- open the Folder READ_ONLY or READ_WRITE- Throws:
MessagingException- if a messaging error occurred
-
decodeFrom
public static java.lang.String decodeFrom(java.lang.String line)
Returns the specified line with any From_ line encoding removed.
-
close
public void close(boolean expunge) throws MessagingExceptionCloses this folder.- Specified by:
closein classFolder- Parameters:
expunge- if the folder is to be expunged before it is closed- Throws:
MessagingException- if a messaging error occurred
-
fromLine
protected java.lang.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.- Throws:
MessagingException
-
expunge
public Message[] expunge() throws MessagingException
Expunges this folder. This deletes all the messages marked as deleted.- Specified by:
expungein classFolder- Throws:
MessagingException- if a messaging error occurred
-
isOpen
public boolean isOpen()
Indicates whether this folder is open.
-
getPermanentFlags
public Flags getPermanentFlags()
Returns the permanent flags for this folder.- Specified by:
getPermanentFlagsin classFolder
-
getMessageCount
public int getMessageCount() throws MessagingExceptionReturns the number of messages in this folder.- Specified by:
getMessageCountin classFolder- Throws:
MessagingException- if a messaging error occurred
-
getMessage
public Message getMessage(int msgnum) throws MessagingException
Returns the specified message number from this folder.- Specified by:
getMessagein classFolder- Parameters:
msgnum- the message number- Throws:
MessagingException- if a messaging error occurred
-
getMessages
public Message[] getMessages() throws MessagingException
Returns the messages in this folder.- Overrides:
getMessagesin classFolder- Throws:
MessagingException- if a messaging error occurred
-
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.- Specified by:
appendMessagesin classFolder- Parameters:
m- an array of messages to be appended- Throws:
FolderNotFoundException- if this folder does not existMessagingException- if the append operation failed
-
getParent
public Folder getParent() throws MessagingException
Returns the parent folder.- Specified by:
getParentin classFolder- Throws:
MessagingException
-
list
public Folder[] list() throws MessagingException
Returns the subfolders of this folder.- Overrides:
listin classFolder- Throws:
MessagingException
-
list
public Folder[] list(java.lang.String pattern) throws MessagingException
Returns the subfolders of this folder matching the specified pattern.- Specified by:
listin classFolder- Parameters:
pattern- the match pattern- Throws:
MessagingException
-
getSeparator
public char getSeparator() throws MessagingExceptionReturns the separator character.- Specified by:
getSeparatorin classFolder- Throws:
MessagingException
-
create
public boolean create(int type) throws MessagingExceptionCreates this folder in the store.- Specified by:
createin classFolder- Parameters:
type- the desired type of the folder- Throws:
MessagingException
-
delete
public boolean delete(boolean recurse) throws MessagingExceptionDeletes this folder.- Specified by:
deletein classFolder- Parameters:
recurse- delete any subfolders- Returns:
- true if the folder is deleted successfully, false otherwise
- Throws:
FolderNotFoundException- if this folder does not existMessagingException
-
renameTo
public boolean renameTo(Folder folder) throws MessagingException
Renames this folder.- Specified by:
renameToin classFolder- Parameters:
folder- a folder representing the new name for this folder- Returns:
- true if the folder is renamed successfully, false otherwise
- Throws:
FolderNotFoundException- if this folder does not existMessagingException
-
getFolder
public Folder getFolder(java.lang.String name) throws MessagingException
Returns the subfolder of this folder with the specified name.- Specified by:
getFolderin classFolder- Parameters:
name- the name of the folder- Throws:
MessagingException
-
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.
-
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.
-
-