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.logger.LogEnabled, org.apache.avalon.framework.service.Serviceable, MailServer, org.apache.mailet.MailetContext

public class James
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements org.apache.avalon.framework.service.Serviceable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Initializable, MailServer, org.apache.mailet.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: 722820 $

Field Summary
protected  org.apache.mailet.Mailet localDeliveryMailet
          Currently used by storeMail to avoid code duplication (we moved store logic to that mailet).
 
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(org.apache.mailet.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(org.apache.mailet.Mail mail, java.lang.String message, org.apache.mailet.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)
           
 java.lang.Object getAttribute(java.lang.String key)
           
 java.util.Iterator getAttributeNames()
           
 java.lang.String getDefaultDomain()
          Return the default domain which will get used to deliver mail to if only the localpart was given on rcpt to.
 java.lang.String getHelloName()
          Return the helloName which should use for all services by default
 java.lang.String getId()
          Note that this method ensures that James cannot be run in a distributed fashion.
 java.util.Collection getMailServers(java.lang.String host)
           
 int getMajorVersion()
           
 int getMinorVersion()
           
 org.apache.mailet.MailAddress getPostmaster()
           
 java.lang.String getServerInfo()
           
 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 primary mailbox for userName.
 void initialize()
           
 boolean isLocalEmail(org.apache.mailet.MailAddress mailAddress)
           
 boolean isLocalServer(java.lang.String serverName)
          Checks if a server is serviced by mail context
 boolean isLocalUser(java.lang.String name)
           
 void log(java.lang.String message)
           
 void log(java.lang.String message, java.lang.Throwable t)
           
protected  DNSService lookupDNSServer()
           
static void main(java.lang.String[] args)
          The main method.
 void removeAttribute(java.lang.String key)
           
 void sendMail(org.apache.mailet.Mail mail)
          Pass a Mail to this MailServer for processing
 void sendMail(org.apache.mailet.MailAddress sender, java.util.Collection recipients, java.io.InputStream msg)
          Pass a MimeMessage to this MailServer for processing
 void sendMail(org.apache.mailet.MailAddress sender, java.util.Collection recipients, javax.mail.internet.MimeMessage message)
          Pass a MimeMessage to this MailServer for processing
 void sendMail(org.apache.mailet.MailAddress sender, java.util.Collection recipients, javax.mail.internet.MimeMessage message, java.lang.String state)
           
 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)
           
 void setLocalusers(UsersRepository localusers)
          Set the UsersRepository to use
 void setSpool(SpoolRepository spool)
          Set the SpoolRepository to use
 void setStore(org.apache.avalon.cornerstone.services.store.Store store)
          Set Store to use
 void storeMail(org.apache.mailet.MailAddress sender, org.apache.mailet.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.
 boolean supportVirtualHosting()
          Return true if virtualHosting support is enabled, otherwise false
 
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

localDeliveryMailet

protected org.apache.mailet.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

service

public void service(org.apache.avalon.framework.service.ServiceManager comp)
             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:
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()

setStore

public void setStore(org.apache.avalon.cornerstone.services.store.Store store)
Set Store to use

Parameters:
store - the Store to use

setSpool

public void setSpool(SpoolRepository spool)
Set the SpoolRepository to use

Parameters:
spool - the SpoleRepository to use

setLocalusers

public void setLocalusers(UsersRepository localusers)
Set the UsersRepository to use

Parameters:
localusers - the UserRepository to use

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 org.apache.mailet.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(org.apache.mailet.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
Specified by:
sendMail in interface org.apache.mailet.MailetContext
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
See Also:
MailServer.sendMail(MailAddress, Collection, MimeMessage)

sendMail

public void sendMail(org.apache.mailet.MailAddress sender,
                     java.util.Collection recipients,
                     javax.mail.internet.MimeMessage message,
                     java.lang.String state)
              throws javax.mail.MessagingException
Specified by:
sendMail in interface org.apache.mailet.MailetContext
Throws:
javax.mail.MessagingException
See Also:
MailetContext.sendMail(MailAddress, Collection, MimeMessage, String)

sendMail

public void sendMail(org.apache.mailet.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
See Also:
MailServer.sendMail(MailAddress, Collection, InputStream)

sendMail

public void sendMail(org.apache.mailet.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
Specified by:
sendMail in interface org.apache.mailet.MailetContext
Parameters:
mail - the Mail to be processed
Throws:
javax.mail.MessagingException
See Also:
MailServer.sendMail(Mail)

getUserInbox

public MailRepository getUserInbox(java.lang.String userName)
Description copied from interface: MailServer
Retrieve the primary mailbox for userName. For POP3 style stores this is their (sole) mailbox.

Specified by:
getUserInbox in interface MailServer
Parameters:
userName - - the name of the user
Returns:
a reference to an initialised mailbox
See Also:
MailServer.getUserInbox(java.lang.String)

getId

public java.lang.String getId()

Note that this method ensures that James cannot be run in a distributed fashion.

Two instances may return the same ID. There are various ways that this could be fixed. The most obvious would be to add a unique prefix. The best approach would be for each instance to be configured with a name which would then be combined with the network address (for example, james.name@mail.example.org) to create a unique James instance identifier.

Alternatively, using a data store backed identifier (for example, from a sequence when DB backed) should be enough to gaurantee uniqueness. This would imply that the Mail interface or the spool store should be responsible for creating new Mail implementations with ID preassigned.

It would be useful for each James cluster to have a unique name. Perhaps a random number could be generated by the spool store upon first initialisation.

This ID is most likely to be used as message ID so this is probably useful in any case.

Specified by:
getId in interface MailServer
Returns:
the new identifier
See Also:
MailServer.getId()

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)
Specified by:
getMailServers in interface org.apache.mailet.MailetContext
See Also:
MailetContext.getMailServers(String)

getAttribute

public java.lang.Object getAttribute(java.lang.String key)
Specified by:
getAttribute in interface org.apache.mailet.MailetContext
See Also:
MailetContext.getAttribute(java.lang.String)

setAttribute

public void setAttribute(java.lang.String key,
                         java.lang.Object object)
Specified by:
setAttribute in interface org.apache.mailet.MailetContext
See Also:
MailetContext.setAttribute(java.lang.String, java.lang.Object)

removeAttribute

public void removeAttribute(java.lang.String key)
Specified by:
removeAttribute in interface org.apache.mailet.MailetContext
See Also:
MailetContext.removeAttribute(java.lang.String)

getAttributeNames

public java.util.Iterator getAttributeNames()
Specified by:
getAttributeNames in interface org.apache.mailet.MailetContext
See Also:
MailetContext.getAttributeNames()

bounce

public void bounce(org.apache.mailet.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 org.apache.mailet.MailetContext
Throws:
javax.mail.MessagingException
See Also:
MailetContext.bounce(Mail, String)

bounce

public void bounce(org.apache.mailet.Mail mail,
                   java.lang.String message,
                   org.apache.mailet.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 org.apache.mailet.MailetContext
Throws:
javax.mail.MessagingException
See Also:
MailetContext.bounce(Mail, String, MailAddress)

isLocalUser

public boolean isLocalUser(java.lang.String name)
Specified by:
isLocalUser in interface org.apache.mailet.MailetContext
See Also:
MailetContext.isLocalUser(String)

isLocalEmail

public boolean isLocalEmail(org.apache.mailet.MailAddress mailAddress)
Specified by:
isLocalEmail in interface org.apache.mailet.MailetContext
See Also:
MailetContext.isLocalEmail(org.apache.mailet.MailAddress)

getPostmaster

public org.apache.mailet.MailAddress getPostmaster()
Specified by:
getPostmaster in interface org.apache.mailet.MailetContext
See Also:
MailetContext.getPostmaster()

getMajorVersion

public int getMajorVersion()
Specified by:
getMajorVersion in interface org.apache.mailet.MailetContext
See Also:
MailetContext.getMajorVersion()

getMinorVersion

public int getMinorVersion()
Specified by:
getMinorVersion in interface org.apache.mailet.MailetContext
See Also:
MailetContext.getMinorVersion()

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
Specified by:
isLocalServer in interface org.apache.mailet.MailetContext
Parameters:
serverName - - name of server.
Returns:
true if server is local, i.e. serviced by this mail context
See Also:
MailServer.isLocalServer(java.lang.String)

getServerInfo

public java.lang.String getServerInfo()
Specified by:
getServerInfo in interface org.apache.mailet.MailetContext
See Also:
MailetContext.getServerInfo()

log

public void log(java.lang.String message)
Specified by:
log in interface org.apache.mailet.MailetContext
See Also:
MailetContext.log(java.lang.String)

log

public void log(java.lang.String message,
                java.lang.Throwable t)
Specified by:
log in interface org.apache.mailet.MailetContext
See Also:
MailetContext.log(java.lang.String, java.lang.Throwable)

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 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 org.apache.mailet.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:
DNSService.getSMTPHostAddresses(String)

lookupDNSServer

protected DNSService lookupDNSServer()

storeMail

public void storeMail(org.apache.mailet.MailAddress sender,
                      org.apache.mailet.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 org.apache.mailet.MailetContext
Throws:
javax.mail.MessagingException
See Also:
MailetContext.storeMail(org.apache.mailet.MailAddress, org.apache.mailet.MailAddress, javax.mail.internet.MimeMessage)

supportVirtualHosting

public boolean supportVirtualHosting()
Description copied from interface: MailServer
Return true if virtualHosting support is enabled, otherwise false

Specified by:
supportVirtualHosting in interface MailServer
Returns:
true or false
See Also:
MailServer.supportVirtualHosting()

getDefaultDomain

public java.lang.String getDefaultDomain()
Description copied from interface: MailServer
Return the default domain which will get used to deliver mail to if only the localpart was given on rcpt to.

Specified by:
getDefaultDomain in interface MailServer
Returns:
the defaultdomain
See Also:
MailServer.getDefaultDomain()

getHelloName

public java.lang.String getHelloName()
Description copied from interface: MailServer
Return the helloName which should use for all services by default

Specified by:
getHelloName in interface MailServer
Returns:
the helloName
See Also:
MailServer.getHelloName()


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