org.apache.james
Class James

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

public class James
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements org.apache.avalon.phoenix.Block, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Initializable, MailServer, MailetContext

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

Author:
Federico Barbieri
, Serge , Charles Benett This is $Revision: 1.22 $ Committed on $Date: 2002/04/18 13:39:34 $ by: $Author: serge $

Field Summary
protected  org.apache.avalon.phoenix.BlockContext blockContext
           
 
Fields inherited from interface org.apache.james.services.MailServer
ALL, MDA, ROLE
 
Constructor Summary
James()
           
 
Method Summary
 boolean addUser(java.lang.String userName, java.lang.String password)
          Adds a user to this mail server.
 void bounce(Mail mail, java.lang.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, java.lang.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(org.apache.avalon.framework.component.ComponentManager comp)
          Override compose method of AbstractBlock to create new ComponentManager object
 void configure(org.apache.avalon.framework.configuration.Configuration conf)
           
 void contextualize(org.apache.avalon.framework.context.Context context)
           
 java.lang.Object getAttribute(java.lang.String key)
          Returns the mailet container attribute with the given name, or null if there is no attribute by that name.
 java.util.Iterator getAttributeNames()
          Returns an Iterator containing the attribute names available within this mailet context.
 java.lang.String getId()
           
 java.util.Collection getMailServers(java.lang.String host)
          Returns a Collection of Strings of hostnames or ip addresses that are specified as mail server listeners for the given hostname.
 int getMajorVersion()
          Returns the minor version of the Mailet API that this mailet container supports.
 int getMinorVersion()
          Returns the minor version of the Mailet API that this mailet container supports.
 MailAddress getPostmaster()
          Returns the address of the postmaster for this server.
 java.lang.String getServerInfo()
          Returns the name and version of the mailet container on which the mailet is running.
 MailRepository getUserInbox(java.lang.String userName)
          For POP3 server only - at the momment.
 void initialize()
           
 boolean isLocalServer(java.lang.String serverName)
          Checks if a server is serviced by mail context
 boolean isLocalUser(java.lang.String name)
          Returns whether that account has a local inbox on this server
 void log(java.lang.String message)
          Writes the specified message to a mailet log file, usually an event log.
 void log(java.lang.String message, java.lang.Throwable t)
          Writes an explanatory message and a stack trace for a given Throwable exception to the mailet log file.
static void main(java.lang.String[] args)
           
 void removeAttribute(java.lang.String key)
          Removes the attribute with the given name from the mailet context.
 void sendMail(Mail mail)
          Pass a Mail to this MailServer for processing
 void sendMail(MailAddress sender, java.util.Collection recipients, java.io.InputStream msg)
          Pass a MimeMessage to this MailServer for processing
 void sendMail(MailAddress sender, java.util.Collection recipients, javax.mail.internet.MimeMessage message)
          Pass a MimeMessage to this MailServer for processing
 void sendMail(MailAddress sender, java.util.Collection recipients, javax.mail.internet.MimeMessage message, java.lang.String state)
          Send an outgoing message to the top of this mailet container queue for the appropriate processor that is specified.
 void sendMail(javax.mail.internet.MimeMessage message)
          Send an outgoing message to the top of this mailet container's root queue.
 void setAttribute(java.lang.String key, java.lang.Object object)
          Binds an object to a given attribute name in this mailet context.
 void storeMail(MailAddress sender, MailAddress recipient, javax.mail.internet.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

blockContext

protected org.apache.avalon.phoenix.BlockContext blockContext
Constructor Detail

James

public James()
Method Detail

contextualize

public void contextualize(org.apache.avalon.framework.context.Context context)
Specified by:
contextualize in interface org.apache.avalon.framework.context.Contextualizable

configure

public void configure(org.apache.avalon.framework.configuration.Configuration conf)
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable

compose

public void compose(org.apache.avalon.framework.component.ComponentManager comp)
Override compose method of AbstractBlock to create new ComponentManager object

Specified by:
compose in interface org.apache.avalon.framework.component.Composable

initialize

public void initialize()
                throws java.lang.Exception
Specified by:
initialize in interface org.apache.avalon.framework.activity.Initializable
java.lang.Exception

sendMail

public void sendMail(javax.mail.internet.MimeMessage message)
              throws javax.mail.MessagingException
Description copied from interface: MailetContext
Send an outgoing message to the top of this mailet container's root queue. This is the equivalent of opening an SMTP session to localhost. This uses sender and recipients as specified in the message itself.

Specified by:
sendMail in interface MailetContext
Parameters:
message - - the MimeMessage of the headers and body content of the outgoing message
Throws:
javax.mail.MessagingException - - if the message fails to parse

sendMail

public void sendMail(MailAddress sender,
                     java.util.Collection recipients,
                     javax.mail.internet.MimeMessage message)
              throws javax.mail.MessagingException
Description copied from interface: MailServer
Pass a MimeMessage to this MailServer for processing

Specified by:
sendMail in interface MailServer
Parameters:
sender - - the sender of the message
recipients - - a Collection of String objects of recipients
message - - the MimeMessage of the headers and body content of the outgoing message
Throws:
javax.mail.MessagingException - - if the message fails to parse

sendMail

public void sendMail(MailAddress sender,
                     java.util.Collection recipients,
                     javax.mail.internet.MimeMessage message,
                     java.lang.String state)
              throws javax.mail.MessagingException
Description copied from interface: MailetContext
Send an outgoing message to the top of this mailet container queue for the appropriate processor that is specified.

Specified by:
sendMail in interface MailetContext
Parameters:
sender - - the sender of the message
recipients - - a Collection of MailAddress objects of recipients
message - - the MimeMessage of the headers and body content of the outgoing message
state - - the state of the message, indicates which processor to use
Throws:
javax.mail.MessagingException - - if the message fails to parse

sendMail

public void sendMail(MailAddress sender,
                     java.util.Collection recipients,
                     java.io.InputStream msg)
              throws javax.mail.MessagingException
Description copied from interface: MailServer
Pass a MimeMessage to this MailServer for processing

Specified by:
sendMail in interface MailServer
Parameters:
sender - - the sender of the message
recipients - - a Collection of String objects of recipients
msg - - an InputStream containing the headers and body content of the outgoing message
Throws:
javax.mail.MessagingException - - if the message fails to parse

sendMail

public void sendMail(Mail mail)
              throws javax.mail.MessagingException
Description copied from interface: MailServer
Pass a Mail to this MailServer for processing

Specified by:
sendMail in interface MailServer
Throws:
javax.mail.MessagingException - - if the message fails to parse

getUserInbox

public MailRepository getUserInbox(java.lang.String userName)
For POP3 server only - at the momment.

Specified by:
getUserInbox in interface MailServer

getId

public java.lang.String getId()
Specified by:
getId in interface MailServer

main

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

getMailServers

public java.util.Collection getMailServers(java.lang.String host)
Description copied from interface: MailetContext
Returns a Collection of Strings of hostnames or ip addresses that are specified as mail server listeners for the given hostname. This is done using MX records, and the hostnames or ip addresses are returned sorted by MX priority.

Specified by:
getMailServers in interface MailetContext
Parameters:
host - - the domain name for which to find mail servers
Returns:
a Collection of Strings of hostnames, sorted by priority

getAttribute

public java.lang.Object getAttribute(java.lang.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(java.lang.String key,
                         java.lang.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(java.lang.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 java.util.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,
                   java.lang.String message)
            throws javax.mail.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
javax.mail.MessagingException

bounce

public void bounce(Mail mail,
                   java.lang.String message,
                   MailAddress bouncer)
            throws javax.mail.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
javax.mail.MessagingException

isLocalUser

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

Specified by:
isLocalUser in interface MailetContext
Parameters:
name - - user identifier.
Returns:
true if the acount is a local account

getPostmaster

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

Specified by:
getPostmaster in interface MailetContext
Returns:
a MailAddress of the Postmaster's address

storeMail

public void storeMail(MailAddress sender,
                      MailAddress recipient,
                      javax.mail.internet.MimeMessage message)
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

getMajorVersion

public int getMajorVersion()
Description copied from interface: MailetContext
Returns the minor version of the Mailet API that this mailet container supports. All implementations that comply with Version 1.2 must have this method return the integer 1.

Specified by:
getMajorVersion in interface MailetContext
Returns:
1

getMinorVersion

public int getMinorVersion()
Description copied from interface: MailetContext
Returns the minor version of the Mailet API that this mailet container supports. All implementations that comply with Version 1.2 must have this method return the integer 2.

Specified by:
getMinorVersion in interface MailetContext
Returns:
2

isLocalServer

public boolean isLocalServer(java.lang.String serverName)
Description copied from interface: MailServer
Checks if a server is serviced by mail context

Specified by:
isLocalServer in interface MailServer
Parameters:
serverName - - name of server.
Returns:
true if server is local, i.e. serviced by this mail context

getServerInfo

public java.lang.String getServerInfo()
Description copied from interface: MailetContext
Returns the name and version of the mailet container on which the mailet is running.

The form of the returned string is servername/versionnumber. For example, JAMES may return the string JAMES/1.2.

The mailet container may return other optional information after the primary string in parentheses, for example, JAMES/1.2 (JDK 1.3.0; Windows NT 4.0 x86).

Specified by:
getServerInfo in interface MailetContext
Returns:
a String containing at least the mailet container name and version number

log

public void log(java.lang.String message)
Description copied from interface: MailetContext
Writes the specified message to a mailet log file, usually an event log. The name and type of the mailet log file is specific to the mailet container.

Specified by:
log in interface MailetContext

log

public void log(java.lang.String message,
                java.lang.Throwable t)
Description copied from interface: MailetContext
Writes an explanatory message and a stack trace for a given Throwable exception to the mailet log file.

Specified by:
log in interface MailetContext
Parameters:
message - - a String that describes the error or exception

addUser

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

Specified by:
addUser in interface MailServer
Parameters:
userName - String representing user name, that is the portion of an email address before the '@'.
password - String plaintext password


"Copyright © 2001 Apache Jakarta Project. All Rights Reserved."