SK.gnome.dwarf.mail.smtp
Class SMTPServer

java.lang.Object
  extended bySK.gnome.dwarf.GenericService
      extended bySK.gnome.dwarf.GenericServer
          extended bySK.gnome.dwarf.thread.ThreadServer
              extended bySK.gnome.dwarf.thread.MultiThreadServer
                  extended bySK.gnome.dwarf.tcpip.TCPIPServer
                      extended bySK.gnome.dwarf.mail.MailServer
                          extended bySK.gnome.dwarf.mail.smtp.SMTPServer
All Implemented Interfaces:
MailAgentContext, SK.gnome.dwarf.Reportable, java.lang.Runnable, SK.gnome.dwarf.Server, SK.gnome.dwarf.Service

public class SMTPServer
extends MailServer
implements MailAgentContext

This is the main SMTP server object.


Field Summary
 
Fields inherited from class SK.gnome.dwarf.mail.MailServer
hosts
 
Fields inherited from class SK.gnome.dwarf.tcpip.TCPIPServer
sslContext
 
Fields inherited from class SK.gnome.dwarf.thread.MultiThreadServer
counter
 
Fields inherited from class SK.gnome.dwarf.thread.ThreadServer
daemon, thread
 
Fields inherited from class SK.gnome.dwarf.GenericService
initParameters, parent
 
Fields inherited from interface SK.gnome.dwarf.Service
INITIALIZED, LOG_DEBUG, LOG_ERROR, LOG_FATAL, LOG_INFO, LOG_TRACE, LOG_WARN, LOG_XFER, SHUTDOWN, STARTED, STOPPED
 
Constructor Summary
SMTPServer(java.lang.String name)
          Creates a new SMTPServer.
 
Method Summary
 void addService(SK.gnome.dwarf.Service service)
          Adds the given service to the server.
 java.util.Collection expandAlias(SMTPMessage message, Recipient recipient)
          Expands the given alias recipient to collection of mail recipients.
 java.lang.String getHostName()
          Returns the full hostname of the server.
 SMTPMessage getMessageInstance()
          Creates a new SMTPMessage istance.
 void init(SK.gnome.dwarf.Server parent)
          Initializes the service.
 boolean isLocalHost(java.lang.String hostname)
          Finds out whether the given argument refers to a local mail host.
 boolean isLocalUser(java.lang.String user)
          Finds out whether the given argument refers to a local mail user.
 void listMessages(boolean details, java.io.PrintWriter pw)
          Lists all messages in the queue.
 void runQueue(java.lang.String node, boolean forceDelivery)
          Process the given queue node.
 void sendMessage(MimeMessageBuilder message)
          Sends the message.
 void sendMessage(SMTPMessage message, java.util.Collection recipients)
          Sends the message.
 void shutdown()
           
 void start()
           
 void storeMessage(java.lang.String user, java.lang.String folder, java.lang.String from, java.io.InputStream in)
          Stores the message to the given mail folder.
 
Methods inherited from class SK.gnome.dwarf.mail.MailServer
getACLStore, getMailHost, getMailHostByUser, getMailStore, getUserStore
 
Methods inherited from class SK.gnome.dwarf.tcpip.TCPIPServer
createSSLServerSocket, createSSLServerSocket, createSSLSocket, enqueue, finish, getRequestReadTimeout, getTCPRequest, isBlocking, isSSLConfigured, loop, report, setKeyPwd, setKeyStorePwd, setKeyStoreURL, setRegistrationQueueSize, setRequestClass, setSSLProtocol
 
Methods inherited from class SK.gnome.dwarf.thread.MultiThreadServer
dequeue, enableThread, getHandlerTimeout, setHandlerClass, setHandlerTimeout, setMaxHandlers, setMinHandlers, setQueueSize, setSingleRequest, wakeUpHandlers
 
Methods inherited from class SK.gnome.dwarf.thread.ThreadServer
finish, run, setDaemon, stop
 
Methods inherited from class SK.gnome.dwarf.GenericServer
addService, getAuthenticator, getLogger, getParameters, getService, getServices, getServices, removeService
 
Methods inherited from class SK.gnome.dwarf.GenericService
getAuthFacility, getFullName, getInitParameter, getInitParameterNames, getLogFacility, getName, getPrincipal, getShutdownTimeout, getState, log, log, login, logout, setAuthFacility, setInitParameters, setLogFacility, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface SK.gnome.dwarf.mail.smtp.proc.MailAgentContext
getMailStore, getUserStore
 
Methods inherited from interface SK.gnome.dwarf.Service
getFullName, getName, getState, log, log, login, logout
 

Constructor Detail

SMTPServer

public SMTPServer(java.lang.String name)
Creates a new SMTPServer.

The setHandlerClass(SMTPHandler.class) is invoked to set the initial handler class. That means the server will use SMTPHandler objects for handling the client connections by default.

Method Detail

addService

public void addService(SK.gnome.dwarf.Service service)
                throws SK.gnome.dwarf.ServiceException
Adds the given service to the server.

Specified by:
addService in interface SK.gnome.dwarf.Server
Overrides:
addService in class MailServer
Throws:
SK.gnome.dwarf.ServiceException

init

public void init(SK.gnome.dwarf.Server parent)
          throws SK.gnome.dwarf.ServiceException
Initializes the service.

Specified by:
init in interface SK.gnome.dwarf.Service
Overrides:
init in class MailServer
Throws:
SK.gnome.dwarf.ServiceException

shutdown

public void shutdown()
Specified by:
shutdown in interface SK.gnome.dwarf.Service

start

public void start()
           throws SK.gnome.dwarf.ServiceException
Specified by:
start in interface SK.gnome.dwarf.Service
Throws:
SK.gnome.dwarf.ServiceException

getHostName

public java.lang.String getHostName()
Description copied from interface: MailAgentContext
Returns the full hostname of the server.

This is also the name of the default mail host contained by the server.

Specified by:
getHostName in interface MailAgentContext
Returns:
the hostname of the server

isLocalHost

public boolean isLocalHost(java.lang.String hostname)
Description copied from interface: MailAgentContext
Finds out whether the given argument refers to a local mail host.

Specified by:
isLocalHost in interface MailAgentContext
Parameters:
hostname - the host name
Returns:
true if the given name refers to a local mail host, false otherwise

isLocalUser

public boolean isLocalUser(java.lang.String user)
                    throws MailException
Description copied from interface: MailAgentContext
Finds out whether the given argument refers to a local mail user.

The user argument may contain a domain part after the '@' character if it represents a virtual domain user.

The local part of the user argument is case-sensitive.

Specified by:
isLocalUser in interface MailAgentContext
Parameters:
user - the user name or mail address, if it is virtual user
Returns:
true if the given argument refers to a local mail user, false otherwise
Throws:
MailException - if an error occured

getMessageInstance

public SMTPMessage getMessageInstance()
                               throws MailException
Description copied from interface: MailAgentContext
Creates a new SMTPMessage istance.

The SMTPMessage object may be used to create and send a new mail message. It provides more precise control over the delivery process than the MimeMessageBuilder class.

Specified by:
getMessageInstance in interface MailAgentContext
Throws:
MailException

sendMessage

public void sendMessage(MimeMessageBuilder message)
                 throws java.io.IOException,
                        MailException
Description copied from interface: MailAgentContext
Sends the message.

The message is put to the mail queue directly, bypassing the network and SMTP protocol overhead.

Specified by:
sendMessage in interface MailAgentContext
Parameters:
message - the message to send
Throws:
java.io.IOException - if an I/O error occured
MailException - if an error occured

sendMessage

public void sendMessage(SMTPMessage message,
                        java.util.Collection recipients)
                 throws java.io.IOException,
                        MailException
Description copied from interface: MailAgentContext
Sends the message.

The message is put to the mail queue directly, bypassing the network and SMTP protocol overhead.

The recipients collection must contain Recipient objects, representing the actual message recipients.

Specified by:
sendMessage in interface MailAgentContext
Parameters:
message - the message to send
recipients - the message recipients represented by the Recipient objects
Throws:
MailException - if an error occured
java.io.IOException - if an I/O error occured

storeMessage

public void storeMessage(java.lang.String user,
                         java.lang.String folder,
                         java.lang.String from,
                         java.io.InputStream in)
                  throws java.io.IOException,
                         MailException
Description copied from interface: MailAgentContext
Stores the message to the given mail folder.

The unparsed message content will be read from the given in stream and stored to the local user's folder. The user argument may contain a domain part after the '@' character if it represents a virtual domain user. The from parameter specifies the sender's address (without the display name and comments) and will be used in setting the "Return-Path" header of the stored message, if the message has not been received via the SMTP protocol. If the from argument is null, this header will not be written at all.

This is a direct way how to store a message to the mail store, completely bypassing the queue and agent processing.

Specified by:
storeMessage in interface MailAgentContext
Parameters:
user - the local user name
folder - full name of the target mail folder
from - the From address or null
in - the input stream containing the raw message data
Throws:
java.io.IOException - if an I/O error occured
MailException - if an error occured

expandAlias

public java.util.Collection expandAlias(SMTPMessage message,
                                        Recipient recipient)
                                 throws MailException
Expands the given alias recipient to collection of mail recipients.

This method checks whether the given recipient represents an alias name and it will try to expand it to collection of other recipients. This mechanism offers a basic mail forwarding as well as simple mail distribution lists. The aliases are obtained from the particular SMTPHost as well as UserStore instance which the given recipient belongs to.

Please note that expanded addresses are not subject of further expansion in the same method call, so the expansion process is cummulative rather than recursive.

Parameters:
message - source SMTP message
recipient - recipient representing the alias name
Returns:
collection of Recipient objects expanded from the given alias name
Throws:
MailException - if an error occurs

listMessages

public void listMessages(boolean details,
                         java.io.PrintWriter pw)
                  throws MailException
Lists all messages in the queue.

Parameters:
details - true to print message details, false otherwise
pw - the output stream
Throws:
MailException - if an error occured
See Also:
MailQueue.listMessages(boolean, PrintWriter)

runQueue

public void runQueue(java.lang.String node,
                     boolean forceDelivery)
Process the given queue node.

Parameters:
node - the node name
forceDelivery - true to force the processing, false otherwise
See Also:
QueueManager.runQueue(String, boolean)


Copyright (c) 2004-2005, Gnome Ltd. All rights reserved.