org.apache.james
Class James

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.james.James
All Implemented Interfaces:
org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.framework.service.Serviceable, JamesMBean, MailServer, MailetContext

public class James
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.service.Serviceable, org.apache.avalon.framework.configuration.Configurable, JamesMBean, 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

Version:
This is $Revision: 494012 $

Field Summary
protected  Mailet localDeliveryMailet
          Currently used by storeMail to avoid code duplication (we moved store logic to that mailet).
protected  org.apache.avalon.framework.context.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(java.lang.String userName, java.lang.String password)
          Deprecated. we deprecated this in the MailServer interface and this is an implementation this component depends already depends on a UsersRepository: clients could directly use the addUser of the usersRepository.
 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 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()
          Return a new mail id.
 java.util.Collection getMailServers(java.lang.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.
 java.lang.String getServerInfo()
          Return the type of the server
 java.util.Iterator getSMTPHostAddresses(java.lang.String domainName)
          Performs DNS lookups as needed to find servers which should or might support SMTP.
 MailRepository getUserInbox(java.lang.String userName)
          Retrieve the mail repository for a user
 void initialize()
           
 boolean isLocalServer(java.lang.String serverName)
          Check whether the mail domain in question is to be handled by this server.
 boolean isLocalUser(java.lang.String name)
          Returns whether that account has a local inbox on this server
 void log(java.lang.String message)
          Log a message to the Mailet logger
 void log(java.lang.String message, java.lang.Throwable t)
          Log a message and a Throwable to the Mailet logger
static void main(java.lang.String[] args)
          The main method.
 void removeAttribute(java.lang.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, java.util.Collection recipients, java.io.InputStream msg)
          Place a mail on the spool for processing
 void sendMail(MailAddress sender, java.util.Collection recipients, javax.mail.internet.MimeMessage message)
          Place a mail on the spool for processing
 void sendMail(MailAddress sender, java.util.Collection recipients, javax.mail.internet.MimeMessage message, java.lang.String state)
          Place a mail on the spool for processing
 void sendMail(javax.mail.internet.MimeMessage message)
          Place a mail on the spool for processing
 void service(org.apache.avalon.framework.service.ServiceManager comp)
           
 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 msg)
          Deprecated. since 2.2.0 look at the LocalDelivery code to find out how to do the local delivery.
 
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 org.apache.avalon.framework.context.Context myContext
The Avalon context used by the instance


localDeliveryMailet

protected Mailet localDeliveryMailet
Currently used by storeMail to avoid code duplication (we moved store logic to that mailet). TODO We should remove this and its initialization when we remove storeMail method.

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
See Also:
Contextualizable.contextualize(Context)

service

public void service(org.apache.avalon.framework.service.ServiceManager comp)
Specified by:
service in interface org.apache.avalon.framework.service.Serviceable
See Also:
Serviceable.service(ServiceManager)

configure

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

initialize

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

sendMail

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

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

sendMail

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

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

sendMail

public void sendMail(MailAddress sender,
                     java.util.Collection recipients,
                     javax.mail.internet.MimeMessage message,
                     java.lang.String state)
              throws javax.mail.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:
javax.mail.MessagingException - if an exception is caught while placing the mail on the spool

sendMail

public void sendMail(MailAddress sender,
                     java.util.Collection recipients,
                     java.io.InputStream msg)
              throws javax.mail.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:
javax.mail.MessagingException - if an exception is caught while placing the mail on the spool

sendMail

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

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

getUserInbox

public MailRepository getUserInbox(java.lang.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 java.lang.String getId()
Return a new mail id.

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

main

public static void main(java.lang.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 java.util.Collection getMailServers(java.lang.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 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
Throws:
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. Bounced messages are attached in their entirety (headers and content) and the resulting MIME part type is "message/rfc822". The attachment to the subject of the original message (or "No Subject" if there is no subject in the original message) There are outstanding issues with this implementation revolving around handling of the return-path header. MIME layout of the bounce message: multipart (mixed)/ contentPartRoot (body) = mpContent (alternative)/ part (body) = message part (body) = original

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
Throws:
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 - 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

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(java.lang.String serverName)
Check whether the mail domain in question is to be handled by this server.

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

getServerInfo

public java.lang.String getServerInfo()
Return the type of the server

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

log

public void log(java.lang.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(java.lang.String message,
                java.lang.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(java.lang.String userName,
                       java.lang.String password)
Deprecated. we deprecated this in the MailServer interface and this is an implementation this component depends already depends on a UsersRepository: clients could directly use the addUser of the usersRepository.

Adds a user to this mail server. Currently just adds user to a UsersRepository.

Specified by:
addUser in interface JamesMBean
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
Returns:
boolean true if user added succesfully, else false.

getSMTPHostAddresses

public java.util.Iterator getSMTPHostAddresses(java.lang.String domainName)
Performs DNS lookups as needed to find servers which should or might support SMTP. Returns an Iterator over HostAddress, a specialized subclass of javax.mail.URLName, which provides location information for servers that are specified as mail handlers for the given hostname. This is done using MX records, and the HostAddress instances are returned sorted by MX priority. If no host is found for domainName, the Iterator returned will be empty and the first call to hasNext() will return false.

Specified by:
getSMTPHostAddresses in interface MailetContext
Parameters:
domainName - - the domain for which to find mail servers
Returns:
an Iterator over HostAddress instances, sorted by priority
Since:
Mailet API v2.2.0a16-unstable
See Also:
org.apache.james.DNSServer#getSMTPHostAddresses(String)

storeMail

public void storeMail(MailAddress sender,
                      MailAddress recipient,
                      javax.mail.internet.MimeMessage msg)
               throws javax.mail.MessagingException
Deprecated. since 2.2.0 look at the LocalDelivery code to find out how to do the local delivery.

This method has been moved to LocalDelivery (the only client of the method). Now we can safely remove it from the Mailet API and from this implementation of MailetContext. The local field localDeliveryMailet will be removed when we remove the storeMail method.

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)
msg - - the MimeMessage to store in a local mailbox
Throws:
javax.mail.MessagingException - - if the message fails to parse
See Also:
MailetContext.storeMail(org.apache.mailet.MailAddress, org.apache.mailet.MailAddress, javax.mail.internet.MimeMessage)


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