org.apache.james
Class James

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLogEnabled
        |
        +--org.apache.james.James
All Implemented Interfaces:
Component, Composable, Configurable, Contextualizable, Initializable, JamesMBean, LogEnabled, MailetContext, MailServer

public class James
extends AbstractLogEnabled
implements Contextualizable, Composable, Configurable, JamesMBean, Initializable, MailServer, MailetContext, Component

Core class for JAMES. Provides three primary services:
1) Instantiates resources, such as user repository, and protocol handlers
2) Handles interactions between components
3) Provides container services for Mailets

Version:
This is $Revision: 1.9 $
Author:
Federico Barbieri , Serge, Charles Benett

Field Summary
protected  Context myContext
          The Avalon context used by the instance
 
Fields inherited from interface org.apache.james.services.MailServer
ALL, MDA, ROLE
 
Constructor Summary
James()
           
 
Method Summary
 boolean addUser(String userName, String password)
          Adds a user to this mail server.
 void bounce(Mail mail, String message)
          This generates a response to the Return-Path address, or the address of the message's sender if the Return-Path is not available.
 void bounce(Mail mail, String message, MailAddress bouncer)
          This generates a response to the Return-Path address, or the address of the message's sender if the Return-Path is not available.
 void compose(ComponentManager comp)
           
 void configure(Configuration conf)
           
 void contextualize(Context context)
           
 Object getAttribute(String key)
          Returns the mailet container attribute with the given name, or null if there is no attribute by that name.
 Iterator getAttributeNames()
          Returns an Iterator containing the attribute names available within this mailet context.
 String getId()
          Return a new mail id.
 Collection getMailServers(String host)
          Get the prioritized list of mail servers for a given host.
 int getMajorVersion()
          Return the major version number for the server
 int getMinorVersion()
          Return the minor version number for the server
 MailAddress getPostmaster()
          Returns the address of the postmaster for this server.
 String getServerInfo()
          Return the type of the server
 MailRepository getUserInbox(String userName)
          Retrieve the mail repository for a user For POP3 server only - at the moment.
 void initialize()
           
 boolean isLocalServer(String serverName)
          Check whether the mail domain in question is to be handled by this server.
 boolean isLocalUser(String name)
          Returns whether that account has a local inbox on this server
 void log(String message)
          Log a message to the Mailet logger
 void log(String message, Throwable t)
          Log a message and a Throwable to the Mailet logger
static void main(String[] args)
          The main method.
 void removeAttribute(String key)
          Removes the attribute with the given name from the mailet context.
 void sendMail(Mail mail)
          Place a mail on the spool for processing
 void sendMail(MailAddress sender, Collection recipients, InputStream msg)
          Place a mail on the spool for processing
 void sendMail(MailAddress sender, Collection recipients, MimeMessage message)
          Place a mail on the spool for processing
 void sendMail(MailAddress sender, Collection recipients, MimeMessage message, String state)
          Place a mail on the spool for processing
 void sendMail(MimeMessage message)
          Place a mail on the spool for processing
 void setAttribute(String key, Object object)
          Binds an object to a given attribute name in this mailet context.
 void storeMail(MailAddress sender, MailAddress recipient, MimeMessage message)
          Stores mail into local accounts (POP3 by default)
 
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
 

Field Detail

myContext

protected Context myContext
The Avalon context used by the instance

Constructor Detail

James

public James()
Method Detail

contextualize

public void contextualize(Context context)
Specified by:
contextualize in interface Contextualizable
See Also:
Contextualizable.contextualize(Context)

compose

public void compose(ComponentManager comp)
Specified by:
compose in interface Composable
See Also:
Composable.compose(ComponentManager)

configure

public void configure(Configuration conf)
Specified by:
configure in interface Configurable
See Also:
Configurable.configure(Configuration)

initialize

public void initialize()
                throws Exception
Specified by:
initialize in interface Initializable
Exception
See Also:
Initializable.initialize()

sendMail

public void sendMail(MimeMessage message)
              throws MessagingException
Place a mail on the spool for processing

Specified by:
sendMail in interface MailServer
Parameters:
message - the message to send
Throws:
MessagingException - if an exception is caught while placing the mail on the spool

sendMail

public void sendMail(MailAddress sender,
                     Collection recipients,
                     MimeMessage message)
              throws MessagingException
Place a mail on the spool for processing

Specified by:
sendMail in interface MailServer
Parameters:
sender - the sender of the mail
recipients - the recipients of the mail
message - the message to send
Throws:
MessagingException - if an exception is caught while placing the mail on the spool

sendMail

public void sendMail(MailAddress sender,
                     Collection recipients,
                     MimeMessage message,
                     String state)
              throws MessagingException
Place a mail on the spool for processing

Specified by:
sendMail in interface MailetContext
Parameters:
sender - the sender of the mail
recipients - the recipients of the mail
message - the message to send
state - the state of the message
Throws:
MessagingException - if an exception is caught while placing the mail on the spool

sendMail

public void sendMail(MailAddress sender,
                     Collection recipients,
                     InputStream msg)
              throws MessagingException
Place a mail on the spool for processing

Specified by:
sendMail in interface MailServer
Parameters:
sender - the sender of the mail
recipients - the recipients of the mail
msg - an InputStream containing the message
Throws:
MessagingException - if an exception is caught while placing the mail on the spool

sendMail

public void sendMail(Mail mail)
              throws MessagingException
Place a mail on the spool for processing

Specified by:
sendMail in interface MailServer
Parameters:
mail - the mail to place on the spool
Throws:
MessagingException - if an exception is caught while placing the mail on the spool

getUserInbox

public MailRepository getUserInbox(String userName)

Retrieve the mail repository for a user

For POP3 server only - at the moment.

Specified by:
getUserInbox in interface MailServer
Parameters:
userName - the name of the user whose inbox is to be retrieved
Returns:
the POP3 inbox for the user

getId

public String getId()
Return a new mail id.

Specified by:
getId in interface MailServer
Returns:
a new mail id

main

public static void main(String[] args)
The main method. Should never be invoked, as James must be called from within an Avalon framework container.

Parameters:
args - the command line arguments

getMailServers

public Collection getMailServers(String host)

Get the prioritized list of mail servers for a given host.

TODO: This needs to be made a more specific ordered subtype of Collection.

Specified by:
getMailServers in interface MailetContext
Parameters:
host -
Returns:
a Collection of Strings of hostnames, sorted by priority

getAttribute

public Object getAttribute(String key)
Description copied from interface: MailetContext
Returns the mailet container attribute with the given name, or null if there is no attribute by that name. An attribute allows a mailet container to give the mailet additional information not already provided by this interface. See * your server documentation for information about its attributes. A list of supported attributes can be retrieved using getAttributeNames.

The attribute is returned as a java.lang.Object or some subclass. Attribute names should follow the same convention as package names. The Java Mailet API specification reserves names matching java.*, javax.*, and sun.*

Specified by:
getAttribute in interface MailetContext
Parameters:
key - - a String specifying the name of the attribute
Returns:
an Object containing the value of the attribute, or null if no attribute exists matching the given name

setAttribute

public void setAttribute(String key,
                         Object object)
Description copied from interface: MailetContext
Binds an object to a given attribute name in this mailet context. If the name specified is already used for an attribute, this method will remove the old attribute and bind the name to the new attribute.

Attribute names should follow the same convention as package names. The Java Mailet API specification reserves names matching java.*, javax.*, and sun.*.

Specified by:
setAttribute in interface MailetContext
Parameters:
key - - a String specifying the name of the attribute
object - - an Object representing the attribute to be bound

removeAttribute

public void removeAttribute(String key)
Description copied from interface: MailetContext
Removes the attribute with the given name from the mailet context. After removal, subsequent calls to getAttribute(java.lang.String) to retrieve the attribute's value will return null.

Specified by:
removeAttribute in interface MailetContext
Parameters:
key - - a String specifying the name of the attribute to be removed

getAttributeNames

public Iterator getAttributeNames()
Description copied from interface: MailetContext
Returns an Iterator containing the attribute names available within this mailet context. Use the getAttribute(java.lang.String) method with an attribute name to get the value of an attribute.

Specified by:
getAttributeNames in interface MailetContext
Returns:
an Iterator of attribute names

bounce

public void bounce(Mail mail,
                   String message)
            throws MessagingException
This generates a response to the Return-Path address, or the address of the message's sender if the Return-Path is not available. Note that this is different than a mail-client's reply, which would use the Reply-To or From header. This will send the bounce with the server's postmaster as the sender.

Specified by:
bounce in interface MailetContext
Parameters:
mail - - the message that is to be bounced and sender to whom to return the message
message - - a descriptive message as to why the message bounced
MessagingException

bounce

public void bounce(Mail mail,
                   String message,
                   MailAddress bouncer)
            throws MessagingException
This generates a response to the Return-Path address, or the address of the message's sender if the Return-Path is not available. Note that this is different than a mail-client's reply, which would use the Reply-To or From header.

Specified by:
bounce in interface MailetContext
Parameters:
mail - - the message that is to be bounced and sender to whom to return the message
message - - a descriptive message as to why the message bounced
bouncer - - the address to give as the sender of the bounced message
MessagingException

isLocalUser

public boolean isLocalUser(String name)
Returns whether that account has a local inbox on this server

Specified by:
isLocalUser in interface MailetContext
Parameters:
name - the name to be checked
Returns:
whether the account has a local inbox

getPostmaster

public MailAddress getPostmaster()
Returns the address of the postmaster for this server.

Specified by:
getPostmaster in interface MailetContext
Returns:
the MailAddress for the postmaster

storeMail

public void storeMail(MailAddress sender,
                      MailAddress recipient,
                      MimeMessage message)
               throws MessagingException
Description copied from interface: MailetContext
Stores mail into local accounts (POP3 by default)

Specified by:
storeMail in interface MailetContext
Parameters:
sender - - the sender of the incoming message
recipient - - the user who is receiving this message (as a complete email address)
message - - the MimeMessage to store in a local mailbox
Throws:
MessagingException - - if the message fails to parse

getMajorVersion

public int getMajorVersion()
Return the major version number for the server

Specified by:
getMajorVersion in interface MailetContext
Returns:
the major vesion number for the server

getMinorVersion

public int getMinorVersion()
Return the minor version number for the server

Specified by:
getMinorVersion in interface MailetContext
Returns:
the minor vesion number for the server

isLocalServer

public boolean isLocalServer(String serverName)
Check whether the mail domain in question is to be handled by this server.

Specified by:
isLocalServer in interface MailServer
Parameters:
serverName - the name of the server to check
Returns:
whether the server is local

getServerInfo

public String getServerInfo()
Return the type of the server

Specified by:
getServerInfo in interface MailetContext
Returns:
the type of the server

log

public void log(String message)
Log a message to the Mailet logger

Specified by:
log in interface MailetContext
Parameters:
message - the message to pass to the Mailet logger

log

public void log(String message,
                Throwable t)
Log a message and a Throwable to the Mailet logger

Specified by:
log in interface MailetContext
Parameters:
message - the message to pass to the Mailet logger
t - the Throwable to be logged

addUser

public boolean addUser(String userName,
                       String password)
Adds a user to this mail server. Currently just adds user to a UsersRepository.

Specified by:
addUser in interface JamesMBean
Parameters:
userName - String representing user name, that is the portion of an email address before the '@'.
password - String plaintext password
Returns:
boolean true if user added succesfully, else false.


"Copyright © 1999-2002 Apache Jakarta Project. All Rights Reserved."