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.activity.Initializable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.framework.service.Serviceable, MailRepository

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

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: 454176 $

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)
          Configure the component
 void initialize()
          Initialise the component
 java.util.Iterator list()
          Return the list of the current messages' keys
 boolean lock(java.lang.String key)
          Not implemented
static void main(java.lang.String[] args)
           
 void remove(java.util.Collection mails)
          Remove a list of messages from disk The collection is simply a list of mails to delete
 void remove(Mail mail)
          Remove an existing message
 void remove(java.lang.String key)
          Remove a mail from the mbox file
 Mail retrieve(java.lang.String key)
          Get a message from the backing store (disk)
 void service(org.apache.avalon.framework.service.ServiceManager componentManager)
           
 void store(Mail mc)
          Store the given email in the current mbox file
 boolean unlock(java.lang.String key)
          Not implemented
 
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(Mail mc)
Store the given email in the current mbox file

Specified by:
store in interface MailRepository
Parameters:
mc - The mail to store

list

public java.util.Iterator list()
Return the list of the current messages' keys

Specified by:
list in interface MailRepository
Returns:
A list of the keys of the emails currently loaded

retrieve

public Mail retrieve(java.lang.String key)
Get a message from the backing store (disk)

Specified by:
retrieve in interface MailRepository
Parameters:
key -
Returns:
The mail found from the key. Returns null if the key is not found

remove

public void remove(Mail mail)
Remove an existing message

Specified by:
remove in interface MailRepository
Parameters:
mail -

remove

public void remove(java.util.Collection mails)
Remove a list of messages from disk The collection is simply a list of mails to delete

Specified by:
remove in interface MailRepository
Parameters:
mails -

remove

public void remove(java.lang.String key)
Remove a mail from the mbox file

Specified by:
remove in interface MailRepository
Parameters:
key - The key of the mail to delete

lock

public boolean lock(java.lang.String key)
Not implemented

Specified by:
lock in interface MailRepository
Parameters:
key -
Returns:

unlock

public boolean unlock(java.lang.String key)
Not implemented

Specified by:
unlock in interface MailRepository
Parameters:
key -
Returns:

service

public void service(org.apache.avalon.framework.service.ServiceManager componentManager)
             throws org.apache.avalon.framework.service.ServiceException
Specified by:
service in interface org.apache.avalon.framework.service.Serviceable
Throws:
org.apache.avalon.framework.service.ServiceException
See Also:
org.apache.avalon.framework.service.Serviceable#compose(ServiceManager )

configure

public void configure(org.apache.avalon.framework.configuration.Configuration conf)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Configure the component

Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Parameters:
conf -
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

initialize

public void initialize()
                throws java.lang.Exception
Initialise the component

Specified by:
initialize in interface org.apache.avalon.framework.activity.Initializable
Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)


Copyright © 2002-2007 The Apache Software Foundation. All Rights Reserved.