org.apache.james.mailrepository
Class MBoxMailRepository

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.james.mailrepository.MBoxMailRepository
All Implemented Interfaces:
org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.logger.LogEnabled, MailRepository

public class MBoxMailRepository
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements MailRepository, org.apache.avalon.framework.configuration.Configurable

Implementation of a MailRepository using UNIX mbox files.

Requires a configuration element in the .conf.xml file of the form:
<repository destinationURL="mbox://<directory>"
type="MAIL"
</directory> is where the individual mbox files are read from/written to
Type can ONLY be MAIL (SPOOL is NOT supported)

Requires a logger called MailRepository.

Implementation notes:

This class keeps an internal store of the mbox file When the internal mbox file is updated (added/deleted) then the file will be re-read from disk and then written back. This is a bit inefficent but means that the file on disk should be correct.

The mbox store is mainly meant to be used as a one-way street. Storing new emails is very fast (append to file) whereas reading them (via POP3) is slower (read from disk and parse). Therefore this implementation is best suited to people who wish to use the mbox format for taking data out of James and into something else (IMAP server or mail list displayer)

Version:
CVS $Revision: 684816 $

Nested Class Summary
static interface MBoxMailRepository.MessageAction
          A callback used when a message is read from the mbox file
 
Field Summary
 
Fields inherited from interface org.apache.james.services.MailRepository
MAIL, ROLE
 
Constructor Summary
MBoxMailRepository()
           
 
Method Summary
 void configure(org.apache.avalon.framework.configuration.Configuration conf)
           
 java.util.Iterator list()
          List string keys of messages in repository.
 boolean lock(java.lang.String key)
          Obtains a lock on a message identified by key
 void remove(java.util.Collection mails)
          Remove an Collection of mails from the repository
 void remove(org.apache.mailet.Mail mail)
          Removes a specified message
 void remove(java.lang.String key)
          Removes a message identified by key.
 org.apache.mailet.Mail retrieve(java.lang.String key)
          Retrieves a message given a key.
 void store(org.apache.mailet.Mail mc)
          Stores a message in this repository.
 boolean unlock(java.lang.String key)
          Releases a lock on a message identified the key
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MBoxMailRepository

public MBoxMailRepository()
Method Detail

store

public void store(org.apache.mailet.Mail mc)
Description copied from interface: MailRepository
Stores a message in this repository. Shouldn't this return the key under which it is stored?

Specified by:
store in interface MailRepository
Parameters:
mc - the mail message to store
See Also:
MailRepository.store(Mail)

list

public java.util.Iterator list()
Description copied from interface: MailRepository
List string keys of messages in repository.

Specified by:
list in interface MailRepository
Returns:
an Iterator over the list of keys in the repository
See Also:
MailRepository.list()

retrieve

public org.apache.mailet.Mail retrieve(java.lang.String key)
Description copied from interface: MailRepository
Retrieves a message given a key. At the moment, keys can be obtained from list() in superinterface Store.Repository

Specified by:
retrieve in interface MailRepository
Parameters:
key - the key of the message to retrieve
Returns:
the mail corresponding to this key, null if none exists
See Also:
MailRepository.retrieve(String)

remove

public void remove(org.apache.mailet.Mail mail)
Description copied from interface: MailRepository
Removes a specified message

Specified by:
remove in interface MailRepository
Parameters:
mail - the message to be removed from the repository
See Also:
MailRepository.remove(Mail)

remove

public void remove(java.util.Collection mails)
Description copied from interface: MailRepository
Remove an Collection of mails from the repository

Specified by:
remove in interface MailRepository
Parameters:
mails - The Collection of MailImpl's to delete
See Also:
MailRepository.remove(Collection)

remove

public void remove(java.lang.String key)
Description copied from interface: MailRepository
Removes a message identified by key.

Specified by:
remove in interface MailRepository
Parameters:
key - the key of the message to be removed from the repository
See Also:
MailRepository.remove(String)

lock

public boolean lock(java.lang.String key)
Description copied from interface: MailRepository
Obtains a lock on a message identified by key

Specified by:
lock in interface MailRepository
Parameters:
key - the key of the message to be locked
Returns:
true if successfully obtained the lock, false otherwise
See Also:
MailRepository.lock(String)

unlock

public boolean unlock(java.lang.String key)
Description copied from interface: MailRepository
Releases a lock on a message identified the key

Specified by:
unlock in interface MailRepository
Parameters:
key - the key of the message to be unlocked
Returns:
true if successfully released the lock, false otherwise
See Also:
MailRepository.unlock(String)

configure

public void configure(org.apache.avalon.framework.configuration.Configuration conf)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Throws:
org.apache.avalon.framework.configuration.ConfigurationException
See Also:
Configurable.configure(Configuration)


Copyright ? 2002-2009 The Apache Software Foundation. All Rights Reserved.